Skip to content

Commit 68d79d6

Browse files
Merge pull request #394 from andrechristikan/development
api key inactive many issue, and repository.update fixed
2 parents 6abad0c + 674d823 commit 68d79d6

File tree

6 files changed

+344
-312
lines changed

6 files changed

+344
-312
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ack-nestjs-boilerplate",
3-
"version": "4.4.1",
3+
"version": "4.4.2",
44
"description": "Ack NestJs Boilerplate",
55
"repository": {
66
"type": "git",
@@ -52,7 +52,7 @@
5252
"rollback": "yarn rollback:setting && yarn rollback:apikey && yarn rollback:user && yarn rollback:role && yarn rollback:permission"
5353
},
5454
"dependencies": {
55-
"@aws-sdk/client-s3": "^3.279.0",
55+
"@aws-sdk/client-s3": "^3.282.0",
5656
"@faker-js/faker": "^7.6.0",
5757
"@joi/date": "^2.1.0",
5858
"@nestjs/axios": "^2.0.0",
@@ -78,15 +78,15 @@
7878
"moment": "^2.29.4",
7979
"mongoose": "^7.0.0",
8080
"morgan": "^1.10.0",
81-
"nest-winston": "^1.8.0",
81+
"nest-winston": "^1.9.0",
8282
"nestjs-command": "^3.1.3",
8383
"nestjs-i18n": "^10.2.6",
8484
"passport": "^0.6.0",
8585
"passport-headerapikey": "^1.2.2",
8686
"passport-jwt": "^4.0.1",
8787
"reflect-metadata": "^0.1.13",
8888
"response-time": "^2.3.2",
89-
"rimraf": "^4.1.2",
89+
"rimraf": "^4.2.0",
9090
"rotating-file-stream": "^3.1.0",
9191
"rxjs": "^7.8.0",
9292
"ua-parser-js": "^1.0.33",
@@ -111,7 +111,7 @@
111111
"@types/morgan": "^1.9.4",
112112
"@types/ms": "^0.7.31",
113113
"@types/multer": "^1.4.7",
114-
"@types/node": "^18.14.2",
114+
"@types/node": "^18.14.5",
115115
"@types/passport-jwt": "^3.0.8",
116116
"@types/supertest": "^2.0.12",
117117
"@types/ua-parser-js": "^0.7.36",

src/common/api-key/services/api-key.service.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,11 @@ export class ApiKeyService implements IApiKeyService {
9090
_id: string,
9191
options?: IDatabaseOptions
9292
): Promise<ApiKeyEntity> {
93-
const dto: ApiKeyActiveDto = new ApiKeyActiveDto();
94-
dto.isActive = true;
95-
9693
return this.apiKeyRepository.updateOneById<ApiKeyActiveDto>(
9794
_id,
98-
dto,
95+
{
96+
isActive: true,
97+
},
9998
options
10099
);
101100
}
@@ -104,12 +103,11 @@ export class ApiKeyService implements IApiKeyService {
104103
_id: string,
105104
options?: IDatabaseOptions
106105
): Promise<ApiKeyEntity> {
107-
const dto: ApiKeyActiveDto = new ApiKeyActiveDto();
108-
dto.isActive = false;
109-
110106
return this.apiKeyRepository.updateOneById<ApiKeyActiveDto>(
111107
_id,
112-
dto,
108+
{
109+
isActive: false,
110+
},
113111
options
114112
);
115113
}
@@ -206,13 +204,12 @@ export class ApiKeyService implements IApiKeyService {
206204
const secret: string = await this.createSecret();
207205
const hash: string = await this.createHashApiKey(key, secret);
208206

209-
const dto: ApiKeyResetDto = new ApiKeyResetDto();
210-
dto.hash = hash;
211-
212207
const apiKey: ApiKeyEntity =
213208
await this.apiKeyRepository.updateOneById<ApiKeyResetDto>(
214209
_id,
215-
dto,
210+
{
211+
hash: hash,
212+
},
216213
options
217214
);
218215

@@ -269,15 +266,15 @@ export class ApiKeyService implements IApiKeyService {
269266
async inactiveManyByEndDate(
270267
options?: IDatabaseManyOptions
271268
): Promise<boolean> {
272-
return this.apiKeyRepository.updateMany(
269+
return this.apiKeyRepository.updateMany<ApiKeyActiveDto>(
273270
{
274-
end_date: {
271+
endDate: {
275272
$lte: this.helperDateService.create(),
276273
},
277-
is_active: true,
274+
isActive: true,
278275
},
279276
{
280-
is_active: false,
277+
isActive: false,
281278
},
282279
options
283280
);

src/modules/permission/services/permission.service.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,11 @@ export class PermissionService implements IPermissionService {
121121
_id: string,
122122
options?: IDatabaseOptions
123123
): Promise<PermissionEntity> {
124-
const dto: PermissionActiveDto = new PermissionActiveDto();
125-
dto.isActive = true;
126-
127124
return this.permissionRepository.updateOneById<PermissionActiveDto>(
128125
_id,
129-
dto,
126+
{
127+
isActive: true,
128+
},
130129
options
131130
);
132131
}
@@ -135,12 +134,11 @@ export class PermissionService implements IPermissionService {
135134
_id: string,
136135
options?: IDatabaseOptions
137136
): Promise<PermissionEntity> {
138-
const dto: PermissionActiveDto = new PermissionActiveDto();
139-
dto.isActive = false;
140-
141137
return this.permissionRepository.updateOneById<PermissionActiveDto>(
142138
_id,
143-
dto,
139+
{
140+
isActive: false,
141+
},
144142
options
145143
);
146144
}

src/modules/role/services/role.service.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,11 @@ export class RoleService implements IRoleService {
115115
}
116116

117117
async active(_id: string, options?: IDatabaseOptions): Promise<RoleEntity> {
118-
const dto: RoleActiveDto = new RoleActiveDto();
119-
dto.isActive = true;
120-
121118
return this.roleRepository.updateOneById<RoleActiveDto>(
122119
_id,
123-
dto,
120+
{
121+
isActive: true,
122+
},
124123
options
125124
);
126125
}
@@ -129,12 +128,11 @@ export class RoleService implements IRoleService {
129128
_id: string,
130129
options?: IDatabaseOptions
131130
): Promise<RoleEntity> {
132-
const dto: RoleActiveDto = new RoleActiveDto();
133-
dto.isActive = false;
134-
135131
return this.roleRepository.updateOneById<RoleActiveDto>(
136132
_id,
137-
dto,
133+
{
134+
isActive: false,
135+
},
138136
options
139137
);
140138
}

src/modules/user/services/user.service.ts

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,11 @@ export class UserService implements IUserService {
141141
photo: AwsS3Serialization,
142142
options?: IDatabaseOptions
143143
): Promise<UserEntity> {
144-
const update: UserPhotoDto = new UserPhotoDto();
145-
update.photo = photo;
146-
147144
return this.userRepository.updateOneById<UserPhotoDto>(
148145
_id,
149-
update,
146+
{
147+
photo: photo,
148+
},
150149
options
151150
);
152151
}
@@ -193,27 +192,25 @@ export class UserService implements IUserService {
193192
{ passwordHash, passwordExpired, salt, passwordCreated }: IAuthPassword,
194193
options?: IDatabaseOptions
195194
): Promise<UserEntity> {
196-
const update: UserPasswordDto = new UserPasswordDto();
197-
update.password = passwordHash;
198-
update.passwordExpired = passwordExpired;
199-
update.passwordCreated = passwordCreated;
200-
update.salt = salt;
201-
202195
return this.userRepository.updateOneById<UserPasswordDto>(
203196
_id,
204-
update,
197+
{
198+
password: passwordHash,
199+
passwordExpired,
200+
passwordCreated,
201+
salt,
202+
},
205203
options
206204
);
207205
}
208206

209207
async active(_id: string, options?: IDatabaseOptions): Promise<UserEntity> {
210-
const dto: UserActiveDto = new UserActiveDto();
211-
dto.isActive = true;
212-
dto.inactiveDate = undefined;
213-
214208
return this.userRepository.updateOneById<UserActiveDto>(
215209
_id,
216-
dto,
210+
{
211+
isActive: true,
212+
inactiveDate: undefined,
213+
},
217214
options
218215
);
219216
}
@@ -222,13 +219,12 @@ export class UserService implements IUserService {
222219
_id: string,
223220
options?: IDatabaseOptions
224221
): Promise<UserEntity> {
225-
const dto: UserActiveDto = new UserActiveDto();
226-
dto.isActive = false;
227-
dto.inactiveDate = this.helperDateService.create();
228-
229222
return this.userRepository.updateOneById<UserActiveDto>(
230223
_id,
231-
dto,
224+
{
225+
isActive: false,
226+
inactiveDate: this.helperDateService.create(),
227+
},
232228
options
233229
);
234230
}
@@ -237,13 +233,12 @@ export class UserService implements IUserService {
237233
_id: string,
238234
options?: IDatabaseOptions
239235
): Promise<UserEntity> {
240-
const dto: UserBlockedDto = new UserBlockedDto();
241-
dto.blocked = true;
242-
dto.blockedDate = this.helperDateService.create();
243-
244236
return this.userRepository.updateOneById<UserBlockedDto>(
245237
_id,
246-
dto,
238+
{
239+
blocked: true,
240+
blockedDate: this.helperDateService.create(),
241+
},
247242
options
248243
);
249244
}
@@ -252,13 +247,12 @@ export class UserService implements IUserService {
252247
_id: string,
253248
options?: IDatabaseOptions
254249
): Promise<UserEntity> {
255-
const dto: UserBlockedDto = new UserBlockedDto();
256-
dto.blocked = false;
257-
dto.blockedDate = undefined;
258-
259250
return this.userRepository.updateOneById<UserBlockedDto>(
260251
_id,
261-
dto,
252+
{
253+
blocked: false,
254+
blockedDate: undefined,
255+
},
262256
options
263257
);
264258
}
@@ -267,12 +261,11 @@ export class UserService implements IUserService {
267261
_id: string,
268262
options?: IDatabaseOptions
269263
): Promise<UserEntity> {
270-
const update: UserPasswordAttemptDto = new UserPasswordAttemptDto();
271-
update.passwordAttempt = 3;
272-
273264
return this.userRepository.updateOneById<UserPasswordAttemptDto>(
274265
_id,
275-
update,
266+
{
267+
passwordAttempt: 3,
268+
},
276269
options
277270
);
278271
}
@@ -281,12 +274,11 @@ export class UserService implements IUserService {
281274
user: UserEntity | IUserEntity,
282275
options?: IDatabaseOptions
283276
): Promise<UserEntity> {
284-
const update: UserPasswordAttemptDto = new UserPasswordAttemptDto();
285-
update.passwordAttempt = ++user.passwordAttempt;
286-
287277
return this.userRepository.updateOneById<UserPasswordAttemptDto>(
288278
user._id,
289-
update,
279+
{
280+
passwordAttempt: ++user.passwordAttempt,
281+
},
290282
options
291283
);
292284
}
@@ -295,12 +287,11 @@ export class UserService implements IUserService {
295287
_id: string,
296288
options?: IDatabaseOptions
297289
): Promise<UserEntity> {
298-
const update: UserPasswordAttemptDto = new UserPasswordAttemptDto();
299-
update.passwordAttempt = 0;
300-
301290
return this.userRepository.updateOneById<UserPasswordAttemptDto>(
302291
_id,
303-
update,
292+
{
293+
passwordAttempt: 0,
294+
},
304295
options
305296
);
306297
}
@@ -342,12 +333,11 @@ export class UserService implements IUserService {
342333
passwordExpired: Date,
343334
options?: IDatabaseOptions
344335
): Promise<UserEntity> {
345-
const update: UserPasswordExpiredDto = new UserPasswordExpiredDto();
346-
update.passwordExpired = passwordExpired;
347-
348336
return this.userRepository.updateOneById<UserPasswordExpiredDto>(
349337
_id,
350-
update,
338+
{
339+
passwordExpired,
340+
},
351341
options
352342
);
353343
}

0 commit comments

Comments
 (0)