typescript-express-starter 6.2.1 → 8.0.1
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 +55 -26
- package/README.md +54 -25
- package/bin/cli.js +4 -3
- package/lib/default/.swcrc +41 -0
- package/lib/default/nodemon.json +2 -2
- package/lib/default/package.json +12 -8
- package/lib/default/src/app.ts +1 -2
- package/lib/default/src/http/auth.http +12 -15
- package/lib/default/src/http/users.http +12 -16
- package/lib/default/src/index.ts +1 -0
- package/lib/default/src/middlewares/auth.middleware.ts +3 -3
- package/lib/default/src/models/users.model.ts +5 -5
- package/lib/default/src/server.ts +1 -2
- package/lib/default/src/services/auth.service.ts +5 -5
- package/lib/default/src/services/users.service.ts +3 -3
- package/lib/default/src/tests/auth.test.ts +4 -4
- package/lib/default/src/tests/users.test.ts +4 -4
- package/lib/default/src/utils/logger.ts +5 -5
- package/lib/default/tsconfig.json +2 -2
- 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/{typeorm/src/entity → graphql/src/entities}/users.entity.ts +3 -3
- 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/lib/knex/.swcrc +39 -0
- package/lib/knex/knexfile.ts +6 -6
- package/lib/knex/nodemon.json +2 -2
- package/lib/knex/package.json +11 -8
- package/lib/knex/src/app.ts +2 -3
- package/lib/knex/src/databases/index.ts +6 -6
- package/lib/knex/src/http/auth.http +12 -15
- package/lib/knex/src/http/users.http +12 -16
- package/lib/knex/src/index.ts +1 -0
- package/lib/knex/src/middlewares/auth.middleware.ts +4 -4
- package/lib/knex/src/server.ts +1 -2
- package/lib/knex/src/services/auth.service.ts +5 -5
- package/lib/knex/src/services/users.service.ts +3 -3
- package/lib/knex/src/tests/auth.test.ts +2 -2
- package/lib/knex/src/tests/index.test.ts +1 -1
- package/lib/knex/src/tests/users.test.ts +2 -2
- package/lib/knex/src/utils/logger.ts +5 -5
- package/lib/knex/tsconfig.json +2 -2
- package/lib/mongoose/.swcrc +39 -0
- package/lib/mongoose/docker-compose.yml +0 -4
- package/lib/mongoose/nodemon.json +2 -2
- package/lib/mongoose/package.json +12 -8
- package/lib/mongoose/src/app.ts +2 -3
- package/lib/mongoose/src/configs/development.json +1 -1
- package/lib/mongoose/src/configs/production.json +1 -1
- package/lib/mongoose/src/configs/test.json +1 -1
- package/lib/mongoose/src/http/auth.http +32 -0
- package/lib/mongoose/src/http/users.http +34 -0
- package/lib/mongoose/src/index.ts +1 -0
- package/lib/mongoose/src/middlewares/auth.middleware.ts +3 -3
- package/lib/mongoose/src/server.ts +1 -2
- package/lib/mongoose/src/services/auth.service.ts +5 -5
- package/lib/mongoose/src/services/users.service.ts +3 -3
- package/lib/mongoose/src/utils/logger.ts +5 -5
- package/lib/mongoose/tsconfig.json +2 -2
- package/lib/prisma/.env +1 -1
- package/lib/prisma/.swcrc +37 -0
- package/lib/prisma/docker-compose.yml +1 -6
- package/lib/prisma/nodemon.json +2 -2
- package/lib/prisma/package.json +14 -10
- package/lib/prisma/src/app.ts +2 -3
- package/lib/prisma/src/http/auth.http +12 -15
- package/lib/prisma/src/http/users.http +12 -16
- package/lib/prisma/src/index.ts +1 -0
- package/lib/prisma/src/middlewares/auth.middleware.ts +4 -4
- package/lib/prisma/src/server.ts +1 -2
- package/lib/prisma/src/services/auth.service.ts +5 -5
- package/lib/prisma/src/services/users.service.ts +3 -3
- package/lib/prisma/src/utils/logger.ts +5 -5
- package/lib/prisma/tsconfig.json +2 -2
- package/lib/routing-controllers/.swcrc +37 -0
- package/lib/routing-controllers/nodemon.json +2 -2
- package/lib/routing-controllers/package.json +12 -9
- package/lib/routing-controllers/src/app.ts +3 -4
- package/lib/routing-controllers/src/http/auth.http +12 -15
- package/lib/routing-controllers/src/http/users.http +12 -16
- package/lib/routing-controllers/src/index.ts +1 -0
- package/lib/routing-controllers/src/middlewares/auth.middleware.ts +3 -3
- package/lib/routing-controllers/src/middlewares/validation.middleware.ts +10 -2
- package/lib/routing-controllers/src/models/users.model.ts +5 -5
- package/lib/routing-controllers/src/server.ts +1 -3
- package/lib/routing-controllers/src/services/auth.service.ts +5 -5
- package/lib/routing-controllers/src/services/users.service.ts +3 -3
- package/lib/routing-controllers/src/utils/logger.ts +5 -5
- package/lib/routing-controllers/tsconfig.json +2 -2
- package/lib/sequelize/.swcrc +39 -0
- package/lib/sequelize/docker-compose.yml +1 -6
- package/lib/sequelize/nodemon.json +2 -2
- package/lib/sequelize/package.json +12 -8
- package/lib/sequelize/src/app.ts +1 -2
- package/lib/sequelize/src/configs/development.json +2 -2
- package/lib/sequelize/src/configs/production.json +1 -1
- package/lib/sequelize/src/configs/test.json +1 -1
- package/lib/sequelize/src/http/auth.http +32 -0
- package/lib/sequelize/src/http/users.http +34 -0
- package/lib/sequelize/src/index.ts +1 -0
- package/lib/sequelize/src/middlewares/auth.middleware.ts +4 -4
- package/lib/sequelize/src/server.ts +1 -2
- package/lib/sequelize/src/services/auth.service.ts +5 -5
- package/lib/sequelize/src/services/users.service.ts +3 -3
- package/lib/sequelize/src/utils/logger.ts +5 -5
- package/lib/sequelize/tsconfig.json +2 -2
- package/lib/starter.js +4 -6
- package/lib/typegoose/.dockerignore +18 -0
- package/lib/typegoose/.editorconfig +9 -0
- package/lib/typegoose/.env.development.local +18 -0
- package/lib/typegoose/.env.production.local +18 -0
- package/lib/typegoose/.env.test.local +18 -0
- package/lib/typegoose/.eslintignore +1 -0
- package/lib/typegoose/.eslintrc +18 -0
- package/lib/typegoose/.huskyrc +5 -0
- package/lib/typegoose/.lintstagedrc.json +5 -0
- package/lib/typegoose/.prettierrc +8 -0
- package/lib/typegoose/.swcrc +40 -0
- package/lib/typegoose/.vscode/launch.json +35 -0
- package/lib/typegoose/.vscode/settings.json +6 -0
- package/lib/typegoose/Dockerfile +24 -0
- package/lib/typegoose/Makefile +6 -0
- package/lib/typegoose/docker-compose.yml +46 -0
- package/lib/typegoose/ecosystem.config.js +57 -0
- package/lib/typegoose/jest.config.js +12 -0
- package/lib/typegoose/nginx.conf +40 -0
- package/lib/typegoose/nodemon.json +12 -0
- package/lib/typegoose/package.json +80 -0
- package/lib/typegoose/src/app.ts +93 -0
- package/lib/typegoose/src/config/index.ts +5 -0
- package/lib/typegoose/src/controllers/auth.controller.ts +46 -0
- package/lib/typegoose/src/controllers/index.controller.ts +13 -0
- package/lib/typegoose/src/controllers/users.controller.ts +65 -0
- package/lib/typegoose/src/databases/index.ts +3 -0
- package/lib/typegoose/src/dtos/users.dto.ts +9 -0
- package/lib/typegoose/src/exceptions/HttpException.ts +10 -0
- package/lib/typegoose/src/http/auth.http +32 -0
- package/lib/typegoose/src/http/users.http +34 -0
- package/lib/typegoose/src/interfaces/auth.interface.ts +15 -0
- package/lib/typegoose/src/interfaces/routes.interface.ts +6 -0
- package/lib/typegoose/src/interfaces/users.interface.ts +5 -0
- package/lib/typegoose/src/middlewares/auth.middleware.ts +32 -0
- package/lib/typegoose/src/middlewares/error.middleware.ts +17 -0
- package/lib/typegoose/src/middlewares/validation.middleware.ts +25 -0
- package/lib/typegoose/src/models/users.model.ts +18 -0
- package/lib/typegoose/src/routes/auth.route.ts +24 -0
- package/lib/typegoose/src/routes/index.route.ts +19 -0
- package/lib/typegoose/src/routes/users.route.ts +25 -0
- package/lib/typegoose/src/server.ts +11 -0
- package/lib/typegoose/src/services/auth.service.ts +61 -0
- package/lib/typegoose/src/services/users.service.ts +64 -0
- package/lib/typegoose/src/tests/auth.test.ts +83 -0
- package/lib/typegoose/src/tests/index.test.ts +18 -0
- package/lib/typegoose/src/tests/users.test.ts +133 -0
- package/lib/typegoose/src/utils/logger.ts +65 -0
- package/lib/typegoose/src/utils/util.ts +19 -0
- package/lib/typegoose/src/utils/validateEnv.ts +10 -0
- package/lib/typegoose/swagger.yaml +122 -0
- package/lib/typegoose/tsconfig.json +40 -0
- package/lib/typeorm/.swcrc +39 -0
- package/lib/typeorm/docker-compose.yml +1 -1
- package/lib/typeorm/nodemon.json +2 -2
- package/lib/typeorm/package.json +12 -8
- package/lib/typeorm/src/app.ts +1 -2
- package/lib/typeorm/src/configs/development.json +1 -1
- package/lib/typeorm/src/configs/production.json +1 -1
- package/lib/typeorm/src/configs/test.json +1 -1
- package/lib/typeorm/src/databases/index.ts +5 -5
- package/lib/typeorm/src/entities/users.entity.ts +26 -0
- package/lib/typeorm/src/http/auth.http +12 -15
- package/lib/typeorm/src/http/users.http +12 -16
- package/lib/typeorm/src/index.ts +1 -0
- package/lib/typeorm/src/middlewares/auth.middleware.ts +5 -9
- package/lib/typeorm/src/server.ts +1 -2
- package/lib/typeorm/src/services/auth.service.ts +13 -17
- package/lib/typeorm/src/services/users.service.ts +16 -22
- package/lib/typeorm/src/utils/logger.ts +5 -5
- package/lib/typeorm/tsconfig.json +3 -3
- package/package.json +14 -4
|
@@ -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/lib/knex/.swcrc
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jsc": {
|
|
3
|
+
"parser": {
|
|
4
|
+
"syntax": "typescript",
|
|
5
|
+
"tsx": false,
|
|
6
|
+
"dynamicImport": true,
|
|
7
|
+
"decorators": true
|
|
8
|
+
},
|
|
9
|
+
"transform": {
|
|
10
|
+
"legacyDecorator": true,
|
|
11
|
+
"decoratorMetadata": true
|
|
12
|
+
},
|
|
13
|
+
"target": "es2017",
|
|
14
|
+
"externalHelpers": false,
|
|
15
|
+
"keepClassNames": true,
|
|
16
|
+
"loose": false,
|
|
17
|
+
"minify": {
|
|
18
|
+
"compress": false,
|
|
19
|
+
"mangle": false
|
|
20
|
+
},
|
|
21
|
+
"baseUrl": "src",
|
|
22
|
+
"paths": {
|
|
23
|
+
"@/*": ["*"],
|
|
24
|
+
"@controllers/*": ["controllers/*"],
|
|
25
|
+
"@databases": ["databases"],
|
|
26
|
+
"@dtos/*": ["dtos/*"],
|
|
27
|
+
"@exceptions/*": ["exceptions/*"],
|
|
28
|
+
"@interfaces/*": ["interfaces/*"],
|
|
29
|
+
"@middlewares/*": ["middlewares/*"],
|
|
30
|
+
"@models/*": ["models/*"],
|
|
31
|
+
"@routes/*": ["routes/*"],
|
|
32
|
+
"@services/*": ["services/*"],
|
|
33
|
+
"@utils/*": ["utils/*"]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"module": {
|
|
37
|
+
"type": "commonjs"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/lib/knex/knexfile.ts
CHANGED
|
@@ -3,17 +3,17 @@ process.env['NODE_CONFIG_DIR'] = __dirname + '/src/configs';
|
|
|
3
3
|
import config from 'config';
|
|
4
4
|
import { dbConfig } from './src/interfaces/db.interface';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const { host, user, password, database, port }: dbConfig = config.get('dbConfig');
|
|
7
7
|
export = {
|
|
8
8
|
client: 'mysql',
|
|
9
9
|
connection: {
|
|
10
10
|
charset: 'utf8',
|
|
11
11
|
timezone: 'UTC',
|
|
12
|
-
host:
|
|
13
|
-
user:
|
|
14
|
-
password:
|
|
15
|
-
database:
|
|
16
|
-
port:
|
|
12
|
+
host: host,
|
|
13
|
+
user: user,
|
|
14
|
+
password: password,
|
|
15
|
+
database: database,
|
|
16
|
+
port: port,
|
|
17
17
|
},
|
|
18
18
|
migrations: {
|
|
19
19
|
directory: 'src/databases/migrations',
|
package/lib/knex/nodemon.json
CHANGED
package/lib/knex/package.json
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"scripts": {
|
|
8
8
|
"start": "npm run build && cross-env NODE_ENV=production node dist/server.js",
|
|
9
9
|
"dev": "cross-env NODE_ENV=development nodemon",
|
|
10
|
-
"build": "tsc &&
|
|
10
|
+
"build": "tsc && tsc-alias",
|
|
11
|
+
"build:swc": "swc src -d dist --source-maps --copy-files",
|
|
11
12
|
"test": "jest --forceExit --detectOpenHandles",
|
|
12
13
|
"lint": "eslint --ignore-path .gitignore --ext .ts src/",
|
|
13
14
|
"lint:fix": "npm run lint -- --fix",
|
|
@@ -27,7 +28,6 @@
|
|
|
27
28
|
"config": "^3.3.6",
|
|
28
29
|
"cookie-parser": "^1.4.5",
|
|
29
30
|
"cors": "^2.8.5",
|
|
30
|
-
"cross-env": "^7.0.3",
|
|
31
31
|
"dotenv": "^9.0.2",
|
|
32
32
|
"envalid": "^7.1.0",
|
|
33
33
|
"express": "^4.17.1",
|
|
@@ -38,13 +38,14 @@
|
|
|
38
38
|
"morgan": "^1.10.0",
|
|
39
39
|
"mysql": "^2.18.1",
|
|
40
40
|
"objection": "^2.2.15",
|
|
41
|
-
"pm2": "^5.1.0",
|
|
42
41
|
"swagger-jsdoc": "^6.0.0",
|
|
43
42
|
"swagger-ui-express": "^4.1.6",
|
|
44
43
|
"winston": "^3.3.3",
|
|
45
44
|
"winston-daily-rotate-file": "^4.5.5"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
47
|
+
"@swc/cli": "^0.1.51",
|
|
48
|
+
"@swc/core": "^1.2.108",
|
|
48
49
|
"@types/bcrypt": "^5.0.0",
|
|
49
50
|
"@types/compression": "^1.7.0",
|
|
50
51
|
"@types/config": "0.0.38",
|
|
@@ -65,21 +66,23 @@
|
|
|
65
66
|
"@types/winston": "^2.4.4",
|
|
66
67
|
"@typescript-eslint/eslint-plugin": "^4.23.0",
|
|
67
68
|
"@typescript-eslint/parser": "^4.23.0",
|
|
69
|
+
"cross-env": "^7.0.3",
|
|
68
70
|
"eslint": "^7.26.0",
|
|
69
71
|
"eslint-config-prettier": "^8.3.0",
|
|
70
72
|
"eslint-plugin-prettier": "^3.4.0",
|
|
71
73
|
"husky": "^6.0.0",
|
|
72
74
|
"jest": "^27.0.6",
|
|
73
|
-
"jest-extended": "^0.11.5",
|
|
74
75
|
"lint-staged": "^11.0.0",
|
|
75
76
|
"node-config": "0.0.2",
|
|
76
77
|
"node-gyp": "^8.0.0",
|
|
77
78
|
"nodemon": "^2.0.7",
|
|
79
|
+
"pm2": "^5.1.0",
|
|
78
80
|
"prettier": "^2.3.0",
|
|
79
81
|
"supertest": "^6.1.3",
|
|
80
|
-
"ts-jest": "^27.0.
|
|
81
|
-
"ts-node": "^10.
|
|
82
|
-
"
|
|
83
|
-
"
|
|
82
|
+
"ts-jest": "^27.0.7",
|
|
83
|
+
"ts-node": "^10.4.0",
|
|
84
|
+
"tsc-alias": "^1.4.1",
|
|
85
|
+
"tsconfig-paths": "^3.10.1",
|
|
86
|
+
"typescript": "^4.5.2"
|
|
84
87
|
}
|
|
85
88
|
}
|
package/lib/knex/src/app.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import '@/index';
|
|
2
|
+
import config from 'config';
|
|
3
3
|
import compression from 'compression';
|
|
4
4
|
import cookieParser from 'cookie-parser';
|
|
5
5
|
import cors from 'cors';
|
|
6
|
-
import config from 'config';
|
|
7
6
|
import express from 'express';
|
|
8
7
|
import helmet from 'helmet';
|
|
9
8
|
import hpp from 'hpp';
|
|
@@ -2,17 +2,17 @@ import config from 'config';
|
|
|
2
2
|
import Knex from 'knex';
|
|
3
3
|
import { dbConfig } from '@interfaces/db.interface';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const { host, port, user, password, database }: dbConfig = config.get('dbConfig');
|
|
6
6
|
const dbConnection = {
|
|
7
7
|
client: 'mysql',
|
|
8
8
|
connection: {
|
|
9
9
|
charset: 'utf8',
|
|
10
10
|
timezone: 'UTC',
|
|
11
|
-
host:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
host: host,
|
|
12
|
+
port: port,
|
|
13
|
+
user: user,
|
|
14
|
+
password: password,
|
|
15
|
+
database: database,
|
|
16
16
|
},
|
|
17
17
|
pool: {
|
|
18
18
|
min: 2,
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
# auth API
|
|
2
|
-
|
|
3
|
-
###
|
|
4
1
|
# baseURL
|
|
5
2
|
@baseURL = http://localhost:3000
|
|
6
3
|
|
|
7
4
|
###
|
|
8
|
-
#
|
|
9
|
-
POST {{baseURL}}/signup
|
|
5
|
+
# User Signup
|
|
6
|
+
POST {{ baseURL }}/signup
|
|
10
7
|
Content-Type: application/json
|
|
11
8
|
|
|
12
9
|
{
|
|
13
|
-
"email": "example@
|
|
14
|
-
|
|
10
|
+
"email": "example@email.com",
|
|
11
|
+
"password": "password"
|
|
15
12
|
}
|
|
16
13
|
|
|
17
14
|
###
|
|
18
|
-
# Login
|
|
19
|
-
POST {{baseURL}}/login
|
|
15
|
+
# User Login
|
|
16
|
+
POST {{ baseURL }}/login
|
|
20
17
|
Content-Type: application/json
|
|
21
18
|
|
|
22
19
|
{
|
|
23
|
-
"email": "
|
|
24
|
-
|
|
20
|
+
"email": "example@email.com",
|
|
21
|
+
"password": "password"
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
###
|
|
28
|
-
# Logout
|
|
29
|
-
POST {{baseURL}}/logout
|
|
25
|
+
# User Logout
|
|
26
|
+
POST {{ baseURL }}/logout
|
|
30
27
|
Content-Type: application/json
|
|
31
28
|
|
|
32
29
|
{
|
|
33
|
-
"email": "
|
|
34
|
-
|
|
30
|
+
"email": "example@email.com",
|
|
31
|
+
"password": "password"
|
|
35
32
|
}
|
|
@@ -1,38 +1,34 @@
|
|
|
1
|
-
# users API
|
|
2
|
-
|
|
3
|
-
###
|
|
4
1
|
# baseURL
|
|
5
2
|
@baseURL = http://localhost:3000
|
|
6
3
|
|
|
7
4
|
###
|
|
8
5
|
# Find All Users
|
|
9
|
-
GET {{baseURL}}/users
|
|
6
|
+
GET {{ baseURL }}/users
|
|
10
7
|
|
|
11
8
|
###
|
|
12
9
|
# Find User By Id
|
|
13
|
-
GET {{baseURL}}/users/1
|
|
14
|
-
|
|
10
|
+
GET {{ baseURL }}/users/1
|
|
15
11
|
|
|
16
12
|
###
|
|
17
|
-
#
|
|
18
|
-
POST {{baseURL}}/users
|
|
13
|
+
# Create User
|
|
14
|
+
POST {{ baseURL }}/users
|
|
19
15
|
Content-Type: application/json
|
|
20
16
|
|
|
21
17
|
{
|
|
22
|
-
"email": "example@
|
|
23
|
-
|
|
18
|
+
"email": "example@email.com",
|
|
19
|
+
"password": "password"
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
###
|
|
27
|
-
#
|
|
28
|
-
PUT {{baseURL}}/users/1
|
|
23
|
+
# Modify User By Id
|
|
24
|
+
PUT {{ baseURL }}/users/1
|
|
29
25
|
Content-Type: application/json
|
|
30
26
|
|
|
31
27
|
{
|
|
32
|
-
"email": "example@
|
|
33
|
-
|
|
28
|
+
"email": "example@email.com",
|
|
29
|
+
"password": "password"
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
###
|
|
37
|
-
#
|
|
38
|
-
DELETE {{baseURL}}/users/1
|
|
33
|
+
# Delete User By Id
|
|
34
|
+
DELETE {{ baseURL }}/users/1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
process.env['NODE_CONFIG_DIR'] = __dirname + '/configs';
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import config from 'config';
|
|
2
2
|
import { NextFunction, Response } from 'express';
|
|
3
|
-
import
|
|
3
|
+
import { verify } from 'jsonwebtoken';
|
|
4
4
|
import { HttpException } from '@exceptions/HttpException';
|
|
5
5
|
import { DataStoredInToken, RequestWithUser } from '@interfaces/auth.interface';
|
|
6
|
-
import { User } from '
|
|
6
|
+
import { User } from '@interfaces/users.interface';
|
|
7
7
|
import { Users } from '@models/users.model';
|
|
8
8
|
|
|
9
9
|
const authMiddleware = async (req: RequestWithUser, res: Response, next: NextFunction) => {
|
|
10
10
|
try {
|
|
11
|
-
const Authorization = req.cookies['Authorization'] || req.header('Authorization').split('Bearer ')[1]
|
|
11
|
+
const Authorization = req.cookies['Authorization'] || (req.header('Authorization') ? req.header('Authorization').split('Bearer ')[1] : null);
|
|
12
12
|
|
|
13
13
|
if (Authorization) {
|
|
14
14
|
const secretKey: string = config.get('secretKey');
|
|
15
|
-
const verificationResponse = (await
|
|
15
|
+
const verificationResponse = (await verify(Authorization, secretKey)) as DataStoredInToken;
|
|
16
16
|
const userId = verificationResponse.id;
|
|
17
17
|
const findUser: User = await Users.query().findById(userId);
|
|
18
18
|
|
package/lib/knex/src/server.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { hash, compare } from 'bcrypt';
|
|
2
2
|
import config from 'config';
|
|
3
|
-
import
|
|
3
|
+
import { sign } from 'jsonwebtoken';
|
|
4
4
|
import { CreateUserDto } from '@dtos/users.dto';
|
|
5
5
|
import { HttpException } from '@exceptions/HttpException';
|
|
6
6
|
import { DataStoredInToken, TokenData } from '@interfaces/auth.interface';
|
|
@@ -15,7 +15,7 @@ class AuthService {
|
|
|
15
15
|
const findUser: Users = await Users.query().select().from('users').where('email', '=', userData.email).first();
|
|
16
16
|
if (findUser) throw new HttpException(409, `You're email ${userData.email} already exists`);
|
|
17
17
|
|
|
18
|
-
const hashedPassword = await
|
|
18
|
+
const hashedPassword = await hash(userData.password, 10);
|
|
19
19
|
const createUserData: User = await Users.query()
|
|
20
20
|
.insert({ ...userData, password: hashedPassword })
|
|
21
21
|
.into('users');
|
|
@@ -29,7 +29,7 @@ class AuthService {
|
|
|
29
29
|
const findUser: User = await Users.query().select().from('users').where('email', '=', userData.email).first();
|
|
30
30
|
if (!findUser) throw new HttpException(409, `You're email ${userData.email} not found`);
|
|
31
31
|
|
|
32
|
-
const isPasswordMatching: boolean = await
|
|
32
|
+
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
33
33
|
if (!isPasswordMatching) throw new HttpException(409, "You're password not matching");
|
|
34
34
|
|
|
35
35
|
const tokenData = this.createToken(findUser);
|
|
@@ -58,7 +58,7 @@ class AuthService {
|
|
|
58
58
|
const secretKey: string = config.get('secretKey');
|
|
59
59
|
const expiresIn: number = 60 * 60;
|
|
60
60
|
|
|
61
|
-
return { expiresIn, token:
|
|
61
|
+
return { expiresIn, token: sign(dataStoredInToken, secretKey, { expiresIn }) };
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
public createCookie(tokenData: TokenData): string {
|