Skip to content

Commit 114435b

Browse files
Merge pull request #353 from andrechristikan/development
Development
2 parents 78aeceb + 7136118 commit 114435b

File tree

5 files changed

+296
-95
lines changed

5 files changed

+296
-95
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ack-nestjs-boilerplate",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"description": "Ack NestJs Boilerplate",
55
"repository": {
66
"type": "git",
@@ -51,7 +51,7 @@
5151
"rollback": "yarn rollback:setting && yarn rollback:apikey && yarn rollback:user && yarn rollback:role && yarn rollback:permission"
5252
},
5353
"dependencies": {
54-
"@aws-sdk/client-s3": "^3.241.0",
54+
"@aws-sdk/client-s3": "^3.245.0",
5555
"@faker-js/faker": "^7.6.0",
5656
"@joi/date": "^2.1.0",
5757
"@nestjs/axios": "^1.0.1",
@@ -75,11 +75,11 @@
7575
"helmet": "^6.0.1",
7676
"joi": "^17.7.0",
7777
"moment": "^2.29.4",
78-
"mongoose": "^6.8.2",
78+
"mongoose": "^6.8.3",
7979
"morgan": "^1.10.0",
8080
"nest-winston": "^1.8.0",
81-
"nestjs-command": "^3.1.2",
82-
"nestjs-i18n": "^10.2.3",
81+
"nestjs-command": "^3.1.3",
82+
"nestjs-i18n": "^10.2.4",
8383
"passport": "^0.6.0",
8484
"passport-headerapikey": "^1.2.2",
8585
"passport-jwt": "^4.0.1",
@@ -116,21 +116,21 @@
116116
"@types/supertest": "^2.0.12",
117117
"@types/ua-parser-js": "^0.7.36",
118118
"@types/uuid": "^9.0.0",
119-
"@typescript-eslint/eslint-plugin": "^5.47.1",
120-
"@typescript-eslint/parser": "^5.47.1",
119+
"@typescript-eslint/eslint-plugin": "^5.48.0",
120+
"@typescript-eslint/parser": "^5.48.0",
121121
"cspell": "^6.18.1",
122122
"eslint": "^8.31.0",
123-
"eslint-config-prettier": "^8.5.0",
123+
"eslint-config-prettier": "^8.6.0",
124124
"eslint-plugin-import": "^2.26.0",
125-
"husky": "^8.0.2",
125+
"husky": "^8.0.3",
126126
"jest": "^29.3.1",
127-
"prettier": "^2.8.1",
127+
"prettier": "^2.8.2",
128128
"supertest": "^6.3.3",
129129
"ts-jest": "^29.0.3",
130130
"ts-loader": "^9.4.2",
131131
"ts-node": "^10.9.1",
132132
"ts-prune": "^0.10.3",
133-
"tsconfig-paths": "^4.1.1",
133+
"tsconfig-paths": "^4.1.2",
134134
"typescript": "^4.9.4"
135135
}
136136
}

src/common/api-key/constants/api-key.status-code.constant.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ export enum ENUM_API_KEY_STATUS_CODE_ERROR {
55
API_KEY_EXPIRED_ERROR = 5123,
66
API_KEY_INACTIVE_ERROR = 5124,
77
API_KEY_INVALID_ERROR = 5125,
8-
API_KEY_PREFIX_INVALID_ERROR = 5126,
9-
API_KEY_WRONG_ERROR = 5127,
8+
API_KEY_WRONG_ERROR = 5126,
109
}

src/common/api-key/guards/x-api-key/api-key.x-api-key.guard.ts

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,67 +25,59 @@ export class ApiKeyXApiKeyGuard extends AuthGuard('api-key') {
2525
): IApiKeyPayload {
2626
if (err || !apiKey) {
2727
if (
28-
info instanceof Error &&
29-
info.name === 'BadRequestError' &&
30-
info.message === 'Missing API Key'
28+
(info instanceof Error &&
29+
info.name === 'BadRequestError' &&
30+
info.message === 'Missing API Key') ||
31+
!apiKey
3132
) {
3233
throw new UnauthorizedException({
3334
statusCode:
3435
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NEEDED_ERROR,
3536
message: 'apiKey.error.keyNeeded',
3637
});
37-
} else if (
38-
info instanceof Error &&
39-
info.name === 'BadRequestError' &&
40-
info.message.startsWith('Invalid API Key prefix')
41-
) {
42-
throw new ForbiddenException({
43-
statusCode:
44-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_PREFIX_INVALID_ERROR,
45-
message: 'apiKey.error.prefixInvalid',
46-
});
47-
}
38+
} else if (err) {
39+
const statusCode: number = this.helperNumberService.create(
40+
err.message as string
41+
);
4842

49-
const statusCode: number = this.helperNumberService.create(
50-
err.message as string
51-
);
52-
53-
if (
54-
statusCode ===
55-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR
56-
) {
57-
throw new ForbiddenException({
58-
statusCode,
59-
message: 'apiKey.error.notFound',
60-
});
61-
} else if (
62-
statusCode ===
63-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_IS_ACTIVE_ERROR
64-
) {
65-
throw new ForbiddenException({
66-
statusCode,
67-
message: 'apiKey.error.inactive',
68-
});
69-
} else if (
70-
statusCode ===
71-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_EXPIRED_ERROR
72-
) {
73-
throw new ForbiddenException({
74-
statusCode,
75-
message: 'apiKey.error.expired',
76-
});
77-
} else if (
78-
statusCode ===
79-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_WRONG_ERROR
80-
) {
81-
throw new ForbiddenException({
82-
statusCode,
83-
message: 'apiKey.error.wrong',
84-
});
43+
if (
44+
statusCode ===
45+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR
46+
) {
47+
throw new ForbiddenException({
48+
statusCode,
49+
message: 'apiKey.error.notFound',
50+
});
51+
} else if (
52+
statusCode ===
53+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_IS_ACTIVE_ERROR
54+
) {
55+
throw new ForbiddenException({
56+
statusCode,
57+
message: 'apiKey.error.inactive',
58+
});
59+
} else if (
60+
statusCode ===
61+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_EXPIRED_ERROR
62+
) {
63+
throw new ForbiddenException({
64+
statusCode,
65+
message: 'apiKey.error.expired',
66+
});
67+
} else if (
68+
statusCode ===
69+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_WRONG_ERROR
70+
) {
71+
throw new ForbiddenException({
72+
statusCode,
73+
message: 'apiKey.error.wrong',
74+
});
75+
}
8576
}
8677

8778
throw new UnauthorizedException({
88-
statusCode,
79+
statusCode:
80+
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_INVALID_ERROR,
8981
message: 'apiKey.error.invalid',
9082
});
9183
}

src/common/doc/decorators/doc.decorator.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ export function Doc<T>(
136136
statusCode: ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NEEDED_ERROR,
137137
messagePath: 'apiKey.error.keyNeeded',
138138
},
139-
{
140-
statusCode:
141-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_PREFIX_INVALID_ERROR,
142-
messagePath: 'apiKey.error.prefixInvalid',
143-
},
144139
{
145140
statusCode:
146141
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR,
@@ -302,11 +297,6 @@ export function DocPaging<T>(
302297
statusCode: ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NEEDED_ERROR,
303298
messagePath: 'apiKey.error.keyNeeded',
304299
},
305-
{
306-
statusCode:
307-
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_PREFIX_INVALID_ERROR,
308-
messagePath: 'apiKey.error.prefixInvalid',
309-
},
310300
{
311301
statusCode:
312302
ENUM_API_KEY_STATUS_CODE_ERROR.API_KEY_NOT_FOUND_ERROR,

0 commit comments

Comments
 (0)