-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from andrechristikan/development
Development
- Loading branch information
Showing
58 changed files
with
920 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/common/pagination/pipes/pagination.filter-nin-enum.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Inject, Injectable, mixin, Type } from '@nestjs/common'; | ||
import { PipeTransform, Scope } from '@nestjs/common/interfaces'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { IPaginationFilterOptions } from 'src/common/pagination/interfaces/pagination.interface'; | ||
import { PaginationService } from 'src/common/pagination/services/pagination.service'; | ||
import { IRequestApp } from 'src/common/request/interfaces/request.interface'; | ||
|
||
export function PaginationFilterNinEnumPipe<T>( | ||
field: string, | ||
defaultValue: T, | ||
defaultEnum: Record<string, any>, | ||
options?: IPaginationFilterOptions | ||
): Type<PipeTransform> { | ||
@Injectable({ scope: Scope.REQUEST }) | ||
class MixinPaginationFilterInEnumPipe implements PipeTransform { | ||
constructor( | ||
@Inject(REQUEST) protected readonly request: IRequestApp, | ||
private readonly paginationService: PaginationService | ||
) {} | ||
|
||
async transform(value: string): Promise<Record<string, any>> { | ||
if (options?.raw) { | ||
this.addToRequestInstance(value); | ||
return { | ||
[field]: value, | ||
}; | ||
} | ||
|
||
const finalValue: T[] = value | ||
? (value | ||
.split(',') | ||
.map((val: string) => defaultEnum[val]) | ||
.filter((val: string) => val) as T[]) | ||
: (defaultValue as T[]); | ||
|
||
return this.paginationService.filterNin<T>(field, finalValue); | ||
} | ||
|
||
addToRequestInstance(value: any): void { | ||
this.request.__pagination = { | ||
...this.request.__pagination, | ||
filters: this.request.__pagination?.filters | ||
? { | ||
...this.request.__pagination?.filters, | ||
[field]: value, | ||
} | ||
: { [field]: value }, | ||
}; | ||
} | ||
} | ||
|
||
return mixin(MixinPaginationFilterInEnumPipe); | ||
} |
55 changes: 55 additions & 0 deletions
55
src/common/pagination/pipes/pagination.filter-not-equal.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Inject, Injectable, mixin, Type } from '@nestjs/common'; | ||
import { PipeTransform, Scope } from '@nestjs/common/interfaces'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { IPaginationFilterEqualOptions } from 'src/common/pagination/interfaces/pagination.interface'; | ||
import { PaginationService } from 'src/common/pagination/services/pagination.service'; | ||
import { IRequestApp } from 'src/common/request/interfaces/request.interface'; | ||
|
||
export function PaginationFilterNotEqualPipe( | ||
field: string, | ||
options?: IPaginationFilterEqualOptions | ||
): Type<PipeTransform> { | ||
@Injectable({ scope: Scope.REQUEST }) | ||
class MixinPaginationFilterEqualPipe implements PipeTransform { | ||
constructor( | ||
@Inject(REQUEST) protected readonly request: IRequestApp, | ||
private readonly paginationService: PaginationService | ||
) {} | ||
|
||
async transform( | ||
value: string | ||
): Promise<Record<string, string | number>> { | ||
if (!value) { | ||
return undefined; | ||
} | ||
|
||
if (options?.raw) { | ||
this.addToRequestInstance(value); | ||
return { | ||
[field]: value, | ||
}; | ||
} | ||
|
||
const finalValue: string | number = options?.isNumber | ||
? Number.parseInt(value) | ||
: value.trim(); | ||
|
||
this.addToRequestInstance(finalValue); | ||
return this.paginationService.filterEqual(field, finalValue); | ||
} | ||
|
||
addToRequestInstance(value: any): void { | ||
this.request.__pagination = { | ||
...this.request.__pagination, | ||
filters: this.request.__pagination?.filters | ||
? { | ||
...this.request.__pagination?.filters, | ||
[field]: value, | ||
} | ||
: { [field]: value }, | ||
}; | ||
} | ||
} | ||
|
||
return mixin(MixinPaginationFilterEqualPipe); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.