Skip to content

Commit

Permalink
initial commit with importing file; creating server structure; adding…
Browse files Browse the repository at this point in the history
… docker-compose.yml
  • Loading branch information
geka-evk committed Aug 26, 2023
0 parents commit 2cb338d
Show file tree
Hide file tree
Showing 33 changed files with 9,538 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dockerfile
.dockerignore

node_modules
npm-debug.log

dist
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
HTTP_PORT=3000

#DB_HOST=postgres # for running in docker-compose
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=curex
DB_PASSWORD=dbpassword
DB_NAME=curex-db
DB_SYNCHRONIZE=true # todo: add more controll on this env var (on prod)

25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

.run/*
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120
}
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ARG NODE_VERSION="18.17-alpine"
ARG WORK_DIR="/curex-app"

FROM node:${NODE_VERSION} as dev
ARG NODE_VERSION
ARG WORK_DIR
WORKDIR ${WORK_DIR}

COPY package*.json ./
RUN npm ci
COPY . .

FROM dev as build
ENV NODE_ENV production

RUN npm run build
RUN npm ci --only=production && npm cache clean --force

FROM node:${NODE_VERSION} as prod
ARG WORK_DIR
USER node

COPY --from=build ${WORK_DIR}/node_modules ./node_modules
COPY --from=build ${WORK_DIR}/dist ./dist
COPY --from=build ${WORK_DIR}/imports ./imports

CMD [ "node", "./dist/main.js" ]
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

## Description
A test tasks for AYA (parser)

## Installation

```bash
$ npm install
```

## Running the app

```bash
# import data from /imports/import.txt into Postgres DB
npm run start:import

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```

## Env vars (.env)

```bash
HTTP_PORT=3000
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=curex
DB_PASSWORD=dbpassword
DB_NAME=curex-db
DB_SYNCHRONIZE=true
```


## Test

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: "3.8"

services:
curex-app:
build:
context: .
dockerfile: Dockerfile
target: prod
restart: always
# command: npm run start:dev
ports:
- "127.0.0.1:3000:${HTTP_PORT}"
env_file: .env
volumes:
- .:/curex-app
depends_on:
- postgres
networks:
- curex-net

postgres:
image: postgres:14.1-alpine
restart: always
environment:
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
ports:
- "${DB_PORT}:5432"
volumes:
- pgData:/var/lib/postgresql/data
networks:
- curex-net

adminer:
image: adminer
restart: always
ports:
- "8080:8080"
networks:
- curex-net

networks:
curex-net:

volumes:
pgData:
47 changes: 47 additions & 0 deletions imports/import.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
exchange-offices
exchange-office
id = 1
name = Exchanger 1
country = UKR
exchanges
exchange
from = EUR
to = USD
ask = 110
date = 2023-04-24 22:55:33
exchange
from = USD
to = UAH
ask = 400
date = 2023-04-24 22:55:33
rates
rate
from = EUR
to = USD
in = 1.1
out = 1
reserve = 120000
date = 2023-04-24 22:55:33
rate
from = USD
to = UAH
in = 1
out = 40
reserve = 150000
date = 2023-04-24 22:55:33
exchange-office
id = 2
name = Exchanger 2
country = UKR
rates
rate
from = AUD
to = CAD
in = 1
out = 2
reserve = 150000
date = 2023-04-24 22:55:33
countries
country
code = UKR
name = Ukraine
9 changes: 9 additions & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
},
"assets": ["**/db/file-importer/*.txt"]
}
Loading

0 comments on commit 2cb338d

Please sign in to comment.