Skip to content

Commit 9918892

Browse files
update template
2 parents 66612d5 + 83a8bb7 commit 9918892

15 files changed

+1374
-1324
lines changed

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ack-nestjs-boilerplate-kafka",
3-
"version": "3.3.4",
3+
"version": "3.3.5",
44
"description": "Ack NestJs Boilerplate Kafka",
55
"repository": {
66
"type": "git",
@@ -48,7 +48,7 @@
4848
"rollback": "yarn rollback:setting && yarn rollback:apikey"
4949
},
5050
"dependencies": {
51-
"@aws-sdk/client-s3": "^3.245.0",
51+
"@aws-sdk/client-s3": "^3.259.0",
5252
"@faker-js/faker": "^7.6.0",
5353
"@joi/date": "^2.1.0",
5454
"@nestjs/axios": "^1.0.1",
@@ -74,7 +74,7 @@
7474
"joi": "^17.7.0",
7575
"kafkajs": "^2.2.3",
7676
"moment": "^2.29.4",
77-
"mongoose": "^6.8.3",
77+
"mongoose": "^6.9.0",
7878
"morgan": "^1.10.0",
7979
"nest-winston": "^1.8.0",
8080
"nestjs-command": "^3.1.3",
@@ -84,28 +84,28 @@
8484
"passport-jwt": "^4.0.1",
8585
"reflect-metadata": "^0.1.13",
8686
"response-time": "^2.3.2",
87-
"rimraf": "^4.0.4",
87+
"rimraf": "^4.1.2",
8888
"rotating-file-stream": "^3.0.4",
8989
"rxjs": "^7.8.0",
90-
"ua-parser-js": "^1.0.32",
90+
"ua-parser-js": "^1.0.33",
9191
"winston": "^3.8.2",
9292
"winston-daily-rotate-file": "^4.7.1",
9393
"xlsx": "^0.18.5",
9494
"yargs": "^17.6.2",
9595
"yarn": "^1.22.19"
9696
},
9797
"devDependencies": {
98-
"@nestjs/cli": "^9.1.8",
98+
"@nestjs/cli": "^9.1.9",
9999
"@nestjs/schematics": "^9.0.4",
100100
"@nestjs/testing": "^9.2.1",
101101
"@types/bcryptjs": "^2.4.2",
102102
"@types/bytes": "^3.1.1",
103103
"@types/cors": "^2.8.13",
104104
"@types/cron": "^2.0.0",
105105
"@types/crypto-js": "^4.1.1",
106-
"@types/express": "^4.17.15",
106+
"@types/express": "^4.17.16",
107107
"@types/express-rate-limit": "^6.0.0",
108-
"@types/jest": "^29.2.5",
108+
"@types/jest": "^29.4.0",
109109
"@types/lodash": "^4.14.191",
110110
"@types/morgan": "^1.9.4",
111111
"@types/ms": "^0.7.31",
@@ -115,14 +115,14 @@
115115
"@types/supertest": "^2.0.12",
116116
"@types/ua-parser-js": "^0.7.36",
117117
"@types/uuid": "^9.0.0",
118-
"@typescript-eslint/eslint-plugin": "^5.48.1",
119-
"@typescript-eslint/parser": "^5.48.1",
120-
"cspell": "^6.18.1",
121-
"eslint": "^8.31.0",
118+
"@typescript-eslint/eslint-plugin": "^5.49.0",
119+
"@typescript-eslint/parser": "^5.49.0",
120+
"cspell": "^6.19.2",
121+
"eslint": "^8.32.0",
122122
"eslint-config-prettier": "^8.6.0",
123-
"eslint-plugin-import": "^2.27.4",
123+
"eslint-plugin-import": "^2.27.5",
124124
"husky": "^8.0.3",
125-
"jest": "^29.3.1",
125+
"jest": "^29.4.1",
126126
"prettier": "^2.8.3",
127127
"supertest": "^6.3.3",
128128
"ts-jest": "^29.0.5",

src/common/database/abstracts/database.base-repository.abstract.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
IDatabaseRestoreManyOptions,
1313
IDatabaseUpdateOptions,
1414
IDatabaseDeleteOptions,
15+
IDatabaseRawOptions,
1516
} from 'src/common/database/interfaces/database.interface';
1617

1718
export abstract class DatabaseBaseRepositoryAbstract<T> {
@@ -46,7 +47,10 @@ export abstract class DatabaseBaseRepositoryAbstract<T> {
4647
options?: IDatabaseExistOptions<any>
4748
): Promise<boolean>;
4849

49-
abstract raw<N, R = any>(rawOperation: R): Promise<N[]>;
50+
abstract raw<N, R = any>(
51+
rawOperation: R,
52+
options?: IDatabaseRawOptions
53+
): Promise<N[]>;
5054

5155
abstract create<N>(
5256
data: N,

src/common/database/abstracts/mongo/repositories/database.mongo.object-id.repository.abstract.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
IDatabaseRestoreManyOptions,
2323
IDatabaseUpdateOptions,
2424
IDatabaseDeleteOptions,
25+
IDatabaseRawOptions,
2526
} from 'src/common/database/interfaces/database.interface';
2627
import { IDatabaseRepository } from 'src/common/database/interfaces/database.repository.interface';
2728
import { ENUM_PAGINATION_SORT_TYPE } from 'src/common/pagination/constants/pagination.enum.constant';
@@ -314,12 +315,46 @@ export abstract class DatabaseMongoObjectIdRepositoryAbstract<T>
314315
return result ? true : false;
315316
}
316317

317-
async raw<N, R = PipelineStage[]>(rawOperation: R): Promise<N[]> {
318+
async raw<N, R = PipelineStage[]>(
319+
rawOperation: R,
320+
options?: IDatabaseRawOptions
321+
): Promise<N[]> {
318322
if (!Array.isArray(rawOperation)) {
319323
throw new Error('Must in array');
320324
}
321325

322-
return this._repository.aggregate<N>(rawOperation);
326+
const pipeline: PipelineStage[] = rawOperation;
327+
328+
if (options?.withDeleted) {
329+
pipeline.push({
330+
$match: {
331+
$or: [
332+
{
333+
[DATABASE_DELETED_AT_FIELD_NAME]: {
334+
$exists: false,
335+
},
336+
},
337+
{
338+
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: true },
339+
},
340+
],
341+
},
342+
});
343+
} else {
344+
pipeline.push({
345+
$match: {
346+
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: false },
347+
},
348+
});
349+
}
350+
351+
const aggregate = this._repository.aggregate<N>(pipeline);
352+
353+
if (options?.session) {
354+
aggregate.session(options?.session);
355+
}
356+
357+
return aggregate;
323358
}
324359

325360
async create<N>(

src/common/database/abstracts/mongo/repositories/database.mongo.uuid.repository.abstract.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
IDatabaseRestoreManyOptions,
2222
IDatabaseUpdateOptions,
2323
IDatabaseDeleteOptions,
24+
IDatabaseRawOptions,
2425
} from 'src/common/database/interfaces/database.interface';
2526
import { IDatabaseRepository } from 'src/common/database/interfaces/database.repository.interface';
2627
import { ENUM_PAGINATION_SORT_TYPE } from 'src/common/pagination/constants/pagination.enum.constant';
@@ -310,12 +311,46 @@ export abstract class DatabaseMongoUUIDRepositoryAbstract<T>
310311
return result ? true : false;
311312
}
312313

313-
async raw<N, R = PipelineStage[]>(rawOperation: R): Promise<N[]> {
314+
async raw<N, R = PipelineStage[]>(
315+
rawOperation: R,
316+
options?: IDatabaseRawOptions
317+
): Promise<N[]> {
314318
if (!Array.isArray(rawOperation)) {
315319
throw new Error('Must in array');
316320
}
317321

318-
return this._repository.aggregate<N>(rawOperation);
322+
const pipeline: PipelineStage[] = rawOperation;
323+
324+
if (options?.withDeleted) {
325+
pipeline.push({
326+
$match: {
327+
$or: [
328+
{
329+
[DATABASE_DELETED_AT_FIELD_NAME]: {
330+
$exists: false,
331+
},
332+
},
333+
{
334+
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: true },
335+
},
336+
],
337+
},
338+
});
339+
} else {
340+
pipeline.push({
341+
$match: {
342+
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: false },
343+
},
344+
});
345+
}
346+
347+
const aggregate = this._repository.aggregate<N>(pipeline);
348+
349+
if (options?.session) {
350+
aggregate.session(options?.session);
351+
}
352+
353+
return aggregate;
319354
}
320355

321356
async create<N>(

src/common/database/interfaces/database.interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ export type IDatabaseCreateManyOptions<T = any> = Pick<
6565
export type IDatabaseSoftDeleteManyOptions<T = any> = IDatabaseManyOptions<T>;
6666

6767
export type IDatabaseRestoreManyOptions<T = any> = IDatabaseManyOptions<T>;
68+
69+
export type IDatabaseRawOptions<T = any> = Pick<
70+
IDatabaseOptions<T>,
71+
'session' | 'withDeleted'
72+
>;

src/common/pagination/pipes/pagination.filter-contain.pipe.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export function PaginationFilterContainPipe(
1414
async transform(
1515
value: string,
1616
{ data: field }: ArgumentMetadata
17-
): Promise<Record<string, any>> {
17+
): Promise<Record<string, { $regex: RegExp; $options: string }>> {
1818
if (!value) {
19-
return undefined;
19+
value = '';
2020
}
2121

2222
if (
@@ -33,10 +33,7 @@ export function PaginationFilterContainPipe(
3333
value = value.trim();
3434
}
3535

36-
const filter: Record<string, any> =
37-
this.paginationService.filterContain(field, value);
38-
39-
return filter;
36+
return this.paginationService.filterContain(field, value);
4037
}
4138
}
4239

src/common/pagination/pipes/pagination.filter-date.pipe.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ export function PaginationFilterDatePipe(
1818
async transform(
1919
value: string,
2020
{ data: field }: ArgumentMetadata
21-
): Promise<Record<string, any>> {
22-
if (!value) {
23-
return undefined;
24-
}
25-
21+
): Promise<Record<string, Date>> {
2622
let date: Date = this.helperDateService.create(value);
2723

2824
if (
@@ -37,10 +33,7 @@ export function PaginationFilterDatePipe(
3733
date = this.helperDateService.startOfDay(date);
3834
}
3935

40-
const filter: Record<string, any> =
41-
this.paginationService.filterDate(field, date);
42-
43-
return filter;
36+
return this.paginationService.filterDate(field, date);
4437
}
4538
}
4639

src/common/pagination/pipes/pagination.filter-equal.pipe.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function PaginationFilterEqualPipe(
1818
async transform(
1919
value: string,
2020
{ data: field }: ArgumentMetadata
21-
): Promise<Record<string, any>> {
21+
): Promise<Record<string, string | number>> {
2222
if (!value) {
2323
return undefined;
2424
}
@@ -44,13 +44,10 @@ export function PaginationFilterEqualPipe(
4444
: value;
4545
}
4646

47-
const filter: Record<string, any> =
48-
this.paginationService.filterEqual<string | number>(
49-
field,
50-
finalValue
51-
);
52-
53-
return filter;
47+
return this.paginationService.filterEqual<string | number>(
48+
field,
49+
finalValue
50+
);
5451
}
5552
}
5653

src/common/pagination/pipes/pagination.filter-in-boolean.pipe.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,16 @@ export function PaginationFilterInBooleanPipe(
1616
async transform(
1717
value: string,
1818
{ data: field }: ArgumentMetadata
19-
): Promise<Record<string, any>> {
20-
if (!value) {
21-
return undefined;
22-
}
19+
): Promise<Record<string, { $in: boolean[] }>> {
20+
let finalValue: boolean[] = defaultValue as boolean[];
2321

24-
const filter: Record<string, any> = this.paginationService.filterIn<
25-
boolean[]
26-
>(
27-
field,
28-
value
29-
? this.helperArrayService.unique(
30-
value.split(',').map((val: string) => val === 'true')
31-
)
32-
: defaultValue
33-
);
22+
if (value) {
23+
finalValue = this.helperArrayService.unique(
24+
value.split(',').map((val: string) => val === 'true')
25+
);
26+
}
3427

35-
return filter;
28+
return this.paginationService.filterIn<boolean>(field, finalValue);
3629
}
3730
}
3831

src/common/pagination/pipes/pagination.filter-in-enum.pipe.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,17 @@ export function PaginationFilterInEnumPipe<T>(
1313
async transform(
1414
value: string,
1515
{ data: field }: ArgumentMetadata
16-
): Promise<Record<string, any>> {
17-
if (!value) {
18-
return undefined;
19-
}
16+
): Promise<Record<string, { $in: T[] }>> {
17+
let finalValue: T[] = defaultValue as T[];
2018

21-
const filter: Record<string, any> =
22-
this.paginationService.filterIn<T>(
23-
field,
24-
value
25-
? (value
26-
.split(',')
27-
.map((val: string) => defaultEnum[val])
28-
.filter((val: string) => val) as T)
29-
: defaultValue
30-
);
19+
if (value) {
20+
finalValue = value
21+
.split(',')
22+
.map((val: string) => defaultEnum[val])
23+
.filter((val: string) => val) as T[];
24+
}
3125

32-
return filter;
26+
return this.paginationService.filterIn<T>(field, finalValue);
3327
}
3428
}
3529

0 commit comments

Comments
 (0)