Skip to content

Commit 3069d4d

Browse files
Merge pull request #379 from andrechristikan/development
Development
2 parents 03045f0 + 663c462 commit 3069d4d

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

src/common/dashboard/interfaces/dashboard.service.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ export interface IDashboardService {
1919
month,
2020
year,
2121
}: IDashboardStartAndEnd): Promise<IDashboardStartAndEndDate>;
22+
23+
getPercentage(value: number, total: number): Promise<number>;
2224
}

src/common/dashboard/services/dashboard.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import {
66
} from 'src/common/dashboard/interfaces/dashboard.interface';
77
import { IDashboardService } from 'src/common/dashboard/interfaces/dashboard.service.interface';
88
import { HelperDateService } from 'src/common/helper/services/helper.date.service';
9+
import { HelperNumberService } from 'src/common/helper/services/helper.number.service';
910

1011
export class DashboardService implements IDashboardService {
11-
constructor(private readonly helperDateService: HelperDateService) {}
12+
constructor(
13+
private readonly helperDateService: HelperDateService,
14+
private readonly helperNumberService: HelperNumberService
15+
) {}
1216

1317
async getStartAndEndDate(
1418
date: DashboardDto
@@ -70,4 +74,8 @@ export class DashboardService implements IDashboardService {
7074
endDate,
7175
};
7276
}
77+
78+
async getPercentage(value: number, total: number): Promise<number> {
79+
return this.helperNumberService.percent(value, total);
80+
}
7381
}

src/modules/user/controllers/user.controller.ts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,27 @@ export class UserController {
114114
user.password
115115
);
116116
if (!validate) {
117-
if (passwordAttempt) {
117+
try {
118118
await this.userService.increasePasswordAttempt(user);
119+
} catch (err: any) {
120+
throw new InternalServerErrorException({
121+
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
122+
message: 'http.serverError.internalServerError',
123+
_error: err.message,
124+
});
119125
}
120126

121127
throw new BadRequestException({
122128
statusCode:
123129
ENUM_USER_STATUS_CODE_ERROR.USER_PASSWORD_NOT_MATCH_ERROR,
124130
message: 'user.error.passwordNotMatch',
125131
});
126-
} else if (!user.isActive) {
132+
} else if (user.blocked) {
133+
throw new ForbiddenException({
134+
statusCode: ENUM_USER_STATUS_CODE_ERROR.USER_BLOCKED_ERROR,
135+
message: 'user.error.blocked',
136+
});
137+
} else if (!user.isActive || user.inactivePermanent) {
127138
throw new ForbiddenException({
128139
statusCode: ENUM_USER_STATUS_CODE_ERROR.USER_INACTIVE_ERROR,
129140
message: 'user.error.inactive',
@@ -135,16 +146,14 @@ export class UserController {
135146
});
136147
}
137148

138-
if (passwordAttempt) {
139-
try {
140-
await this.userService.resetPasswordAttempt(user._id);
141-
} catch (err: any) {
142-
throw new InternalServerErrorException({
143-
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
144-
message: 'http.serverError.internalServerError',
145-
_error: err.message,
146-
});
147-
}
149+
try {
150+
await this.userService.resetPasswordAttempt(user._id);
151+
} catch (err: any) {
152+
throw new InternalServerErrorException({
153+
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
154+
message: 'http.serverError.internalServerError',
155+
_error: err.message,
156+
});
148157
}
149158

150159
const payload: UserPayloadSerialization =
@@ -235,7 +244,12 @@ export class UserController {
235244
statusCode: ENUM_USER_STATUS_CODE_ERROR.USER_NOT_FOUND_ERROR,
236245
message: 'user.error.notFound',
237246
});
238-
} else if (!user.isActive) {
247+
} else if (user.blocked) {
248+
throw new ForbiddenException({
249+
statusCode: ENUM_USER_STATUS_CODE_ERROR.USER_BLOCKED_ERROR,
250+
message: 'user.error.blocked',
251+
});
252+
} else if (!user.isActive || user.inactivePermanent) {
239253
throw new ForbiddenException({
240254
statusCode: ENUM_USER_STATUS_CODE_ERROR.USER_INACTIVE_ERROR,
241255
message: 'user.error.inactive',
@@ -326,8 +340,14 @@ export class UserController {
326340
user.password
327341
);
328342
if (!matchPassword) {
329-
if (passwordAttempt) {
343+
try {
330344
await this.userService.increasePasswordAttempt(user);
345+
} catch (err: any) {
346+
throw new InternalServerErrorException({
347+
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
348+
message: 'http.serverError.internalServerError',
349+
_error: err.message,
350+
});
331351
}
332352

333353
throw new BadRequestException({
@@ -349,16 +369,14 @@ export class UserController {
349369
});
350370
}
351371

352-
if (passwordAttempt) {
353-
try {
354-
await this.userService.increasePasswordAttempt(user);
355-
} catch (err: any) {
356-
throw new InternalServerErrorException({
357-
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
358-
message: 'http.serverError.internalServerError',
359-
_error: err.message,
360-
});
361-
}
372+
try {
373+
await this.userService.resetPasswordAttempt(user._id);
374+
} catch (err: any) {
375+
throw new InternalServerErrorException({
376+
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
377+
message: 'http.serverError.internalServerError',
378+
_error: err.message,
379+
});
362380
}
363381

364382
try {

0 commit comments

Comments
 (0)