typescript-express-starter 6.3.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.kr.md +13 -11
- package/README.md +12 -10
- package/lib/graphql/.dockerignore +18 -0
- package/lib/graphql/.editorconfig +9 -0
- package/lib/graphql/.env +1 -0
- package/lib/graphql/.eslintignore +1 -0
- package/lib/graphql/.eslintrc +18 -0
- package/lib/graphql/.huskyrc +5 -0
- package/lib/graphql/.lintstagedrc.json +5 -0
- package/lib/graphql/.prettierrc +8 -0
- package/lib/graphql/.swcrc +39 -0
- package/lib/graphql/.vscode/launch.json +35 -0
- package/lib/graphql/.vscode/settings.json +6 -0
- package/lib/graphql/Dockerfile +24 -0
- package/lib/graphql/Makefile +6 -0
- package/lib/graphql/docker-compose.yml +50 -0
- package/lib/graphql/ecosystem.config.js +59 -0
- package/lib/graphql/jest.config.js +12 -0
- package/lib/graphql/nginx.conf +40 -0
- package/lib/graphql/nodemon.json +12 -0
- package/lib/graphql/package.json +79 -0
- package/lib/graphql/src/app.ts +105 -0
- package/lib/graphql/src/configs/development.json +19 -0
- package/lib/graphql/src/configs/production.json +19 -0
- package/lib/graphql/src/configs/test.json +19 -0
- package/lib/graphql/src/databases/index.ts +24 -0
- package/lib/graphql/src/dtos/users.dto.ts +14 -0
- package/lib/graphql/src/entities/users.entity.ts +26 -0
- package/lib/graphql/src/exceptions/HttpException.ts +10 -0
- package/lib/graphql/src/http/auth.http +49 -0
- package/lib/graphql/src/http/users.http +78 -0
- package/lib/graphql/src/index.ts +1 -0
- package/lib/graphql/src/interfaces/auth.interface.ts +14 -0
- package/lib/graphql/src/interfaces/db.interface.ts +7 -0
- package/lib/graphql/src/interfaces/users.interface.ts +5 -0
- package/lib/graphql/src/middlewares/auth.middleware.ts +32 -0
- package/lib/graphql/src/middlewares/error.middleware.ts +17 -0
- package/lib/graphql/src/repositories/auth.repository.ts +61 -0
- package/lib/graphql/src/repositories/users.repository.ts +60 -0
- package/lib/graphql/src/resolvers/auth.resolver.ts +32 -0
- package/lib/graphql/src/resolvers/users.resolver.ts +47 -0
- package/lib/graphql/src/server.ts +14 -0
- package/lib/graphql/src/tests/auth.test.ts +52 -0
- package/lib/graphql/src/tests/index.test.ts +18 -0
- package/lib/graphql/src/tests/users.test.ts +71 -0
- package/lib/graphql/src/typedefs/users.type.ts +13 -0
- package/lib/graphql/src/utils/logger.ts +75 -0
- package/lib/graphql/src/utils/util.ts +19 -0
- package/lib/graphql/src/utils/validateEnv.ts +10 -0
- package/lib/graphql/tsconfig.json +39 -0
- package/package.json +3 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import App from '@/app';
|
|
3
|
+
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
|
+
import AuthRoute from '@routes/auth.route';
|
|
5
|
+
|
|
6
|
+
afterAll(async () => {
|
|
7
|
+
await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('Testing Auth', () => {
|
|
11
|
+
describe('[POST] /signup', () => {
|
|
12
|
+
it('response should have the Create userData', () => {
|
|
13
|
+
const userData: CreateUserDto = {
|
|
14
|
+
email: 'test@email.com',
|
|
15
|
+
password: 'q1w2e3r4',
|
|
16
|
+
};
|
|
17
|
+
const authRoute = new AuthRoute();
|
|
18
|
+
const app = new App([authRoute]);
|
|
19
|
+
|
|
20
|
+
return request(app.getServer()).post('/signup').send(userData);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('[POST] /login', () => {
|
|
25
|
+
it('response should have the Set-Cookie header with the Authorization token', async () => {
|
|
26
|
+
const userData: CreateUserDto = {
|
|
27
|
+
email: 'test@email.com',
|
|
28
|
+
password: 'q1w2e3r4',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const authRoute = new AuthRoute();
|
|
32
|
+
const app = new App([authRoute]);
|
|
33
|
+
|
|
34
|
+
return request(app.getServer())
|
|
35
|
+
.post('/login')
|
|
36
|
+
.send(userData)
|
|
37
|
+
.expect('Set-Cookie', /^Authorization=.+/);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// error: StatusCode : 404, Message : Authentication token missing
|
|
42
|
+
// describe('[POST] /logout', () => {
|
|
43
|
+
// it('logout Set-Cookie Authorization=; Max-age=0', () => {
|
|
44
|
+
// const authRoute = new AuthRoute();
|
|
45
|
+
// const app = new App([authRoute]);
|
|
46
|
+
|
|
47
|
+
// return request(app.getServer())
|
|
48
|
+
// .post('/logout')
|
|
49
|
+
// .expect('Set-Cookie', /^Authorization=\;/);
|
|
50
|
+
// });
|
|
51
|
+
// });
|
|
52
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import App from '@app';
|
|
3
|
+
import IndexRoute from '@routes/index.route';
|
|
4
|
+
|
|
5
|
+
afterAll(async () => {
|
|
6
|
+
await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
describe('Testing Index', () => {
|
|
10
|
+
describe('[GET] /', () => {
|
|
11
|
+
it('response statusCode 200', () => {
|
|
12
|
+
const indexRoute = new IndexRoute();
|
|
13
|
+
const app = new App([indexRoute]);
|
|
14
|
+
|
|
15
|
+
return request(app.getServer()).get(`${indexRoute.path}`).expect(200);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import App from '@app';
|
|
3
|
+
import { CreateUserDto } from '@dtos/users.dto';
|
|
4
|
+
import { User } from '@interfaces/users.interface';
|
|
5
|
+
import userModel from '@models/users.model';
|
|
6
|
+
import UserRoute from '@routes/users.route';
|
|
7
|
+
|
|
8
|
+
afterAll(async () => {
|
|
9
|
+
await new Promise<void>(resolve => setTimeout(() => resolve(), 500));
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('Testing Users', () => {
|
|
13
|
+
describe('[GET] /users', () => {
|
|
14
|
+
it('response statusCode 200 / findAll', () => {
|
|
15
|
+
const findUser: User[] = userModel;
|
|
16
|
+
const usersRoute = new UserRoute();
|
|
17
|
+
const app = new App([usersRoute]);
|
|
18
|
+
|
|
19
|
+
return request(app.getServer()).get(`${usersRoute.path}`).expect(200, { data: findUser, message: 'findAll' });
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('[GET] /users/:id', () => {
|
|
24
|
+
it('response statusCode 200 / findOne', () => {
|
|
25
|
+
const userId = 1;
|
|
26
|
+
const findUser: User = userModel.find(user => user.id === userId);
|
|
27
|
+
const usersRoute = new UserRoute();
|
|
28
|
+
const app = new App([usersRoute]);
|
|
29
|
+
|
|
30
|
+
return request(app.getServer()).get(`${usersRoute.path}/${userId}`).expect(200, { data: findUser, message: 'findOne' });
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('[POST] /users', () => {
|
|
35
|
+
it('response statusCode 201 / created', async () => {
|
|
36
|
+
const userData: CreateUserDto = {
|
|
37
|
+
email: 'test@email.com',
|
|
38
|
+
password: 'q1w2e3r4',
|
|
39
|
+
};
|
|
40
|
+
const usersRoute = new UserRoute();
|
|
41
|
+
const app = new App([usersRoute]);
|
|
42
|
+
|
|
43
|
+
return request(app.getServer()).post(`${usersRoute.path}`).send(userData).expect(201);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('[PUT] /users/:id', () => {
|
|
48
|
+
it('response statusCode 200 / updated', async () => {
|
|
49
|
+
const userId = 1;
|
|
50
|
+
const userData: CreateUserDto = {
|
|
51
|
+
email: 'test@email.com',
|
|
52
|
+
password: 'q1w2e3r4',
|
|
53
|
+
};
|
|
54
|
+
const usersRoute = new UserRoute();
|
|
55
|
+
const app = new App([usersRoute]);
|
|
56
|
+
|
|
57
|
+
return request(app.getServer()).put(`${usersRoute.path}/${userId}`).send(userData).expect(200);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('[DELETE] /users/:id', () => {
|
|
62
|
+
it('response statusCode 200 / deleted', () => {
|
|
63
|
+
const userId = 1;
|
|
64
|
+
const deleteUser: User[] = userModel.filter(user => user.id !== userId);
|
|
65
|
+
const usersRoute = new UserRoute();
|
|
66
|
+
const app = new App([usersRoute]);
|
|
67
|
+
|
|
68
|
+
return request(app.getServer()).delete(`${usersRoute.path}/${userId}`).expect(200, { data: deleteUser, message: 'deleted' });
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import config from 'config';
|
|
2
|
+
import { existsSync, mkdirSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import winston from 'winston';
|
|
5
|
+
import winstonDaily from 'winston-daily-rotate-file';
|
|
6
|
+
|
|
7
|
+
// logs dir
|
|
8
|
+
const logDir: string = join(__dirname, config.get('log.dir'));
|
|
9
|
+
|
|
10
|
+
if (!existsSync(logDir)) {
|
|
11
|
+
mkdirSync(logDir);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Define log format
|
|
15
|
+
const logFormat = winston.format.printf(({ timestamp, level, message }) => `${timestamp} ${level}: ${message}`);
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Log Level
|
|
19
|
+
* error: 0, warn: 1, info: 2, http: 3, verbose: 4, debug: 5, silly: 6
|
|
20
|
+
*/
|
|
21
|
+
export const logger = winston.createLogger({
|
|
22
|
+
format: winston.format.combine(
|
|
23
|
+
winston.format.timestamp({
|
|
24
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
25
|
+
}),
|
|
26
|
+
logFormat,
|
|
27
|
+
),
|
|
28
|
+
transports: [
|
|
29
|
+
// debug log setting
|
|
30
|
+
new winstonDaily({
|
|
31
|
+
level: 'debug',
|
|
32
|
+
datePattern: 'YYYY-MM-DD',
|
|
33
|
+
dirname: logDir + '/debug', // log file /logs/debug/*.log in save
|
|
34
|
+
filename: `%DATE%.log`,
|
|
35
|
+
maxFiles: 30, // 30 Days saved
|
|
36
|
+
json: false,
|
|
37
|
+
zippedArchive: true,
|
|
38
|
+
}),
|
|
39
|
+
// error log setting
|
|
40
|
+
new winstonDaily({
|
|
41
|
+
level: 'error',
|
|
42
|
+
datePattern: 'YYYY-MM-DD',
|
|
43
|
+
dirname: logDir + '/error', // log file /logs/error/*.log in save
|
|
44
|
+
filename: `%DATE%.log`,
|
|
45
|
+
maxFiles: 30, // 30 Days saved
|
|
46
|
+
handleExceptions: true,
|
|
47
|
+
json: false,
|
|
48
|
+
zippedArchive: true,
|
|
49
|
+
}),
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
logger.add(
|
|
54
|
+
new winston.transports.Console({
|
|
55
|
+
format: winston.format.combine(winston.format.splat(), winston.format.colorize()),
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
export const responseLogger = request => {
|
|
60
|
+
const { query } = request.request;
|
|
61
|
+
logger.info(query);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const errorLogger = error => {
|
|
65
|
+
const { validationErrors } = error.extensions.exception;
|
|
66
|
+
|
|
67
|
+
let message = '';
|
|
68
|
+
if (validationErrors) {
|
|
69
|
+
message = validationErrors.map(error => Object.values(error.constraints)).join(', ');
|
|
70
|
+
} else {
|
|
71
|
+
message = error.message;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
logger.error(message);
|
|
75
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @method isEmpty
|
|
3
|
+
* @param {String | Number | Object} value
|
|
4
|
+
* @returns {Boolean} true & false
|
|
5
|
+
* @description this value is Empty Check
|
|
6
|
+
*/
|
|
7
|
+
export const isEmpty = (value: string | number | object): boolean => {
|
|
8
|
+
if (value === null) {
|
|
9
|
+
return true;
|
|
10
|
+
} else if (typeof value !== 'number' && value === '') {
|
|
11
|
+
return true;
|
|
12
|
+
} else if (typeof value === 'undefined' || value === undefined) {
|
|
13
|
+
return true;
|
|
14
|
+
} else if (value !== null && typeof value === 'object' && !Object.keys(value).length) {
|
|
15
|
+
return true;
|
|
16
|
+
} else {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": false,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es2017",
|
|
5
|
+
"lib": ["es2017", "esnext.asynciterable"],
|
|
6
|
+
"typeRoots": ["node_modules/@types"],
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"emitDecoratorMetadata": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"module": "commonjs",
|
|
13
|
+
"pretty": true,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"outDir": "dist",
|
|
17
|
+
"allowJs": true,
|
|
18
|
+
"noEmit": false,
|
|
19
|
+
"esModuleInterop": true,
|
|
20
|
+
"resolveJsonModule": true,
|
|
21
|
+
"importHelpers": true,
|
|
22
|
+
"baseUrl": "src",
|
|
23
|
+
"paths": {
|
|
24
|
+
"@/*": ["*"],
|
|
25
|
+
"@databases": ["databases"],
|
|
26
|
+
"@dtos/*": ["dtos/*"],
|
|
27
|
+
"@entities/*": ["entities/*"],
|
|
28
|
+
"@exceptions/*": ["exceptions/*"],
|
|
29
|
+
"@interfaces/*": ["interfaces/*"],
|
|
30
|
+
"@middlewares/*": ["middlewares/*"],
|
|
31
|
+
"@repositories/*": ["repositories/*"],
|
|
32
|
+
"@resolvers/*": ["resolvers/*"],
|
|
33
|
+
"@typedefs/*": ["typedefs/*"],
|
|
34
|
+
"@utils/*": ["utils/*"]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"include": ["src/**/*.ts", "src/**/*.json", ".env"],
|
|
38
|
+
"exclude": ["node_modules", "src/http", "src/logs", "src/tests"]
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typescript-express-starter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Quick and Easy TypeScript Express Starter",
|
|
5
5
|
"author": "AGUMON <ljlm0402@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"typeorm",
|
|
15
15
|
"knex",
|
|
16
16
|
"prisma",
|
|
17
|
+
"graphql",
|
|
18
|
+
"apollo",
|
|
17
19
|
"jest",
|
|
18
20
|
"nodemon",
|
|
19
21
|
"jsonwebtoken",
|