Skip to content

Commit 663c462

Browse files
up dashboard service
1 parent 0aba16e commit 663c462

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
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: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,14 @@ 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({
@@ -140,16 +146,14 @@ export class UserController {
140146
});
141147
}
142148

143-
if (passwordAttempt) {
144-
try {
145-
await this.userService.resetPasswordAttempt(user._id);
146-
} catch (err: any) {
147-
throw new InternalServerErrorException({
148-
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
149-
message: 'http.serverError.internalServerError',
150-
_error: err.message,
151-
});
152-
}
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+
});
153157
}
154158

155159
const payload: UserPayloadSerialization =
@@ -336,8 +340,14 @@ export class UserController {
336340
user.password
337341
);
338342
if (!matchPassword) {
339-
if (passwordAttempt) {
343+
try {
340344
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+
});
341351
}
342352

343353
throw new BadRequestException({
@@ -359,16 +369,14 @@ export class UserController {
359369
});
360370
}
361371

362-
if (passwordAttempt) {
363-
try {
364-
await this.userService.resetPasswordAttempt(user._id);
365-
} catch (err: any) {
366-
throw new InternalServerErrorException({
367-
statusCode: ENUM_ERROR_STATUS_CODE_ERROR.ERROR_UNKNOWN,
368-
message: 'http.serverError.internalServerError',
369-
_error: err.message,
370-
});
371-
}
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+
});
372380
}
373381

374382
try {

0 commit comments

Comments
 (0)