Skip to content

Commit

Permalink
update template
Browse files Browse the repository at this point in the history
  • Loading branch information
andrechristikan committed Jan 27, 2023
2 parents 66612d5 + 83a8bb7 commit 9918892
Show file tree
Hide file tree
Showing 15 changed files with 1,374 additions and 1,324 deletions.
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ack-nestjs-boilerplate-kafka",
"version": "3.3.4",
"version": "3.3.5",
"description": "Ack NestJs Boilerplate Kafka",
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,7 +48,7 @@
"rollback": "yarn rollback:setting && yarn rollback:apikey"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.245.0",
"@aws-sdk/client-s3": "^3.259.0",
"@faker-js/faker": "^7.6.0",
"@joi/date": "^2.1.0",
"@nestjs/axios": "^1.0.1",
Expand All @@ -74,7 +74,7 @@
"joi": "^17.7.0",
"kafkajs": "^2.2.3",
"moment": "^2.29.4",
"mongoose": "^6.8.3",
"mongoose": "^6.9.0",
"morgan": "^1.10.0",
"nest-winston": "^1.8.0",
"nestjs-command": "^3.1.3",
Expand All @@ -84,28 +84,28 @@
"passport-jwt": "^4.0.1",
"reflect-metadata": "^0.1.13",
"response-time": "^2.3.2",
"rimraf": "^4.0.4",
"rimraf": "^4.1.2",
"rotating-file-stream": "^3.0.4",
"rxjs": "^7.8.0",
"ua-parser-js": "^1.0.32",
"ua-parser-js": "^1.0.33",
"winston": "^3.8.2",
"winston-daily-rotate-file": "^4.7.1",
"xlsx": "^0.18.5",
"yargs": "^17.6.2",
"yarn": "^1.22.19"
},
"devDependencies": {
"@nestjs/cli": "^9.1.8",
"@nestjs/cli": "^9.1.9",
"@nestjs/schematics": "^9.0.4",
"@nestjs/testing": "^9.2.1",
"@types/bcryptjs": "^2.4.2",
"@types/bytes": "^3.1.1",
"@types/cors": "^2.8.13",
"@types/cron": "^2.0.0",
"@types/crypto-js": "^4.1.1",
"@types/express": "^4.17.15",
"@types/express": "^4.17.16",
"@types/express-rate-limit": "^6.0.0",
"@types/jest": "^29.2.5",
"@types/jest": "^29.4.0",
"@types/lodash": "^4.14.191",
"@types/morgan": "^1.9.4",
"@types/ms": "^0.7.31",
Expand All @@ -115,14 +115,14 @@
"@types/supertest": "^2.0.12",
"@types/ua-parser-js": "^0.7.36",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
"cspell": "^6.18.1",
"eslint": "^8.31.0",
"@typescript-eslint/eslint-plugin": "^5.49.0",
"@typescript-eslint/parser": "^5.49.0",
"cspell": "^6.19.2",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.4",
"eslint-plugin-import": "^2.27.5",
"husky": "^8.0.3",
"jest": "^29.3.1",
"jest": "^29.4.1",
"prettier": "^2.8.3",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IDatabaseRestoreManyOptions,
IDatabaseUpdateOptions,
IDatabaseDeleteOptions,
IDatabaseRawOptions,
} from 'src/common/database/interfaces/database.interface';

export abstract class DatabaseBaseRepositoryAbstract<T> {
Expand Down Expand Up @@ -46,7 +47,10 @@ export abstract class DatabaseBaseRepositoryAbstract<T> {
options?: IDatabaseExistOptions<any>
): Promise<boolean>;

abstract raw<N, R = any>(rawOperation: R): Promise<N[]>;
abstract raw<N, R = any>(
rawOperation: R,
options?: IDatabaseRawOptions
): Promise<N[]>;

abstract create<N>(
data: N,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IDatabaseRestoreManyOptions,
IDatabaseUpdateOptions,
IDatabaseDeleteOptions,
IDatabaseRawOptions,
} from 'src/common/database/interfaces/database.interface';
import { IDatabaseRepository } from 'src/common/database/interfaces/database.repository.interface';
import { ENUM_PAGINATION_SORT_TYPE } from 'src/common/pagination/constants/pagination.enum.constant';
Expand Down Expand Up @@ -314,12 +315,46 @@ export abstract class DatabaseMongoObjectIdRepositoryAbstract<T>
return result ? true : false;
}

async raw<N, R = PipelineStage[]>(rawOperation: R): Promise<N[]> {
async raw<N, R = PipelineStage[]>(
rawOperation: R,
options?: IDatabaseRawOptions
): Promise<N[]> {
if (!Array.isArray(rawOperation)) {
throw new Error('Must in array');
}

return this._repository.aggregate<N>(rawOperation);
const pipeline: PipelineStage[] = rawOperation;

if (options?.withDeleted) {
pipeline.push({
$match: {
$or: [
{
[DATABASE_DELETED_AT_FIELD_NAME]: {
$exists: false,
},
},
{
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: true },
},
],
},
});
} else {
pipeline.push({
$match: {
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: false },
},
});
}

const aggregate = this._repository.aggregate<N>(pipeline);

if (options?.session) {
aggregate.session(options?.session);
}

return aggregate;
}

async create<N>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
IDatabaseRestoreManyOptions,
IDatabaseUpdateOptions,
IDatabaseDeleteOptions,
IDatabaseRawOptions,
} from 'src/common/database/interfaces/database.interface';
import { IDatabaseRepository } from 'src/common/database/interfaces/database.repository.interface';
import { ENUM_PAGINATION_SORT_TYPE } from 'src/common/pagination/constants/pagination.enum.constant';
Expand Down Expand Up @@ -310,12 +311,46 @@ export abstract class DatabaseMongoUUIDRepositoryAbstract<T>
return result ? true : false;
}

async raw<N, R = PipelineStage[]>(rawOperation: R): Promise<N[]> {
async raw<N, R = PipelineStage[]>(
rawOperation: R,
options?: IDatabaseRawOptions
): Promise<N[]> {
if (!Array.isArray(rawOperation)) {
throw new Error('Must in array');
}

return this._repository.aggregate<N>(rawOperation);
const pipeline: PipelineStage[] = rawOperation;

if (options?.withDeleted) {
pipeline.push({
$match: {
$or: [
{
[DATABASE_DELETED_AT_FIELD_NAME]: {
$exists: false,
},
},
{
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: true },
},
],
},
});
} else {
pipeline.push({
$match: {
[DATABASE_DELETED_AT_FIELD_NAME]: { $exists: false },
},
});
}

const aggregate = this._repository.aggregate<N>(pipeline);

if (options?.session) {
aggregate.session(options?.session);
}

return aggregate;
}

async create<N>(
Expand Down
5 changes: 5 additions & 0 deletions src/common/database/interfaces/database.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ export type IDatabaseCreateManyOptions<T = any> = Pick<
export type IDatabaseSoftDeleteManyOptions<T = any> = IDatabaseManyOptions<T>;

export type IDatabaseRestoreManyOptions<T = any> = IDatabaseManyOptions<T>;

export type IDatabaseRawOptions<T = any> = Pick<
IDatabaseOptions<T>,
'session' | 'withDeleted'
>;
9 changes: 3 additions & 6 deletions src/common/pagination/pipes/pagination.filter-contain.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export function PaginationFilterContainPipe(
async transform(
value: string,
{ data: field }: ArgumentMetadata
): Promise<Record<string, any>> {
): Promise<Record<string, { $regex: RegExp; $options: string }>> {
if (!value) {
return undefined;
value = '';
}

if (
Expand All @@ -33,10 +33,7 @@ export function PaginationFilterContainPipe(
value = value.trim();
}

const filter: Record<string, any> =
this.paginationService.filterContain(field, value);

return filter;
return this.paginationService.filterContain(field, value);
}
}

Expand Down
11 changes: 2 additions & 9 deletions src/common/pagination/pipes/pagination.filter-date.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ export function PaginationFilterDatePipe(
async transform(
value: string,
{ data: field }: ArgumentMetadata
): Promise<Record<string, any>> {
if (!value) {
return undefined;
}

): Promise<Record<string, Date>> {
let date: Date = this.helperDateService.create(value);

if (
Expand All @@ -37,10 +33,7 @@ export function PaginationFilterDatePipe(
date = this.helperDateService.startOfDay(date);
}

const filter: Record<string, any> =
this.paginationService.filterDate(field, date);

return filter;
return this.paginationService.filterDate(field, date);
}
}

Expand Down
13 changes: 5 additions & 8 deletions src/common/pagination/pipes/pagination.filter-equal.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function PaginationFilterEqualPipe(
async transform(
value: string,
{ data: field }: ArgumentMetadata
): Promise<Record<string, any>> {
): Promise<Record<string, string | number>> {
if (!value) {
return undefined;
}
Expand All @@ -44,13 +44,10 @@ export function PaginationFilterEqualPipe(
: value;
}

const filter: Record<string, any> =
this.paginationService.filterEqual<string | number>(
field,
finalValue
);

return filter;
return this.paginationService.filterEqual<string | number>(
field,
finalValue
);
}
}

Expand Down
23 changes: 8 additions & 15 deletions src/common/pagination/pipes/pagination.filter-in-boolean.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,16 @@ export function PaginationFilterInBooleanPipe(
async transform(
value: string,
{ data: field }: ArgumentMetadata
): Promise<Record<string, any>> {
if (!value) {
return undefined;
}
): Promise<Record<string, { $in: boolean[] }>> {
let finalValue: boolean[] = defaultValue as boolean[];

const filter: Record<string, any> = this.paginationService.filterIn<
boolean[]
>(
field,
value
? this.helperArrayService.unique(
value.split(',').map((val: string) => val === 'true')
)
: defaultValue
);
if (value) {
finalValue = this.helperArrayService.unique(
value.split(',').map((val: string) => val === 'true')
);
}

return filter;
return this.paginationService.filterIn<boolean>(field, finalValue);
}
}

Expand Down
24 changes: 9 additions & 15 deletions src/common/pagination/pipes/pagination.filter-in-enum.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@ export function PaginationFilterInEnumPipe<T>(
async transform(
value: string,
{ data: field }: ArgumentMetadata
): Promise<Record<string, any>> {
if (!value) {
return undefined;
}
): Promise<Record<string, { $in: T[] }>> {
let finalValue: T[] = defaultValue as T[];

const filter: Record<string, any> =
this.paginationService.filterIn<T>(
field,
value
? (value
.split(',')
.map((val: string) => defaultEnum[val])
.filter((val: string) => val) as T)
: defaultValue
);
if (value) {
finalValue = value
.split(',')
.map((val: string) => defaultEnum[val])
.filter((val: string) => val) as T[];
}

return filter;
return this.paginationService.filterIn<T>(field, finalValue);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/pagination/pipes/pagination.paging.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function PaginationPagingPipe(
...value,
page,
perPage,
offset,
_offset: offset,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/pagination/pipes/pagination.sort.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function PaginationSortPipe(

return {
...value,
sort,
_sort: sort,
_availableSort,
};
}
Expand Down
Loading

0 comments on commit 9918892

Please sign in to comment.