Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datamodel): add common api query parameters
begin to define common parameters for filtering,sorting, etc on endpoints
- Loading branch information
1 parent
e4e1986
commit c8bace5
Showing
2 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './error'; | ||
export * from './meta'; | ||
export * from './queryParameters'; |
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,64 @@ | ||
import { ApiProperty, ApiQuery } from "@nestjs/swagger"; | ||
import { IsArray, IsInt, IsOptional, IsString } from 'class-validator'; | ||
import { Transform, Type,} from 'class-transformer'; | ||
import { applyDecorators } from "@nestjs/common"; | ||
|
||
|
||
|
||
export class FieldsQueryParameters { | ||
@IsString({ each: true }) | ||
@IsArray() | ||
@IsOptional() | ||
@ApiProperty({ type: [String] }) | ||
@Transform((params) => { | ||
return params.value.split(','); | ||
}) | ||
fields!: string[]; | ||
} | ||
|
||
export const ApiFieldsQuery = (...args: string[]) => applyDecorators( | ||
ApiQuery({ name: 'fields', explode: false, style: 'form', type:String, isArray: true }) | ||
) | ||
|
||
// WIP can use this to define the query parameters for operations like sorting, filtering, paging, etc. | ||
class FullJsonAPIQueryParameters { | ||
@IsString({ each: true }) | ||
@IsArray() | ||
@IsOptional() | ||
@ApiProperty({ type: [String] }) | ||
@Transform((params) => { | ||
return params.value.split(','); | ||
}) | ||
fields!: string[]; | ||
|
||
@IsString({ each: true }) | ||
@IsArray() | ||
@IsOptional() | ||
@ApiProperty({ type: [String] }) | ||
@Transform((params) => { | ||
return params.value.split(','); | ||
}) | ||
sort!: string[]; | ||
|
||
@IsInt() | ||
@IsArray() | ||
@IsOptional() | ||
@ApiProperty({ type: Number, format: 'int' }) | ||
@Type(() => Number) | ||
page!: number; | ||
|
||
@IsString({ each: true }) | ||
@IsArray() | ||
@IsOptional() | ||
@ApiProperty({ type: [String] }) | ||
@Transform((params) => { | ||
return params.value.split(','); | ||
}) | ||
include!: string[]; | ||
|
||
|
||
@IsOptional() | ||
//@ApiProperty({ type: [String] }) | ||
// Maybe make this object | ||
filter!: string[]; | ||
} |