@nestjs/common#ParseArrayPipe TypeScript Examples
The following examples show how to use
@nestjs/common#ParseArrayPipe.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sensors.controller.ts From aqualink-app with MIT License | 6 votes |
@ApiTimeSeriesResponse()
@ApiNestNotFoundResponse('No data were found with the specified sensor id')
@ApiOperation({ summary: 'Get data from a specified sensor' })
@ApiParam({ name: 'id', example: 'SPOT-0000' })
@ApiQuery({ name: 'startDate', example: '2021-01-10T12:00:00Z' })
@ApiQuery({ name: 'endDate', example: '2021-05-10T12:00:00Z' })
@ApiQuery({
name: 'metrics',
example: ['bottom_temperature', 'top_temperature'],
})
@Get(':id/data')
findSensorData(
@Param('id') sensorId: string,
@Query('metrics', ParseArrayPipe) metrics: string[],
@Query('startDate', ParseDatePipe) startDate?: string,
@Query('endDate', ParseDatePipe) endDate?: string,
) {
return this.coralAtlasService.findSensorData(
sensorId,
metrics,
startDate,
endDate,
);
}
Example #2
Source File: time-series.controller.ts From aqualink-app with MIT License | 6 votes |
@ApiTimeSeriesResponse()
@ApiOperation({
summary:
'Returns specified time series data for a specified site point of interest',
})
@ApiQuery({ name: 'start', example: '2021-05-18T10:20:28.017Z' })
@ApiQuery({ name: 'end', example: '2021-05-18T10:20:28.017Z' })
@ApiQuery({
name: 'metrics',
example: [Metric.BOTTOM_TEMPERATURE, Metric.TOP_TEMPERATURE],
})
@ApiQuery({ name: 'hourly', example: false, required: false })
@Get('sites/:siteId/site-survey-points/:surveyPointId')
findSurveyPointData(
@Param() surveyPointDataDto: SurveyPointDataDto,
@Query(
'metrics',
new DefaultValuePipe(Object.values(Metric)),
ParseArrayPipe,
)
metrics: Metric[],
@Query('start', ParseDatePipe) startDate?: string,
@Query('end', ParseDatePipe) endDate?: string,
@Query('hourly') hourly?: boolean,
) {
return this.timeSeriesService.findSurveyPointData(
surveyPointDataDto,
metrics,
startDate,
endDate,
hourly,
);
}
Example #3
Source File: time-series.controller.ts From aqualink-app with MIT License | 6 votes |
@ApiTimeSeriesResponse()
@ApiOperation({
summary: 'Returns specified time series data for a specified site',
})
@ApiQuery({ name: 'start', example: '2021-05-18T10:20:28.017Z' })
@ApiQuery({ name: 'end', example: '2021-05-18T10:20:28.017Z' })
@ApiQuery({
name: 'metrics',
example: [Metric.BOTTOM_TEMPERATURE, Metric.TOP_TEMPERATURE],
})
@ApiQuery({ name: 'hourly', example: false, required: false })
@Get('sites/:siteId')
findSiteData(
@Param() siteDataDto: SiteDataDto,
@Query(
'metrics',
new DefaultValuePipe(Object.values(Metric)),
ParseArrayPipe,
)
metrics: Metric[],
@Query('start', ParseDatePipe) startDate?: string,
@Query('end', ParseDatePipe) endDate?: string,
@Query('hourly', ParseBoolPipe) hourly?: boolean,
) {
return this.timeSeriesService.findSiteData(
siteDataDto,
metrics,
startDate,
endDate,
hourly,
);
}
Example #4
Source File: user.controller.ts From MyAPI with MIT License | 6 votes |
@ApiOperation({ summary: 'Add new users' })
@ApiBody({ type: User, isArray: true, description: 'Info of the users' })
@ApiCreatedResponse({ description: 'The users were created successfully' })
@ApiBadRequestResponse({ description: 'The users could not be created' })
@ApiForbiddenResponse({ description: 'You do not have the necessary role to perform this action' })
@UseGuards(RolesGuard)
@Roles(DefaultRole.Admin)
@Post('bulk')
@HttpCode(HttpStatus.CREATED)
async createBulk(
@Body(new ParseArrayPipe({ items: User })) users: User[]
): Promise<void> {
try {
await this.userService.addUsers(users)
} catch (error) {
/**
* Validate database exceptions
*/
switch(error.code) {
case POSTGRES.UNIQUE_VIOLATION:
throw new BadRequestException(ERRORS.UNIQUE_VIOLATION)
default:
this.logger.error(error.message, 'ADD_USERS')
throw new BadRequestException(error.message)
}
}
}
Example #5
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Create Users - Batch
* @param dto User Form but in Array format
* @example POST /users/bulk
*/
@ApiTags('Users batch operations')
@ApiOperation({ summary: 'Create Users - Batch', description: 'Register users in batch.' })
@ApiCreatedResponse({ status: 201, description: 'Users created successfully', type: User })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiBadRequestResponse({ status: 400, description: 'You will prompt with an array with the validation issues' })
@ApiBody({ type: [CreateUserDto] })
@Post('bulk')
async createBulk(@Body(new ParseArrayPipe({ items: CreateUserDto })) dto: CreateUserDto[]): Promise<DataOutput<IUser[]>> {
return { message: 'Users created successfully', output: await this.service.createBatch(dto) };
}
Example #6
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Get users by ids - Batch
* @param ids User ID integer Array
* @example GET /users/bulk?ids=1,2,3
*/
@ApiTags('Users batch operations')
@ApiOperation({
summary: 'Get Users by ids- Batch',
description: 'Get users by Ids. You will have to provide a query param of ids separated by comas example: ?ids=1,2,3',
})
@ApiOkResponse({ status: 200, description: 'Success response', type: [User] })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiQuery({ name: 'ids', required: true, type: 'string', example: '1,2,3' })
@Get('bulk')
async getByIds(@Query('ids', new ParseArrayPipe({ items: Number, separator: ',' })) ids: number[]) {
return await this.service.getByIds(ids);
}
Example #7
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Update many
* @param dtos Update User Form including the ID insude
* @example PUT /users/bulk
*/
@ApiTags('Users batch operations')
@ApiOperation({ summary: 'Update users - Batch', description: 'Update users. You have to provide an id each object inside an updateUserDTO' })
@ApiOkResponse({ status: 200, description: 'Success response' })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiBadRequestResponse({ status: 400, description: 'You will prompt with an array with the validation issues' })
@ApiBody({ required: true, type: [UpdateUserDto] })
@Put('bulk')
async updateMany(@Body(new ParseArrayPipe({ items: UpdateUserDto })) dtos: UpdateUserDto[]) {
return await this.service.updateMany(dtos);
}
Example #8
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Softdelete users (SOFT DELETION)
* @param ids User ID integers ?ids=1,2,3
* @example DELETE /users/bulk
*/
@ApiTags('Users batch operations')
@ApiOperation({
summary: 'Softdelete users - Batch',
description: '(SOFT DELETION) Delete users. You will have to provide a query param of ids separated by comas example: ?ids=1,2,3',
})
@ApiOkResponse({ status: 200, description: 'Success response' })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiBadRequestResponse({ status: 400, description: 'You will prompt with an array with the validation issues' })
@ApiQuery({ name: 'ids', required: true, type: 'string', example: '1,2,3' })
@Delete('bulk')
async deleteMany(@Query('ids', new ParseArrayPipe({ items: Number, separator: ',' })) ids: number[]) {
return await this.service.softDeleteMany(ids);
}
Example #9
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Delete many (ATENTTION: PERMANENT DELETION)
* @param ids User ID integers ?ids=1,2,3
* @example DELETE /users?ids=1,2,3
*/
@ApiTags('Users batch operations')
@ApiOperation({
summary: 'Hard delete users - Batch',
description: '(HARD DELETION) Delete users. You will have to provide a query param of ids separated by comas example: ?ids=1,2,3',
})
@ApiOkResponse({ status: 200, description: 'Success response' })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiQuery({ name: 'ids', required: true, type: 'string', example: '1,2,3' })
@Delete('bulk/hard')
async hardDeleteMany(@Query('ids', new ParseArrayPipe({ items: Number, separator: ',' })) ids: number[]) {
return await this.service.deleteMany(ids);
}
Example #10
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Restore softdeleted users
* @param ids User ID integers ?ids=1,2,3
* @example DELETE /users/bulk/restore?ids=1,2,3
*/
@ApiTags('Users batch operations')
@ApiOperation({
summary: 'Restore users - Batch',
description: 'Restore users. You will have to provide a query param of ids separated by comas example: ?ids=1,2,3',
})
@ApiOkResponse({ status: 200, description: 'Success response' })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiQuery({ name: 'ids', required: true, type: 'string', example: '1,2,3' })
@Patch('bulk/restore')
async restoreMany(@Query('ids', new ParseArrayPipe({ items: Number, separator: ',' })) ids: number[]) {
return await this.service.restoreMany(ids);
}
Example #11
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Disable users
* @param ids User ID integers ?ids=1,2,3
* @example DELETE /users/bulk/disable?ids=1,2,3
*/
@ApiTags('Users batch operations')
@ApiOperation({
summary: 'Disable users - Batch',
description: 'Disable users. You will have to provide a query param of ids separated by comas example: ?ids=1,2,3',
})
@ApiOkResponse({ status: 200, description: 'Success response' })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiQuery({ name: 'ids', required: true, type: 'string', example: '1,2,3' })
@Patch('bulk/disable')
async disableMany(@Query('ids', new ParseArrayPipe({ items: Number, separator: ',' })) ids: number[]) {
return await this.service.disableMany(ids);
}
Example #12
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Enable users
* @param ids User ID integers ?ids=1,2,3
* @example DELETE /users/bulk/enable?ids=1,2,3
*/
@ApiTags('Users batch operations')
@ApiOperation({
summary: 'Enable users - Batch',
description: 'Enable users. You will have to provide a query param of ids separated by comas example: ?ids=1,2,3',
})
@ApiOkResponse({ status: 200, description: 'Success response' })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiQuery({ name: 'ids', required: true, type: 'string', example: '1,2,3' })
@Patch('bulk/enable')
async enableMany(@Query('ids', new ParseArrayPipe({ items: Number, separator: ',' })) ids: number[]) {
return await this.service.enableMany(ids);
}
Example #13
Source File: users.controller.ts From nestjs-starter with MIT License | 6 votes |
/**
* Get users by ids - Batch
* @param ids User ID integer Array
* @example GET /users/bulk?ids=1,2,3
*/
@ApiTags('Users batch operations')
@ApiOperation({
summary: 'Get Users by ids- Batch',
description: 'Get Deleted users by Ids. You will have to provide a query param of ids separated by comas example: ?ids=1,2,3',
})
@ApiOkResponse({ status: 200, description: 'Success response', type: User })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized' })
@ApiBadGatewayResponse({ status: 502, description: 'Something happened' })
@ApiQuery({ name: 'ids', required: false, type: 'number', example: '1,2,3', explode: false })
@Get('bulk/deleted')
async getSoftdeletedUsersByIds(@Query('ids', new ParseArrayPipe({ items: Number, separator: ',' })) ids?: number[]) {
return await this.service.getDeletedUsers(ids);
}