Skip to content

Commit 401082c

Browse files
authored
Merge pull request #56 from cham11ng/fix-lint
Fix lint issue and fix securities
2 parents bf0575f + cb51050 commit 401082c

File tree

14 files changed

+217
-149
lines changed

14 files changed

+217
-149
lines changed

.env.docker

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ DB_USER=starter
1111
DB_PASSWORD=secret
1212

1313
# Log
14-
LOGGING_DIR=logs
1514
LOGGING_LEVEL=debug
1615

1716
# Authentication

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
APP_PORT=8000
22

3+
CODE_SOURCE=
4+
35
# Database Configurations
46
DB_CLIENT=pg
57
DB_HOST=127.0.0.1
@@ -9,7 +11,6 @@ DB_USER=
911
DB_PASSWORD=
1012

1113
# Log
12-
LOGGING_DIR=logs
1314
LOGGING_LEVEL=debug
1415

1516
# Authentication

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
build
3+
volumes

.husky/pre-commit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn sync-env && yarn lint-staged
4+
npx sync-dotenv
5+
yarn lint-staged

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ $ yarn seed # to seed
113113

114114
Create a file or add following lines in `.vscode` > `settings.json` and switch an environment `Cmd/Ctrl + Shift + P` > `REST Client: Switch Environment`. Then, you can request APIs from `api.rest` file.
115115

116-
```
116+
```json
117117
{
118118
"rest-client.environmentVariables": {
119119
"$shared": {

nodemon.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
".env"
55
],
66
"ext": "ts,.env",
7-
"verbose": true,
8-
"exec": "ts-node src/index.ts"
7+
"verbose": true
98
}

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,30 @@
1515
"node": ">= 16.5.0"
1616
},
1717
"scripts": {
18-
"start": "nodemon",
18+
"start": "concurrently 'npx tsc --watch' 'nodemon -q build/index.js'",
1919
"transpile": "tsc",
2020
"clean": "rimraf build",
2121
"sync-env": "sync-dotenv",
2222
"build": "concurrently 'yarn clean' 'yarn lint:fix' 'yarn transpile'",
2323
"send:mail": "ts-node scripts/mail-test",
24-
"load:fake": "NODE_ENV=test ts-node scripts/fake-loader",
24+
"load:fake": "ts-node scripts/fake-loader",
2525
"test": "NODE_ENV=test yarn migrate && NODE_ENV=test jest --forceExit --detectOpenHandles --maxWorkers=1 --verbose",
2626
"seed": "knex seed:run --knexfile=knexfile.ts --verbose",
2727
"migrate": "knex migrate:latest --knexfile=knexfile.ts --verbose",
2828
"rollback": "knex migrate:rollback --knexfile=knexfile.ts --verbose",
2929
"make:seeder": "knex seed:make --knexfile=knexfile.ts -x ts",
3030
"make:migration": "knex migrate:make --knexfile=knexfile.ts -x ts",
31+
"prepare": "husky install",
3132
"lint": "eslint . --ext .ts,.json",
3233
"lint:fix": "eslint --fix . --ext .ts,.json",
33-
"prettify": "prettier 'src/**/*.ts' --write"
34+
"prettify": "prettier 'src/**/*.ts' --write",
35+
"prettier:check": "prettier --list-different 'src/**/*.ts'",
36+
"format:code": "concurrently 'yarn lint:fix' 'yarn prettify' 'sync-dotenv'"
3437
},
3538
"lint-staged": {
3639
"*.{ts,json}": [
37-
"eslint --fix . --ext .ts,.json"
40+
"eslint --fix",
41+
"prettier --write"
3842
]
3943
},
4044
"private": true,
@@ -55,7 +59,7 @@
5559
"date-fns": "^2.11.1",
5660
"dotenv": "^16.0.1",
5761
"express": "4.17.1",
58-
"helmet": "^4.6.0",
62+
"helmet": "^5.1.0",
5963
"http-status-codes": "^2.1.4",
6064
"joi": "^17.6.0",
6165
"jsonwebtoken": "^8.5.1",
@@ -76,7 +80,7 @@
7680
"@types/jest": "^28.1.3",
7781
"@types/jsonwebtoken": "^8.5.4",
7882
"@types/morgan": "^1.9.3",
79-
"@types/node": "^16.4.0",
83+
"@types/node": "^18.0.0",
8084
"@types/nodemailer": "^6.4.4",
8185
"@types/supertest": "^2.0.11",
8286
"@typescript-eslint/eslint-plugin": "^5.30.0",
@@ -87,7 +91,7 @@
8791
"eslint-plugin-security": "^1.4.0",
8892
"husky": "^8.0.1",
8993
"jest": "^28.1.2",
90-
"lint-staged": "^11.0.1",
94+
"lint-staged": "^13.0.3",
9195
"nodemon": "^2.0.12",
9296
"prettier": "^2.3.2",
9397
"rimraf": "^3.0.2",

scripts/fake-loader.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import chalk from 'chalk';
22

33
import * as fake from '../src/utils/fake';
4-
import * as factories from '../src/database/factories';
4+
import factories, { FactoryType } from '../src/database/factories';
55

66
const { info } = console;
77

@@ -15,7 +15,8 @@ function print<T>(data: T): void {
1515
try {
1616
const table = process.argv[2];
1717
const total = +process.argv[3] || 1;
18-
const factoryCallback = (factories as any)[table].run;
18+
19+
const factoryCallback = factories[table as FactoryType].run;
1920

2021
print(await fake.generate(factoryCallback, total));
2122

src/config/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export default {
2828
refreshTokenSecretKey: process.env.REFRESH_TOKEN_SECRET_KEY || ''
2929
},
3030
logging: {
31-
dir: process.env.LOGGING_DIR || 'logs',
3231
level: process.env.LOGGING_LEVEL || 'info',
3332
maxSize: process.env.LOGGING_MAX_SIZE || '20m',
3433
maxFiles: process.env.LOGGING_MAX_FILES || '7d',

src/database/factories/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
import * as User from './userFactory';
1+
import * as userFactory from './userFactory';
2+
import UserDetail from '../../domain/entities/UserDetail';
23

3-
export { User };
4+
interface Callback<T> {
5+
run: () => Promise<T>;
6+
}
7+
8+
export enum FactoryType {
9+
USER = 'User'
10+
}
11+
12+
export interface Factories {
13+
[FactoryType.USER]: Callback<UserDetail>;
14+
}
15+
16+
const factories: Factories = { [FactoryType.USER]: userFactory };
17+
18+
export default factories;

0 commit comments

Comments
 (0)