typescript-express-starter 9.1.2 → 9.2.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 +6 -0
- package/README.md +6 -0
- package/lib/default/jest.config.js +1 -1
- package/lib/default/package.json +39 -39
- package/lib/default/src/services/auth.service.ts +6 -6
- package/lib/default/src/services/users.service.ts +6 -6
- package/lib/graphql/jest.config.js +1 -1
- package/lib/graphql/package.json +42 -42
- package/lib/graphql/src/repositories/auth.repository.ts +7 -7
- package/lib/graphql/src/repositories/users.repository.ts +8 -8
- package/lib/knex/jest.config.js +1 -1
- package/lib/knex/knexfile.ts +4 -2
- package/lib/knex/package.json +42 -42
- package/lib/knex/src/databases/migrations/20210713110926_initial.ts +1 -1
- package/lib/knex/src/services/auth.service.ts +7 -7
- package/lib/knex/src/services/users.service.ts +6 -6
- package/lib/mikro-orm/package.json +40 -40
- package/lib/mikro-orm/src/services/auth.service.ts +7 -7
- package/lib/mikro-orm/src/services/users.service.ts +8 -8
- package/lib/mongoose/jest.config.js +1 -1
- package/lib/mongoose/package.json +41 -41
- package/lib/mongoose/src/databases/index.ts +1 -2
- package/lib/mongoose/src/services/auth.service.ts +7 -7
- package/lib/mongoose/src/services/users.service.ts +8 -8
- package/lib/prisma/jest.config.js +1 -1
- package/lib/prisma/package.json +41 -41
- package/lib/prisma/src/services/auth.service.ts +7 -7
- package/lib/prisma/src/services/users.service.ts +8 -8
- package/lib/routing-controllers/jest.config.js +1 -1
- package/lib/routing-controllers/package.json +40 -40
- package/lib/routing-controllers/src/services/auth.service.ts +7 -7
- package/lib/routing-controllers/src/services/users.service.ts +6 -6
- package/lib/sequelize/jest.config.js +1 -1
- package/lib/sequelize/package.json +43 -43
- package/lib/sequelize/src/services/auth.service.ts +7 -7
- package/lib/sequelize/src/services/users.service.ts +8 -8
- package/lib/starter.js +4 -4
- package/lib/typegoose/jest.config.js +1 -1
- package/lib/typegoose/package.json +39 -39
- package/lib/typegoose/src/middlewares/validation.middleware.ts +3 -3
- package/lib/typegoose/src/services/auth.service.ts +7 -7
- package/lib/typegoose/src/services/users.service.ts +8 -8
- package/lib/typeorm/jest.config.js +1 -1
- package/lib/typeorm/package.json +41 -41
- package/lib/typeorm/src/databases/index.ts +1 -1
- package/lib/typeorm/src/services/auth.service.ts +7 -7
- package/lib/typeorm/src/services/users.service.ts +8 -8
- package/lib/typeorm/src/tests/auth.test.ts +5 -6
- package/lib/typeorm/src/tests/users.test.ts +29 -33
- package/package.json +2 -3
package/README.kr.md
CHANGED
|
@@ -371,6 +371,12 @@ VSCode Extension에서 [REST Client](https://marketplace.visualstudio.com/items?
|
|
|
371
371
|
|
|
372
372
|
- Tamzid Karim [Tamzid Karim](https://github.com/tamzidkarim)
|
|
373
373
|
|
|
374
|
+
- Andrija Milojević [https://github.com/andrija29](https://github.com/andrija29)
|
|
375
|
+
|
|
376
|
+
- Engjell Avdiu [https://github.com/engjellavdiu](https://github.com/engjellavdiu)
|
|
377
|
+
|
|
378
|
+
- Florian Mifsud [https://github.com/florianmifsud](https://github.com/florianmifsud)
|
|
379
|
+
|
|
374
380
|
## 💳 라이센스
|
|
375
381
|
|
|
376
382
|
[MIT](LICENSE)
|
package/README.md
CHANGED
|
@@ -378,6 +378,12 @@ Modify `.swcrc` file to your source code.
|
|
|
378
378
|
|
|
379
379
|
- Tamzid Karim [Tamzid Karim](https://github.com/tamzidkarim)
|
|
380
380
|
|
|
381
|
+
- Andrija Milojević [https://github.com/andrija29](https://github.com/andrija29)
|
|
382
|
+
|
|
383
|
+
- Engjell Avdiu [https://github.com/engjellavdiu](https://github.com/engjellavdiu)
|
|
384
|
+
|
|
385
|
+
- Florian Mifsud [https://github.com/florianmifsud](https://github.com/florianmifsud)
|
|
386
|
+
|
|
381
387
|
## 💳 License
|
|
382
388
|
|
|
383
389
|
[MIT](LICENSE)
|
package/lib/default/package.json
CHANGED
|
@@ -18,57 +18,57 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"bcrypt": "^5.0.1",
|
|
20
20
|
"class-transformer": "^0.5.1",
|
|
21
|
-
"class-validator": "^0.13.
|
|
21
|
+
"class-validator": "^0.13.2",
|
|
22
22
|
"compression": "^1.7.4",
|
|
23
|
-
"cookie-parser": "^1.4.
|
|
23
|
+
"cookie-parser": "^1.4.6",
|
|
24
24
|
"cors": "^2.8.5",
|
|
25
|
-
"dotenv": "^
|
|
26
|
-
"envalid": "^7.1
|
|
27
|
-
"express": "^4.
|
|
28
|
-
"helmet": "^
|
|
25
|
+
"dotenv": "^16.0.1",
|
|
26
|
+
"envalid": "^7.3.1",
|
|
27
|
+
"express": "^4.18.1",
|
|
28
|
+
"helmet": "^5.1.1",
|
|
29
29
|
"hpp": "^0.2.3",
|
|
30
30
|
"jsonwebtoken": "^8.5.1",
|
|
31
31
|
"morgan": "^1.10.0",
|
|
32
|
-
"swagger-jsdoc": "^6.
|
|
33
|
-
"swagger-ui-express": "^4.
|
|
34
|
-
"winston": "^3.
|
|
35
|
-
"winston-daily-rotate-file": "^4.
|
|
32
|
+
"swagger-jsdoc": "^6.2.1",
|
|
33
|
+
"swagger-ui-express": "^4.5.0",
|
|
34
|
+
"winston": "^3.8.1",
|
|
35
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@swc/cli": "^0.1.
|
|
39
|
-
"@swc/core": "^1.2.
|
|
38
|
+
"@swc/cli": "^0.1.57",
|
|
39
|
+
"@swc/core": "^1.2.220",
|
|
40
40
|
"@types/bcrypt": "^5.0.0",
|
|
41
|
-
"@types/compression": "^1.7.
|
|
42
|
-
"@types/cookie-parser": "^1.4.
|
|
43
|
-
"@types/cors": "^2.8.
|
|
41
|
+
"@types/compression": "^1.7.2",
|
|
42
|
+
"@types/cookie-parser": "^1.4.3",
|
|
43
|
+
"@types/cors": "^2.8.12",
|
|
44
44
|
"@types/express": "^4.17.13",
|
|
45
|
-
"@types/hpp": "^0.2.
|
|
46
|
-
"@types/jest": "
|
|
47
|
-
"@types/jsonwebtoken": "^8.5.
|
|
45
|
+
"@types/hpp": "^0.2.2",
|
|
46
|
+
"@types/jest": "^28.1.6",
|
|
47
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
48
48
|
"@types/morgan": "^1.9.3",
|
|
49
|
-
"@types/node": "^
|
|
50
|
-
"@types/supertest": "^2.0.
|
|
49
|
+
"@types/node": "^17.0.45",
|
|
50
|
+
"@types/supertest": "^2.0.12",
|
|
51
51
|
"@types/swagger-jsdoc": "^6.0.1",
|
|
52
52
|
"@types/swagger-ui-express": "^4.1.3",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
54
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
55
55
|
"cross-env": "^7.0.3",
|
|
56
|
-
"eslint": "^
|
|
57
|
-
"eslint-config-prettier": "^8.
|
|
58
|
-
"eslint-plugin-prettier": "^
|
|
59
|
-
"husky": "^
|
|
60
|
-
"jest": "
|
|
61
|
-
"lint-staged": "^
|
|
56
|
+
"eslint": "^8.20.0",
|
|
57
|
+
"eslint-config-prettier": "^8.5.0",
|
|
58
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
59
|
+
"husky": "^8.0.1",
|
|
60
|
+
"jest": "^28.1.1",
|
|
61
|
+
"lint-staged": "^13.0.3",
|
|
62
62
|
"node-config": "^0.0.2",
|
|
63
|
-
"node-gyp": "^
|
|
64
|
-
"nodemon": "^2.0.
|
|
65
|
-
"pm2": "^5.
|
|
66
|
-
"prettier": "^2.
|
|
67
|
-
"supertest": "^6.2.
|
|
68
|
-
"ts-jest": "^
|
|
69
|
-
"ts-node": "^10.
|
|
70
|
-
"tsc-alias": "^1.
|
|
71
|
-
"tsconfig-paths": "^
|
|
72
|
-
"typescript": "^4.
|
|
63
|
+
"node-gyp": "^9.1.0",
|
|
64
|
+
"nodemon": "^2.0.19",
|
|
65
|
+
"pm2": "^5.2.0",
|
|
66
|
+
"prettier": "^2.7.1",
|
|
67
|
+
"supertest": "^6.2.4",
|
|
68
|
+
"ts-jest": "^28.0.7",
|
|
69
|
+
"ts-node": "^10.9.1",
|
|
70
|
+
"tsc-alias": "^1.7.0",
|
|
71
|
+
"tsconfig-paths": "^4.0.0",
|
|
72
|
+
"typescript": "^4.7.4"
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
}
|
|
@@ -12,10 +12,10 @@ class AuthService {
|
|
|
12
12
|
public users = userModel;
|
|
13
13
|
|
|
14
14
|
public async signup(userData: CreateUserDto): Promise<User> {
|
|
15
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
15
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
16
16
|
|
|
17
17
|
const findUser: User = this.users.find(user => user.email === userData.email);
|
|
18
|
-
if (findUser) throw new HttpException(409, `
|
|
18
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
19
19
|
|
|
20
20
|
const hashedPassword = await hash(userData.password, 10);
|
|
21
21
|
const createUserData: User = { id: this.users.length + 1, ...userData, password: hashedPassword };
|
|
@@ -24,10 +24,10 @@ class AuthService {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public async login(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
|
|
27
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
27
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
28
28
|
|
|
29
29
|
const findUser: User = this.users.find(user => user.email === userData.email);
|
|
30
|
-
if (!findUser) throw new HttpException(409, `
|
|
30
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
31
31
|
|
|
32
32
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
33
33
|
if (!isPasswordMatching) throw new HttpException(409, "You're password not matching");
|
|
@@ -39,10 +39,10 @@ class AuthService {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
public async logout(userData: User): Promise<User> {
|
|
42
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
42
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
43
43
|
|
|
44
44
|
const findUser: User = this.users.find(user => user.email === userData.email && user.password === userData.password);
|
|
45
|
-
if (!findUser) throw new HttpException(409, "
|
|
45
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
46
46
|
|
|
47
47
|
return findUser;
|
|
48
48
|
}
|
|
@@ -15,16 +15,16 @@ class UserService {
|
|
|
15
15
|
|
|
16
16
|
public async findUserById(userId: number): Promise<User> {
|
|
17
17
|
const findUser: User = this.users.find(user => user.id === userId);
|
|
18
|
-
if (!findUser) throw new HttpException(409, "
|
|
18
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
19
19
|
|
|
20
20
|
return findUser;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public async createUser(userData: CreateUserDto): Promise<User> {
|
|
24
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
24
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
25
25
|
|
|
26
26
|
const findUser: User = this.users.find(user => user.email === userData.email);
|
|
27
|
-
if (findUser) throw new HttpException(409, `
|
|
27
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
28
28
|
|
|
29
29
|
const hashedPassword = await hash(userData.password, 10);
|
|
30
30
|
const createUserData: User = { id: this.users.length + 1, ...userData, password: hashedPassword };
|
|
@@ -34,10 +34,10 @@ class UserService {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
public async updateUser(userId: number, userData: CreateUserDto): Promise<User[]> {
|
|
37
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
37
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
38
38
|
|
|
39
39
|
const findUser: User = this.users.find(user => user.id === userId);
|
|
40
|
-
if (!findUser) throw new HttpException(409, "
|
|
40
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
41
41
|
|
|
42
42
|
const hashedPassword = await hash(userData.password, 10);
|
|
43
43
|
const updateUserData: User[] = this.users.map((user: User) => {
|
|
@@ -50,7 +50,7 @@ class UserService {
|
|
|
50
50
|
|
|
51
51
|
public async deleteUser(userId: number): Promise<User[]> {
|
|
52
52
|
const findUser: User = this.users.find(user => user.id === userId);
|
|
53
|
-
if (!findUser) throw new HttpException(409, "
|
|
53
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
54
54
|
|
|
55
55
|
const deleteUserData: User[] = this.users.filter(user => user.id !== findUser.id);
|
|
56
56
|
return deleteUserData;
|
package/lib/graphql/package.json
CHANGED
|
@@ -16,59 +16,59 @@
|
|
|
16
16
|
"deploy:dev": "pm2 start ecosystem.config.js --only dev"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"apollo-server-core": "^3.
|
|
20
|
-
"apollo-server-express": "^3.
|
|
19
|
+
"apollo-server-core": "^3.10.0",
|
|
20
|
+
"apollo-server-express": "^3.10.0",
|
|
21
21
|
"bcrypt": "^5.0.1",
|
|
22
|
-
"class-validator": "^0.13.
|
|
22
|
+
"class-validator": "^0.13.2",
|
|
23
23
|
"compression": "^1.7.4",
|
|
24
|
-
"cookie-parser": "^1.4.
|
|
24
|
+
"cookie-parser": "^1.4.6",
|
|
25
25
|
"cors": "^2.8.5",
|
|
26
|
-
"dotenv": "^
|
|
27
|
-
"envalid": "^7.1
|
|
28
|
-
"express": "^4.
|
|
29
|
-
"graphql": "^
|
|
30
|
-
"helmet": "^
|
|
26
|
+
"dotenv": "^16.0.1",
|
|
27
|
+
"envalid": "^7.3.1",
|
|
28
|
+
"express": "^4.18.1",
|
|
29
|
+
"graphql": "^16.5.0",
|
|
30
|
+
"helmet": "^5.1.1",
|
|
31
31
|
"hpp": "^0.2.3",
|
|
32
32
|
"jsonwebtoken": "^8.5.1",
|
|
33
|
-
"pg": "^8.7.
|
|
33
|
+
"pg": "^8.7.3",
|
|
34
34
|
"reflect-metadata": "^0.1.13",
|
|
35
35
|
"type-graphql": "^1.1.1",
|
|
36
|
-
"typeorm": "^0.2.
|
|
37
|
-
"winston": "^3.
|
|
38
|
-
"winston-daily-rotate-file": "^4.
|
|
36
|
+
"typeorm": "^0.2.45",
|
|
37
|
+
"winston": "^3.8.1",
|
|
38
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@swc/cli": "^0.1.
|
|
42
|
-
"@swc/core": "^1.2.
|
|
41
|
+
"@swc/cli": "^0.1.57",
|
|
42
|
+
"@swc/core": "^1.2.220",
|
|
43
43
|
"@types/bcrypt": "^5.0.0",
|
|
44
|
-
"@types/compression": "^1.7.
|
|
45
|
-
"@types/cookie-parser": "^1.4.
|
|
46
|
-
"@types/cors": "^2.8.
|
|
44
|
+
"@types/compression": "^1.7.2",
|
|
45
|
+
"@types/cookie-parser": "^1.4.3",
|
|
46
|
+
"@types/cors": "^2.8.12",
|
|
47
47
|
"@types/express": "^4.17.13",
|
|
48
|
-
"@types/hpp": "^0.2.
|
|
49
|
-
"@types/jest": "
|
|
50
|
-
"@types/jsonwebtoken": "^8.5.
|
|
51
|
-
"@types/node": "^
|
|
52
|
-
"@types/supertest": "^2.0.
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
48
|
+
"@types/hpp": "^0.2.2",
|
|
49
|
+
"@types/jest": "^28.1.6",
|
|
50
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
51
|
+
"@types/node": "^17.0.45",
|
|
52
|
+
"@types/supertest": "^2.0.12",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
54
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
55
55
|
"cross-env": "^7.0.3",
|
|
56
|
-
"eslint": "^
|
|
57
|
-
"eslint-config-prettier": "^8.
|
|
58
|
-
"eslint-plugin-prettier": "^
|
|
59
|
-
"husky": "^
|
|
60
|
-
"jest": "
|
|
61
|
-
"lint-staged": "^
|
|
56
|
+
"eslint": "^8.20.0",
|
|
57
|
+
"eslint-config-prettier": "^8.5.0",
|
|
58
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
59
|
+
"husky": "^8.0.1",
|
|
60
|
+
"jest": "^28.1.1",
|
|
61
|
+
"lint-staged": "^13.0.3",
|
|
62
62
|
"node-config": "^0.0.2",
|
|
63
|
-
"node-gyp": "^
|
|
64
|
-
"nodemon": "^2.0.
|
|
65
|
-
"pm2": "^5.
|
|
66
|
-
"prettier": "^2.
|
|
67
|
-
"supertest": "^6.2.
|
|
68
|
-
"ts-jest": "^
|
|
69
|
-
"ts-node": "^10.
|
|
70
|
-
"tsc-alias": "^1.
|
|
71
|
-
"tsconfig-paths": "^
|
|
72
|
-
"typescript": "^4.
|
|
63
|
+
"node-gyp": "^9.1.0",
|
|
64
|
+
"nodemon": "^2.0.19",
|
|
65
|
+
"pm2": "^5.2.0",
|
|
66
|
+
"prettier": "^2.7.1",
|
|
67
|
+
"supertest": "^6.2.4",
|
|
68
|
+
"ts-jest": "^28.0.7",
|
|
69
|
+
"ts-node": "^10.9.1",
|
|
70
|
+
"tsc-alias": "^1.7.0",
|
|
71
|
+
"tsconfig-paths": "^4.0.0",
|
|
72
|
+
"typescript": "^4.7.4"
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
}
|
|
@@ -12,10 +12,10 @@ import { isEmpty } from '@utils/util';
|
|
|
12
12
|
@EntityRepository(UserEntity)
|
|
13
13
|
export default class AuthRepository {
|
|
14
14
|
public async userSignUp(userData: CreateUserDto): Promise<User> {
|
|
15
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
15
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
16
16
|
|
|
17
17
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
18
|
-
if (findUser) throw new HttpException(409, `
|
|
18
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
19
19
|
|
|
20
20
|
const hashedPassword = await hash(userData.password, 10);
|
|
21
21
|
const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
|
|
@@ -24,13 +24,13 @@ export default class AuthRepository {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public async userLogIn(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
|
|
27
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
27
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
28
28
|
|
|
29
29
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
30
|
-
if (!findUser) throw new HttpException(409, `
|
|
30
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
31
31
|
|
|
32
32
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
33
|
-
if (!isPasswordMatching) throw new HttpException(409, "
|
|
33
|
+
if (!isPasswordMatching) throw new HttpException(409, "Password is not matching");
|
|
34
34
|
|
|
35
35
|
const tokenData = this.createToken(findUser);
|
|
36
36
|
const cookie = this.createCookie(tokenData);
|
|
@@ -39,10 +39,10 @@ export default class AuthRepository {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
public async userLogOut(userId: number): Promise<User> {
|
|
42
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
42
|
+
if (isEmpty(userId)) throw new HttpException(400, "userId is empty");
|
|
43
43
|
|
|
44
44
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
45
|
-
if (!findUser) throw new HttpException(409, "
|
|
45
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
46
46
|
|
|
47
47
|
return findUser;
|
|
48
48
|
}
|
|
@@ -15,19 +15,19 @@ export default class UserRepository {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
public async userFindById(userId: number): Promise<User> {
|
|
18
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
18
|
+
if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
|
|
19
19
|
|
|
20
20
|
const user: User = await UserEntity.findOne({ where: { id: userId } });
|
|
21
|
-
if (!user) throw new HttpException(409, "
|
|
21
|
+
if (!user) throw new HttpException(409, "User doesn't exist");
|
|
22
22
|
|
|
23
23
|
return user;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public async userCreate(userData: CreateUserDto): Promise<User> {
|
|
27
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
27
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
28
28
|
|
|
29
29
|
const findUser: User = await UserEntity.findOne({ where: { email: userData.email } });
|
|
30
|
-
if (findUser) throw new HttpException(409, `
|
|
30
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
31
31
|
|
|
32
32
|
const hashedPassword = await hash(userData.password, 10);
|
|
33
33
|
const createUserData: User = await UserEntity.create({ ...userData, password: hashedPassword }).save();
|
|
@@ -36,10 +36,10 @@ export default class UserRepository {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
public async userUpdate(userId: number, userData: CreateUserDto): Promise<User> {
|
|
39
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
39
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
40
40
|
|
|
41
41
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
42
|
-
if (!findUser) throw new HttpException(409, "
|
|
42
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
43
43
|
|
|
44
44
|
const hashedPassword = await hash(userData.password, 10);
|
|
45
45
|
await UserEntity.update(userId, { ...userData, password: hashedPassword });
|
|
@@ -49,10 +49,10 @@ export default class UserRepository {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
public async userDelete(userId: number): Promise<User> {
|
|
52
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
52
|
+
if (isEmpty(userId)) throw new HttpException(400, "User doesn't existId");
|
|
53
53
|
|
|
54
54
|
const findUser: User = await UserEntity.findOne({ where: { id: userId } });
|
|
55
|
-
if (!findUser) throw new HttpException(409, "
|
|
55
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
56
56
|
|
|
57
57
|
await UserEntity.delete({ id: userId });
|
|
58
58
|
return findUser;
|
package/lib/knex/jest.config.js
CHANGED
package/lib/knex/knexfile.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE } from './src/config';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const dbConfig = {
|
|
4
4
|
client: 'mysql',
|
|
5
5
|
connection: {
|
|
6
6
|
charset: 'utf8',
|
|
@@ -9,7 +9,7 @@ export = {
|
|
|
9
9
|
port: DB_PORT,
|
|
10
10
|
user: DB_USER,
|
|
11
11
|
password: DB_PASSWORD,
|
|
12
|
-
database: DB_DATABASE
|
|
12
|
+
database: DB_DATABASE,
|
|
13
13
|
},
|
|
14
14
|
migrations: {
|
|
15
15
|
directory: 'src/databases/migrations',
|
|
@@ -21,3 +21,5 @@ export = {
|
|
|
21
21
|
// stub: 'src/databases/stubs',
|
|
22
22
|
},
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
export default dbConfig;
|
package/lib/knex/package.json
CHANGED
|
@@ -23,61 +23,61 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"bcrypt": "^5.0.1",
|
|
25
25
|
"class-transformer": "^0.5.1",
|
|
26
|
-
"class-validator": "^0.13.
|
|
26
|
+
"class-validator": "^0.13.2",
|
|
27
27
|
"compression": "^1.7.4",
|
|
28
|
-
"cookie-parser": "^1.4.
|
|
28
|
+
"cookie-parser": "^1.4.6",
|
|
29
29
|
"cors": "^2.8.5",
|
|
30
|
-
"dotenv": "^
|
|
31
|
-
"envalid": "^7.1
|
|
32
|
-
"express": "^4.
|
|
33
|
-
"helmet": "^
|
|
30
|
+
"dotenv": "^16.0.1",
|
|
31
|
+
"envalid": "^7.3.1",
|
|
32
|
+
"express": "^4.18.1",
|
|
33
|
+
"helmet": "^5.1.1",
|
|
34
34
|
"hpp": "^0.2.3",
|
|
35
35
|
"jsonwebtoken": "^8.5.1",
|
|
36
|
-
"knex": "^
|
|
36
|
+
"knex": "^2.2.0",
|
|
37
37
|
"morgan": "^1.10.0",
|
|
38
38
|
"mysql": "^2.18.1",
|
|
39
|
-
"objection": "^
|
|
40
|
-
"swagger-jsdoc": "^6.
|
|
41
|
-
"swagger-ui-express": "^4.
|
|
42
|
-
"winston": "^3.
|
|
43
|
-
"winston-daily-rotate-file": "^4.
|
|
39
|
+
"objection": "^3.0.1",
|
|
40
|
+
"swagger-jsdoc": "^6.2.1",
|
|
41
|
+
"swagger-ui-express": "^4.5.0",
|
|
42
|
+
"winston": "^3.8.1",
|
|
43
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@swc/cli": "^0.1.
|
|
47
|
-
"@swc/core": "^1.2.
|
|
46
|
+
"@swc/cli": "^0.1.57",
|
|
47
|
+
"@swc/core": "^1.2.220",
|
|
48
48
|
"@types/bcrypt": "^5.0.0",
|
|
49
|
-
"@types/compression": "^1.7.
|
|
50
|
-
"@types/cookie-parser": "^1.4.
|
|
51
|
-
"@types/cors": "^2.8.
|
|
49
|
+
"@types/compression": "^1.7.2",
|
|
50
|
+
"@types/cookie-parser": "^1.4.3",
|
|
51
|
+
"@types/cors": "^2.8.12",
|
|
52
52
|
"@types/express": "^4.17.13",
|
|
53
|
-
"@types/hpp": "^0.2.
|
|
54
|
-
"@types/jest": "
|
|
55
|
-
"@types/jsonwebtoken": "^8.5.
|
|
53
|
+
"@types/hpp": "^0.2.2",
|
|
54
|
+
"@types/jest": "^28.1.6",
|
|
55
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
56
56
|
"@types/knex": "^0.16.1",
|
|
57
57
|
"@types/morgan": "^1.9.3",
|
|
58
|
-
"@types/node": "^
|
|
59
|
-
"@types/supertest": "^2.0.
|
|
58
|
+
"@types/node": "^17.0.45",
|
|
59
|
+
"@types/supertest": "^2.0.12",
|
|
60
60
|
"@types/swagger-jsdoc": "^6.0.1",
|
|
61
61
|
"@types/swagger-ui-express": "^4.1.3",
|
|
62
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
63
|
-
"@typescript-eslint/parser": "^
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
63
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
64
64
|
"cross-env": "^7.0.3",
|
|
65
|
-
"eslint": "^
|
|
66
|
-
"eslint-config-prettier": "^8.
|
|
67
|
-
"eslint-plugin-prettier": "^
|
|
68
|
-
"husky": "^
|
|
69
|
-
"jest": "
|
|
70
|
-
"lint-staged": "^
|
|
71
|
-
"node-config": "0.0.2",
|
|
72
|
-
"node-gyp": "^
|
|
73
|
-
"nodemon": "^2.0.
|
|
74
|
-
"pm2": "^5.
|
|
75
|
-
"prettier": "^2.
|
|
76
|
-
"supertest": "^6.2.
|
|
77
|
-
"ts-jest": "^
|
|
78
|
-
"ts-node": "^10.
|
|
79
|
-
"tsc-alias": "^1.
|
|
80
|
-
"tsconfig-paths": "^
|
|
81
|
-
"typescript": "^4.
|
|
65
|
+
"eslint": "^8.20.0",
|
|
66
|
+
"eslint-config-prettier": "^8.5.0",
|
|
67
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
68
|
+
"husky": "^8.0.1",
|
|
69
|
+
"jest": "^28.1.1",
|
|
70
|
+
"lint-staged": "^13.0.3",
|
|
71
|
+
"node-config": "^0.0.2",
|
|
72
|
+
"node-gyp": "^9.1.0",
|
|
73
|
+
"nodemon": "^2.0.19",
|
|
74
|
+
"pm2": "^5.2.0",
|
|
75
|
+
"prettier": "^2.7.1",
|
|
76
|
+
"supertest": "^6.2.4",
|
|
77
|
+
"ts-jest": "^28.0.7",
|
|
78
|
+
"ts-node": "^10.9.1",
|
|
79
|
+
"tsc-alias": "^1.7.0",
|
|
80
|
+
"tsconfig-paths": "^4.0.0",
|
|
81
|
+
"typescript": "^4.7.4"
|
|
82
82
|
}
|
|
83
|
-
}
|
|
83
|
+
}
|
|
@@ -10,10 +10,10 @@ import { isEmpty } from '@utils/util';
|
|
|
10
10
|
|
|
11
11
|
class AuthService {
|
|
12
12
|
public async signup(userData: CreateUserDto): Promise<User> {
|
|
13
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
13
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
14
14
|
|
|
15
15
|
const findUser: Users = await Users.query().select().from('users').where('email', '=', userData.email).first();
|
|
16
|
-
if (findUser) throw new HttpException(409, `
|
|
16
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
17
17
|
|
|
18
18
|
const hashedPassword = await hash(userData.password, 10);
|
|
19
19
|
const createUserData: User = await Users.query()
|
|
@@ -24,13 +24,13 @@ class AuthService {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
public async login(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
|
|
27
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
27
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
28
28
|
|
|
29
29
|
const findUser: User = await Users.query().select().from('users').where('email', '=', userData.email).first();
|
|
30
|
-
if (!findUser) throw new HttpException(409, `
|
|
30
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
31
31
|
|
|
32
32
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
33
|
-
if (!isPasswordMatching) throw new HttpException(409, "
|
|
33
|
+
if (!isPasswordMatching) throw new HttpException(409, "Password is not matching");
|
|
34
34
|
|
|
35
35
|
const tokenData = this.createToken(findUser);
|
|
36
36
|
const cookie = this.createCookie(tokenData);
|
|
@@ -39,7 +39,7 @@ class AuthService {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
public async logout(userData: User): Promise<User> {
|
|
42
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
42
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
43
43
|
|
|
44
44
|
const findUser: User = await Users.query()
|
|
45
45
|
.select()
|
|
@@ -48,7 +48,7 @@ class AuthService {
|
|
|
48
48
|
.andWhere('password', '=', userData.password)
|
|
49
49
|
.first();
|
|
50
50
|
|
|
51
|
-
if (!findUser) throw new HttpException(409, "
|
|
51
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
52
52
|
|
|
53
53
|
return findUser;
|
|
54
54
|
}
|