Skip to content

Commit 9ba0693

Browse files
committed
Fix lint issue and fix securities
1 parent bf0575f commit 9ba0693

File tree

13 files changed

+208
-141
lines changed

13 files changed

+208
-141
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": {

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@
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,
@@ -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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
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

8-
function print<T>(data: T): void {
9-
const jsonData = JSON.stringify(data, null, ' ');
10-
11-
info(chalk.green(jsonData));
12-
}
13-
148
(async (): Promise<void> => {
159
try {
1610
const table = process.argv[2];
1711
const total = +process.argv[3] || 1;
18-
const factoryCallback = (factories as any)[table].run;
12+
const factoryCallback = factories[table as FactoryType].run;
1913

20-
print(await fake.generate(factoryCallback, total));
14+
await fake.generate(factoryCallback, total);
2115

2216
process.exit(0);
2317
} catch (err: any) {

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;

src/utils/fake.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ export async function generate<T>(
99
factoryCallback: () => Promise<T>,
1010
total = 1
1111
): Promise<T[]> {
12-
const data = [];
12+
const data: T[] = [];
1313
for (let i = 0; i < total; i++) {
14-
data[i] = await factoryCallback();
14+
const res = await factoryCallback();
15+
16+
data.push(res);
1517
}
1618

1719
return data;

0 commit comments

Comments
 (0)