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
|
@@ -13,16 +13,16 @@ class UserService {
|
|
|
13
13
|
|
|
14
14
|
public async findUserById(userId: number): Promise<User> {
|
|
15
15
|
const findUser: User = await Users.query().findById(userId);
|
|
16
|
-
if (!findUser) throw new HttpException(409, "
|
|
16
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
17
17
|
|
|
18
18
|
return findUser;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
public async createUser(userData: CreateUserDto): Promise<User> {
|
|
22
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
22
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
23
23
|
|
|
24
24
|
const findUser: User = await Users.query().select().from('users').where('email', '=', userData.email).first();
|
|
25
|
-
if (findUser) throw new HttpException(409, `
|
|
25
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
26
26
|
|
|
27
27
|
const hashedPassword = await hash(userData.password, 10);
|
|
28
28
|
const createUserData: User = await Users.query()
|
|
@@ -33,10 +33,10 @@ class UserService {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
public async updateUser(userId: number, userData: User): Promise<User> {
|
|
36
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
36
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
37
37
|
|
|
38
38
|
const findUser: User[] = await Users.query().select().from('users').where('id', '=', userId);
|
|
39
|
-
if (!findUser) throw new HttpException(409, "
|
|
39
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
40
40
|
|
|
41
41
|
const hashedPassword = await hash(userData.password, 10);
|
|
42
42
|
await Users.query()
|
|
@@ -50,7 +50,7 @@ class UserService {
|
|
|
50
50
|
|
|
51
51
|
public async deleteUser(userId: number): Promise<User> {
|
|
52
52
|
const findUser: User = await Users.query().select().from('users').where('id', '=', userId).first();
|
|
53
|
-
if (!findUser) throw new HttpException(409, "
|
|
53
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
54
54
|
|
|
55
55
|
await Users.query().delete().where('id', '=', userId).into('users');
|
|
56
56
|
return findUser;
|
|
@@ -16,62 +16,62 @@
|
|
|
16
16
|
"deploy:dev": "pm2 start ecosystem.config.js --only dev"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@mikro-orm/core": "^5.
|
|
20
|
-
"@mikro-orm/mongodb": "^5.
|
|
19
|
+
"@mikro-orm/core": "^5.2.4",
|
|
20
|
+
"@mikro-orm/mongodb": "^5.2.4",
|
|
21
21
|
"bcrypt": "^5.0.1",
|
|
22
22
|
"class-transformer": "^0.5.1",
|
|
23
|
-
"class-validator": "^0.13.
|
|
23
|
+
"class-validator": "^0.13.2",
|
|
24
24
|
"compression": "^1.7.4",
|
|
25
|
-
"cookie-parser": "^1.4.
|
|
25
|
+
"cookie-parser": "^1.4.6",
|
|
26
26
|
"cors": "^2.8.5",
|
|
27
|
-
"dotenv": "^
|
|
28
|
-
"envalid": "^7.1
|
|
29
|
-
"express": "^4.
|
|
30
|
-
"helmet": "^
|
|
27
|
+
"dotenv": "^16.0.1",
|
|
28
|
+
"envalid": "^7.3.1",
|
|
29
|
+
"express": "^4.18.1",
|
|
30
|
+
"helmet": "^5.1.1",
|
|
31
31
|
"hpp": "^0.2.3",
|
|
32
32
|
"jsonwebtoken": "^8.5.1",
|
|
33
33
|
"morgan": "^1.10.0",
|
|
34
|
-
"swagger-jsdoc": "^6.
|
|
35
|
-
"swagger-ui-express": "^4.
|
|
36
|
-
"winston": "^3.
|
|
37
|
-
"winston-daily-rotate-file": "^4.
|
|
34
|
+
"swagger-jsdoc": "^6.2.1",
|
|
35
|
+
"swagger-ui-express": "^4.5.0",
|
|
36
|
+
"winston": "^3.8.1",
|
|
37
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@mikro-orm/mongo-highlighter": "^1.0.0",
|
|
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.
|
|
48
|
+
"@types/hpp": "^0.2.2",
|
|
49
|
+
"@types/jest": "^28.1.6",
|
|
50
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
51
51
|
"@types/morgan": "^1.9.3",
|
|
52
|
-
"@types/node": "^
|
|
53
|
-
"@types/supertest": "^2.0.
|
|
52
|
+
"@types/node": "^17.0.45",
|
|
53
|
+
"@types/supertest": "^2.0.12",
|
|
54
54
|
"@types/swagger-jsdoc": "^6.0.1",
|
|
55
55
|
"@types/swagger-ui-express": "^4.1.3",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
57
|
-
"@typescript-eslint/parser": "^
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
57
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
58
58
|
"cross-env": "^7.0.3",
|
|
59
|
-
"eslint": "^
|
|
60
|
-
"eslint-config-prettier": "^8.
|
|
61
|
-
"eslint-plugin-prettier": "^
|
|
62
|
-
"husky": "^
|
|
63
|
-
"jest": "
|
|
64
|
-
"lint-staged": "^
|
|
59
|
+
"eslint": "^8.20.0",
|
|
60
|
+
"eslint-config-prettier": "^8.5.0",
|
|
61
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
62
|
+
"husky": "^8.0.1",
|
|
63
|
+
"jest": "^28.1.1",
|
|
64
|
+
"lint-staged": "^13.0.3",
|
|
65
65
|
"node-config": "^0.0.2",
|
|
66
|
-
"node-gyp": "^
|
|
67
|
-
"nodemon": "^2.0.
|
|
68
|
-
"pm2": "^5.
|
|
69
|
-
"prettier": "^2.
|
|
70
|
-
"supertest": "^6.2.
|
|
71
|
-
"ts-jest": "^
|
|
72
|
-
"ts-node": "^10.
|
|
73
|
-
"tsc-alias": "^1.
|
|
74
|
-
"tsconfig-paths": "^
|
|
75
|
-
"typescript": "^4.
|
|
66
|
+
"node-gyp": "^9.1.0",
|
|
67
|
+
"nodemon": "^2.0.19",
|
|
68
|
+
"pm2": "^5.2.0",
|
|
69
|
+
"prettier": "^2.7.1",
|
|
70
|
+
"supertest": "^6.2.4",
|
|
71
|
+
"ts-jest": "^28.0.7",
|
|
72
|
+
"ts-node": "^10.9.1",
|
|
73
|
+
"tsc-alias": "^1.7.0",
|
|
74
|
+
"tsconfig-paths": "^4.0.0",
|
|
75
|
+
"typescript": "^4.7.4"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -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: User = await DI.userRepository.findOne({ email: userData.email });
|
|
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 = DI.userRepository.create({ ...userData, password: hashedPassword });
|
|
@@ -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 DI.userRepository.findOne({ 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 @@ 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 DI.userRepository.findOne({ email: userData.email, password: userData.password });
|
|
45
|
-
if (!findUser) throw new HttpException(409, `
|
|
45
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
46
46
|
|
|
47
47
|
return findUser;
|
|
48
48
|
}
|
|
@@ -13,19 +13,19 @@ class UserService {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
public async findUserById(userId: string): Promise<User> {
|
|
16
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
16
|
+
if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
|
|
17
17
|
|
|
18
18
|
const findUser: User = await DI.userRepository.findOne(userId);
|
|
19
|
-
if (!findUser) throw new HttpException(409, "
|
|
19
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
20
20
|
|
|
21
21
|
return findUser;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
public async createUser(userData: CreateUserDto): Promise<User> {
|
|
25
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
25
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
26
26
|
|
|
27
27
|
const findUser: User = await DI.userRepository.findOne({ email: userData.email });
|
|
28
|
-
if (findUser) throw new HttpException(409, `
|
|
28
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
29
29
|
|
|
30
30
|
const hashedPassword = await hash(userData.password, 10);
|
|
31
31
|
const createUserData: User = DI.userRepository.create({ ...userData, password: hashedPassword });
|
|
@@ -36,11 +36,11 @@ class UserService {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
public async updateUser(userId: string, 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
|
if (userData.email) {
|
|
42
42
|
const findUser: User = await DI.userRepository.findOne({ email: userData.email });
|
|
43
|
-
if (findUser && findUser.id !== userId) throw new HttpException(409, `
|
|
43
|
+
if (findUser && findUser.id !== userId) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
if (userData.password) {
|
|
@@ -50,7 +50,7 @@ class UserService {
|
|
|
50
50
|
|
|
51
51
|
const updateUserById: User = await DI.userRepository.findOne(userId);
|
|
52
52
|
wrap(updateUserById).assign(userData);
|
|
53
|
-
if (!updateUserById) throw new HttpException(409, "
|
|
53
|
+
if (!updateUserById) throw new HttpException(409, "User doesn't exist");
|
|
54
54
|
|
|
55
55
|
return updateUserById;
|
|
56
56
|
}
|
|
@@ -58,7 +58,7 @@ class UserService {
|
|
|
58
58
|
public async deleteUser(userId: string): Promise<User> {
|
|
59
59
|
const findUser = await DI.userRepository.findOne(userId);
|
|
60
60
|
|
|
61
|
-
if (!findUser) throw new HttpException(409, "
|
|
61
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
62
62
|
await DI.userRepository.removeAndFlush(findUser);
|
|
63
63
|
|
|
64
64
|
return findUser;
|
|
@@ -18,59 +18,59 @@
|
|
|
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
|
-
"mongoose": "^5.
|
|
31
|
+
"mongoose": "^6.5.0",
|
|
32
32
|
"morgan": "^1.10.0",
|
|
33
|
-
"swagger-jsdoc": "^6.
|
|
34
|
-
"swagger-ui-express": "^4.
|
|
35
|
-
"winston": "^3.
|
|
36
|
-
"winston-daily-rotate-file": "^4.
|
|
33
|
+
"swagger-jsdoc": "^6.2.1",
|
|
34
|
+
"swagger-ui-express": "^4.5.0",
|
|
35
|
+
"winston": "^3.8.1",
|
|
36
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@swc/cli": "^0.1.
|
|
40
|
-
"@swc/core": "^1.2.
|
|
39
|
+
"@swc/cli": "^0.1.57",
|
|
40
|
+
"@swc/core": "^1.2.220",
|
|
41
41
|
"@types/bcrypt": "^5.0.0",
|
|
42
|
-
"@types/compression": "^1.7.
|
|
43
|
-
"@types/cookie-parser": "^1.4.
|
|
44
|
-
"@types/cors": "^2.8.
|
|
42
|
+
"@types/compression": "^1.7.2",
|
|
43
|
+
"@types/cookie-parser": "^1.4.3",
|
|
44
|
+
"@types/cors": "^2.8.12",
|
|
45
45
|
"@types/express": "^4.17.13",
|
|
46
|
-
"@types/hpp": "^0.2.
|
|
47
|
-
"@types/jest": "
|
|
48
|
-
"@types/jsonwebtoken": "^8.5.
|
|
49
|
-
"@types/mongoose": "^5.
|
|
46
|
+
"@types/hpp": "^0.2.2",
|
|
47
|
+
"@types/jest": "^28.1.6",
|
|
48
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
49
|
+
"@types/mongoose": "^5.11.97",
|
|
50
50
|
"@types/morgan": "^1.9.3",
|
|
51
|
-
"@types/node": "^
|
|
52
|
-
"@types/supertest": "^2.0.
|
|
51
|
+
"@types/node": "^17.0.45",
|
|
52
|
+
"@types/supertest": "^2.0.12",
|
|
53
53
|
"@types/swagger-jsdoc": "^6.0.1",
|
|
54
54
|
"@types/swagger-ui-express": "^4.1.3",
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
56
|
-
"@typescript-eslint/parser": "^
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
56
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
57
57
|
"cross-env": "^7.0.3",
|
|
58
|
-
"eslint": "^
|
|
59
|
-
"eslint-config-prettier": "^8.
|
|
60
|
-
"eslint-plugin-prettier": "^
|
|
61
|
-
"husky": "^
|
|
62
|
-
"jest": "
|
|
63
|
-
"lint-staged": "^
|
|
58
|
+
"eslint": "^8.20.0",
|
|
59
|
+
"eslint-config-prettier": "^8.5.0",
|
|
60
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
61
|
+
"husky": "^8.0.1",
|
|
62
|
+
"jest": "^28.1.1",
|
|
63
|
+
"lint-staged": "^13.0.3",
|
|
64
64
|
"node-config": "^0.0.2",
|
|
65
|
-
"node-gyp": "^
|
|
66
|
-
"nodemon": "^2.0.
|
|
67
|
-
"pm2": "^5.
|
|
68
|
-
"prettier": "^2.
|
|
69
|
-
"supertest": "^6.2.
|
|
70
|
-
"ts-jest": "^
|
|
71
|
-
"ts-node": "^10.
|
|
72
|
-
"tsc-alias": "^1.
|
|
73
|
-
"tsconfig-paths": "^
|
|
74
|
-
"typescript": "^4.
|
|
65
|
+
"node-gyp": "^9.1.0",
|
|
66
|
+
"nodemon": "^2.0.19",
|
|
67
|
+
"pm2": "^5.2.0",
|
|
68
|
+
"prettier": "^2.7.1",
|
|
69
|
+
"supertest": "^6.2.4",
|
|
70
|
+
"ts-jest": "^28.0.7",
|
|
71
|
+
"ts-node": "^10.9.1",
|
|
72
|
+
"tsc-alias": "^1.7.0",
|
|
73
|
+
"tsconfig-paths": "^4.0.0",
|
|
74
|
+
"typescript": "^4.7.4"
|
|
75
75
|
}
|
|
76
|
-
}
|
|
76
|
+
}
|
|
@@ -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 = await this.users.findOne({ 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 this.users.create({ ...userData, password: hashedPassword });
|
|
@@ -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 this.users.findOne({ 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 @@ 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 this.users.findOne({ email: userData.email, password: userData.password });
|
|
45
|
-
if (!findUser) throw new HttpException(409, `
|
|
45
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
46
46
|
|
|
47
47
|
return findUser;
|
|
48
48
|
}
|
|
@@ -14,19 +14,19 @@ class UserService {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
public async findUserById(userId: string): Promise<User> {
|
|
17
|
-
if (isEmpty(userId)) throw new HttpException(400, "
|
|
17
|
+
if (isEmpty(userId)) throw new HttpException(400, "UserId is empty");
|
|
18
18
|
|
|
19
19
|
const findUser: User = await this.users.findOne({ _id: userId });
|
|
20
|
-
if (!findUser) throw new HttpException(409, "
|
|
20
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
21
21
|
|
|
22
22
|
return findUser;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
public async createUser(userData: CreateUserDto): Promise<User> {
|
|
26
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
26
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
27
27
|
|
|
28
28
|
const findUser: User = await this.users.findOne({ email: userData.email });
|
|
29
|
-
if (findUser) throw new HttpException(409, `
|
|
29
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
30
30
|
|
|
31
31
|
const hashedPassword = await hash(userData.password, 10);
|
|
32
32
|
const createUserData: User = await this.users.create({ ...userData, password: hashedPassword });
|
|
@@ -35,11 +35,11 @@ class UserService {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public async updateUser(userId: string, userData: CreateUserDto): Promise<User> {
|
|
38
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
38
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
39
39
|
|
|
40
40
|
if (userData.email) {
|
|
41
41
|
const findUser: User = await this.users.findOne({ email: userData.email });
|
|
42
|
-
if (findUser && findUser._id != userId) throw new HttpException(409, `
|
|
42
|
+
if (findUser && findUser._id != userId) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (userData.password) {
|
|
@@ -48,14 +48,14 @@ class UserService {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
const updateUserById: User = await this.users.findByIdAndUpdate(userId, { userData });
|
|
51
|
-
if (!updateUserById) throw new HttpException(409, "
|
|
51
|
+
if (!updateUserById) throw new HttpException(409, "User doesn't exist");
|
|
52
52
|
|
|
53
53
|
return updateUserById;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
public async deleteUser(userId: string): Promise<User> {
|
|
57
57
|
const deleteUserById: User = await this.users.findByIdAndDelete(userId);
|
|
58
|
-
if (!deleteUserById) throw new HttpException(409, "
|
|
58
|
+
if (!deleteUserById) throw new HttpException(409, "User doesn't exist");
|
|
59
59
|
|
|
60
60
|
return deleteUserById;
|
|
61
61
|
}
|
package/lib/prisma/package.json
CHANGED
|
@@ -22,61 +22,61 @@
|
|
|
22
22
|
"schema": "src/prisma/schema.prisma"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@prisma/client": "^
|
|
25
|
+
"@prisma/client": "^4.1.0",
|
|
26
26
|
"bcrypt": "^5.0.1",
|
|
27
27
|
"class-transformer": "^0.5.1",
|
|
28
|
-
"class-validator": "^0.13.
|
|
28
|
+
"class-validator": "^0.13.2",
|
|
29
29
|
"compression": "^1.7.4",
|
|
30
|
-
"cookie-parser": "^1.4.
|
|
30
|
+
"cookie-parser": "^1.4.6",
|
|
31
31
|
"cors": "^2.8.5",
|
|
32
|
-
"dotenv": "^
|
|
33
|
-
"envalid": "^7.1
|
|
34
|
-
"express": "^4.
|
|
35
|
-
"helmet": "^
|
|
32
|
+
"dotenv": "^16.0.1",
|
|
33
|
+
"envalid": "^7.3.1",
|
|
34
|
+
"express": "^4.18.1",
|
|
35
|
+
"helmet": "^5.1.1",
|
|
36
36
|
"hpp": "^0.2.3",
|
|
37
37
|
"jsonwebtoken": "^8.5.1",
|
|
38
38
|
"morgan": "^1.10.0",
|
|
39
|
-
"swagger-jsdoc": "^6.
|
|
40
|
-
"swagger-ui-express": "^4.
|
|
41
|
-
"winston": "^3.
|
|
42
|
-
"winston-daily-rotate-file": "^4.
|
|
39
|
+
"swagger-jsdoc": "^6.2.1",
|
|
40
|
+
"swagger-ui-express": "^4.5.0",
|
|
41
|
+
"winston": "^3.8.1",
|
|
42
|
+
"winston-daily-rotate-file": "^4.7.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@swc/cli": "^0.1.
|
|
46
|
-
"@swc/core": "^1.2.
|
|
45
|
+
"@swc/cli": "^0.1.57",
|
|
46
|
+
"@swc/core": "^1.2.220",
|
|
47
47
|
"@types/bcrypt": "^5.0.0",
|
|
48
|
-
"@types/compression": "^1.7.
|
|
49
|
-
"@types/cookie-parser": "^1.4.
|
|
50
|
-
"@types/cors": "^2.8.
|
|
48
|
+
"@types/compression": "^1.7.2",
|
|
49
|
+
"@types/cookie-parser": "^1.4.3",
|
|
50
|
+
"@types/cors": "^2.8.12",
|
|
51
51
|
"@types/express": "^4.17.13",
|
|
52
|
-
"@types/hpp": "^0.2.
|
|
53
|
-
"@types/jest": "
|
|
54
|
-
"@types/jsonwebtoken": "^8.5.
|
|
52
|
+
"@types/hpp": "^0.2.2",
|
|
53
|
+
"@types/jest": "^28.1.6",
|
|
54
|
+
"@types/jsonwebtoken": "^8.5.8",
|
|
55
55
|
"@types/morgan": "^1.9.3",
|
|
56
|
-
"@types/node": "^
|
|
57
|
-
"@types/supertest": "^2.0.
|
|
56
|
+
"@types/node": "^17.0.45",
|
|
57
|
+
"@types/supertest": "^2.0.12",
|
|
58
58
|
"@types/swagger-jsdoc": "^6.0.1",
|
|
59
59
|
"@types/swagger-ui-express": "^4.1.3",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
61
|
-
"@typescript-eslint/parser": "^
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^5.29.0",
|
|
61
|
+
"@typescript-eslint/parser": "^5.29.0",
|
|
62
62
|
"cross-env": "^7.0.3",
|
|
63
|
-
"eslint": "^
|
|
64
|
-
"eslint-config-prettier": "^8.
|
|
65
|
-
"eslint-plugin-prettier": "^
|
|
66
|
-
"husky": "^
|
|
67
|
-
"jest": "
|
|
68
|
-
"lint-staged": "^
|
|
63
|
+
"eslint": "^8.20.0",
|
|
64
|
+
"eslint-config-prettier": "^8.5.0",
|
|
65
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
66
|
+
"husky": "^8.0.1",
|
|
67
|
+
"jest": "^28.1.1",
|
|
68
|
+
"lint-staged": "^13.0.3",
|
|
69
69
|
"node-config": "^0.0.2",
|
|
70
|
-
"node-gyp": "^
|
|
71
|
-
"nodemon": "^2.0.
|
|
72
|
-
"pm2": "^5.
|
|
73
|
-
"prettier": "^2.
|
|
74
|
-
"prisma": "^
|
|
75
|
-
"supertest": "^6.2.
|
|
76
|
-
"ts-jest": "^
|
|
77
|
-
"ts-node": "^10.
|
|
78
|
-
"tsc-alias": "^1.
|
|
79
|
-
"tsconfig-paths": "^
|
|
80
|
-
"typescript": "^4.
|
|
70
|
+
"node-gyp": "^9.1.0",
|
|
71
|
+
"nodemon": "^2.0.19",
|
|
72
|
+
"pm2": "^5.2.0",
|
|
73
|
+
"prettier": "^2.7.1",
|
|
74
|
+
"prisma": "^4.1.0",
|
|
75
|
+
"supertest": "^6.2.4",
|
|
76
|
+
"ts-jest": "^28.0.7",
|
|
77
|
+
"ts-node": "^10.9.1",
|
|
78
|
+
"tsc-alias": "^1.7.0",
|
|
79
|
+
"tsconfig-paths": "^4.0.0",
|
|
80
|
+
"typescript": "^4.7.4"
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
}
|
|
@@ -11,10 +11,10 @@ class AuthService {
|
|
|
11
11
|
public users = new PrismaClient().user;
|
|
12
12
|
|
|
13
13
|
public async signup(userData: CreateUserDto): Promise<User> {
|
|
14
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
14
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
15
15
|
|
|
16
16
|
const findUser: User = await this.users.findUnique({ where: { email: userData.email } });
|
|
17
|
-
if (findUser) throw new HttpException(409, `
|
|
17
|
+
if (findUser) throw new HttpException(409, `This email ${userData.email} already exists`);
|
|
18
18
|
|
|
19
19
|
const hashedPassword = await hash(userData.password, 10);
|
|
20
20
|
const createUserData: Promise<User> = this.users.create({ data: { ...userData, password: hashedPassword } });
|
|
@@ -23,13 +23,13 @@ class AuthService {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
public async login(userData: CreateUserDto): Promise<{ cookie: string; findUser: User }> {
|
|
26
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
26
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
27
27
|
|
|
28
28
|
const findUser: User = await this.users.findUnique({ where: { email: userData.email } });
|
|
29
|
-
if (!findUser) throw new HttpException(409, `
|
|
29
|
+
if (!findUser) throw new HttpException(409, `This email ${userData.email} was not found`);
|
|
30
30
|
|
|
31
31
|
const isPasswordMatching: boolean = await compare(userData.password, findUser.password);
|
|
32
|
-
if (!isPasswordMatching) throw new HttpException(409, "
|
|
32
|
+
if (!isPasswordMatching) throw new HttpException(409, "Password is not matching");
|
|
33
33
|
|
|
34
34
|
const tokenData = this.createToken(findUser);
|
|
35
35
|
const cookie = this.createCookie(tokenData);
|
|
@@ -38,10 +38,10 @@ class AuthService {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
public async logout(userData: User): Promise<User> {
|
|
41
|
-
if (isEmpty(userData)) throw new HttpException(400, "
|
|
41
|
+
if (isEmpty(userData)) throw new HttpException(400, "userData is empty");
|
|
42
42
|
|
|
43
43
|
const findUser: User = await this.users.findFirst({ where: { email: userData.email, password: userData.password } });
|
|
44
|
-
if (!findUser) throw new HttpException(409, "
|
|
44
|
+
if (!findUser) throw new HttpException(409, "User doesn't exist");
|
|
45
45
|
|
|
46
46
|
return findUser;
|
|
47
47
|
}
|