Skip to content

Commit 86dc8cd

Browse files
update template
2 parents 61f1519 + 03045f0 commit 86dc8cd

File tree

14 files changed

+436
-291
lines changed

14 files changed

+436
-291
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@
4848
"rollback": "yarn rollback:setting && yarn rollback:apikey"
4949
},
5050
"dependencies": {
51-
"@aws-sdk/client-s3": "^3.262.0",
51+
"@aws-sdk/client-s3": "^3.264.0",
5252
"@faker-js/faker": "^7.6.0",
5353
"@joi/date": "^2.1.0",
54-
"@nestjs/axios": "^1.0.1",
54+
"@nestjs/axios": "^2.0.0",
5555
"@nestjs/common": "^9.2.1",
56-
"@nestjs/config": "^2.2.0",
56+
"@nestjs/config": "^2.3.0",
5757
"@nestjs/core": "^9.2.1",
5858
"@nestjs/jwt": "^10.0.1",
5959
"@nestjs/mongoose": "^9.2.1",
6060
"@nestjs/microservices": "^9.2.1",
61-
"@nestjs/passport": "^9.0.0",
61+
"@nestjs/passport": "^9.0.1",
6262
"@nestjs/platform-express": "^9.2.1",
63-
"@nestjs/schedule": "^2.1.0",
63+
"@nestjs/schedule": "^2.2.0",
6464
"@nestjs/swagger": "^6.1.4",
65-
"@nestjs/terminus": "^9.1.4",
65+
"@nestjs/terminus": "^9.2.0",
6666
"@types/response-time": "^2.3.5",
6767
"bcryptjs": "^2.4.3",
6868
"class-transformer": "^0.5.1",
@@ -95,7 +95,7 @@
9595
"yarn": "^1.22.19"
9696
},
9797
"devDependencies": {
98-
"@nestjs/cli": "^9.1.9",
98+
"@nestjs/cli": "^9.2.0",
9999
"@nestjs/schematics": "^9.0.4",
100100
"@nestjs/testing": "^9.2.1",
101101
"@types/bcryptjs": "^2.4.2",
@@ -117,7 +117,7 @@
117117
"@types/uuid": "^9.0.0",
118118
"@typescript-eslint/eslint-plugin": "^5.50.0",
119119
"@typescript-eslint/parser": "^5.50.0",
120-
"cspell": "^6.19.2",
120+
"cspell": "^6.21.0",
121121
"eslint": "^8.33.0",
122122
"eslint-config-prettier": "^8.6.0",
123123
"eslint-plugin-import": "^2.27.5",

src/common/auth/interfaces/auth.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface IAuthPassword {
33
salt: string;
44
passwordHash: string;
55
passwordExpired: Date;
6+
passwordCreated: Date;
67
}
78

89
export interface IAuthPayloadOptions {

src/common/auth/services/auth.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,12 @@ export class AuthService implements IAuthService {
315315
const passwordExpired: Date = this.helperDateService.forwardInSeconds(
316316
this.passwordExpiredIn
317317
);
318+
const passwordCreated: Date = this.helperDateService.create();
318319
const passwordHash = this.helperHashService.bcrypt(password, salt);
319320
return {
320321
passwordHash,
321322
passwordExpired,
323+
passwordCreated,
322324
salt,
323325
};
324326
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Module } from '@nestjs/common';
2+
import { DashboardService } from 'src/common/dashboard/services/dashboard.service';
3+
4+
@Module({
5+
controllers: [],
6+
providers: [DashboardService],
7+
exports: [DashboardService],
8+
imports: [],
9+
})
10+
export class DashboardModule {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Type } from 'class-transformer';
2+
import { IsDate, IsOptional, ValidateIf } from 'class-validator';
3+
import { MinGreaterThan } from 'src/common/request/validations/request.min-greater-than.validation';
4+
5+
export class DashboardDto {
6+
@IsDate()
7+
@IsOptional()
8+
@Type(() => Date)
9+
@ValidateIf((e) => e.startDate !== '' || e.endDate !== '')
10+
startDate?: Date;
11+
12+
@IsDate()
13+
@IsOptional()
14+
@MinGreaterThan('startDate')
15+
@Type(() => Date)
16+
@ValidateIf((e) => e.startDate !== '' || e.endDate !== '')
17+
endDate?: Date;
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export interface IDashboardStartAndEndDate {
2+
startDate: Date;
3+
endDate: Date;
4+
}
5+
6+
export interface IDashboardStartAndEndYear {
7+
startYear: number;
8+
endYear: number;
9+
}
10+
11+
export interface IDashboardStartAndEnd {
12+
month: number;
13+
year: number;
14+
}
15+
16+
export interface IDashboardMonthAndYear extends Partial<IDashboardStartAndEnd> {
17+
total: number;
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { DashboardDto } from 'src/common/dashboard/dtos/dashboard';
2+
import {
3+
IDashboardStartAndEnd,
4+
IDashboardStartAndEndDate,
5+
IDashboardStartAndEndYear,
6+
} from 'src/common/dashboard/interfaces/dashboard.interface';
7+
8+
export interface IDashboardService {
9+
getStartAndEndDate(date: DashboardDto): Promise<IDashboardStartAndEndDate>;
10+
11+
getMonths(): Promise<number[]>;
12+
13+
getStartAndEndYear({
14+
startDate,
15+
endDate,
16+
}: IDashboardStartAndEndDate): Promise<IDashboardStartAndEndYear>;
17+
18+
getStartAndEndMonth({
19+
month,
20+
year,
21+
}: IDashboardStartAndEnd): Promise<IDashboardStartAndEndDate>;
22+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { DashboardDto } from 'src/common/dashboard/dtos/dashboard';
2+
import {
3+
IDashboardStartAndEnd,
4+
IDashboardStartAndEndDate,
5+
IDashboardStartAndEndYear,
6+
} from 'src/common/dashboard/interfaces/dashboard.interface';
7+
import { IDashboardService } from 'src/common/dashboard/interfaces/dashboard.service.interface';
8+
import { HelperDateService } from 'src/common/helper/services/helper.date.service';
9+
10+
export class DashboardService implements IDashboardService {
11+
constructor(private readonly helperDateService: HelperDateService) {}
12+
13+
async getStartAndEndDate(
14+
date: DashboardDto
15+
): Promise<IDashboardStartAndEndDate> {
16+
const today = this.helperDateService.create();
17+
let { startDate, endDate } = date;
18+
19+
if (!startDate && !endDate) {
20+
startDate = this.helperDateService.startOfYear(today);
21+
endDate = this.helperDateService.endOfYear(today);
22+
} else {
23+
if (!startDate) {
24+
startDate = this.helperDateService.startOfDay();
25+
} else {
26+
startDate = this.helperDateService.startOfDay(startDate);
27+
}
28+
29+
if (!endDate) {
30+
endDate = this.helperDateService.endOfDay();
31+
} else {
32+
endDate = this.helperDateService.endOfDay(endDate);
33+
}
34+
}
35+
36+
return {
37+
startDate,
38+
endDate,
39+
};
40+
}
41+
42+
async getMonths(): Promise<number[]> {
43+
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
44+
}
45+
46+
async getStartAndEndYear({
47+
startDate,
48+
endDate,
49+
}: IDashboardStartAndEndDate): Promise<IDashboardStartAndEndYear> {
50+
return {
51+
startYear: startDate.getFullYear(),
52+
endYear: endDate.getFullYear(),
53+
};
54+
}
55+
56+
async getStartAndEndMonth({
57+
month,
58+
year,
59+
}: IDashboardStartAndEnd): Promise<IDashboardStartAndEndDate> {
60+
const monthString = `${month}`.padStart(2, '0');
61+
const date: Date = this.helperDateService.create(
62+
`${year}-${monthString}-01`
63+
);
64+
65+
const startDate = this.helperDateService.startOfMonth(date);
66+
const endDate = this.helperDateService.endOfMonth(date);
67+
68+
return {
69+
startDate,
70+
endDate,
71+
};
72+
}
73+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export const FILE_CUSTOM_SIZE_META_KEY = 'FileCustomSizeMetaKey';
1+
export const FILE_CUSTOM_MAX_SIZE_META_KEY = 'FileCustomMaxSizeMetaKey';
22
export const FILE_CUSTOM_MAX_FILES_META_KEY = 'FileCustomMaxFilesMetaKey';

src/common/file/decorators/file.decorator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
99
import {
1010
FILE_CUSTOM_MAX_FILES_META_KEY,
11-
FILE_CUSTOM_SIZE_META_KEY,
11+
FILE_CUSTOM_MAX_SIZE_META_KEY,
1212
} from 'src/common/file/constants/file.constant';
1313
import { FileCustomMaxFilesInterceptor } from 'src/common/file/interceptors/file.custom-max-files.interceptor';
14-
import { FileCustomSizeInterceptor } from 'src/common/file/interceptors/file.custom-size.interceptor';
14+
import { FileCustomMaxSizeInterceptor } from 'src/common/file/interceptors/file.custom-max-size.interceptor';
1515
import { IRequestApp } from 'src/common/request/interfaces/request.interface';
1616

1717
export function UploadFileSingle(field: string): MethodDecorator {
@@ -29,10 +29,10 @@ export function FileCustomMaxFile(customMaxFiles: number): MethodDecorator {
2929
);
3030
}
3131

32-
export function FileCustomSize(customSize: string): MethodDecorator {
32+
export function FileCustomMaxSize(customMaxSize: string): MethodDecorator {
3333
return applyDecorators(
34-
UseInterceptors(FileCustomSizeInterceptor),
35-
SetMetadata(FILE_CUSTOM_SIZE_META_KEY, customSize)
34+
UseInterceptors(FileCustomMaxSizeInterceptor),
35+
SetMetadata(FILE_CUSTOM_MAX_SIZE_META_KEY, customMaxSize)
3636
);
3737
}
3838

0 commit comments

Comments
 (0)