src/alert/alert.controller.ts
alert
Methods |
| createAlert | |||||||||
createAlert(req, createAlertInput: CreateAlertDto)
|
|||||||||
Decorators :
@Post()
|
|||||||||
|
Defined in src/alert/alert.controller.ts:32
|
|||||||||
|
Parameters :
Returns :
any
|
| deleteAlert | ||||||
deleteAlert(id: string)
|
||||||
Decorators :
@Delete(':id')
|
||||||
|
Defined in src/alert/alert.controller.ts:92
|
||||||
|
Parameters :
Returns :
Promise<Alert>
|
| Async findAllForUser | |||||||||
findAllForUser(req, queryOptions: literal type)
|
|||||||||
Decorators :
@Get()
|
|||||||||
|
Defined in src/alert/alert.controller.ts:46
|
|||||||||
|
Parameters :
Returns :
Promise<Alert[]>
|
| getAlert | ||||||
getAlert(id: string)
|
||||||
Decorators :
@Get(':id')
|
||||||
|
Defined in src/alert/alert.controller.ts:75
|
||||||
|
Parameters :
Returns :
Promise<Alert>
|
| getAlertsByMetricID | ||||||
getAlertsByMetricID(req, metricId)
|
||||||
Decorators :
@Get('/metric/:metricId/list')
|
||||||
|
Defined in src/alert/alert.controller.ts:62
|
||||||
|
Parameters :
Returns :
any
|
| getAlertsByProjectID | ||||
getAlertsByProjectID(projectId)
|
||||
Decorators :
@Get('/project/:projectId/list')
|
||||
|
Defined in src/alert/alert.controller.ts:40
|
||||
|
Parameters :
Returns :
any
|
| update | |||||||||
update(id: string, updateAlertDto: UpdateAlertDto)
|
|||||||||
Decorators :
@Patch(':id')
|
|||||||||
|
Defined in src/alert/alert.controller.ts:82
|
|||||||||
|
Parameters :
Returns :
Promise<Alert>
|
import {
Body,
Controller,
Delete,
Get,
Param,
Patch,
Post,
Query,
Request,
UsePipes,
ValidationPipe,
} from "@nestjs/common";
import { AlertService } from "./alert.service";
import { ApiOkResponse } from "@nestjs/swagger";
import { Alert, AlertCategory, AlertStatus } from "./entities/alert.entity";
import { CreateAlertDto } from "./dto/create-alert.dto";
import { UpdateAlertDto } from "./dto/update-alert.dto";
const validationPipe = new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
});
@Controller("alert")
export class AlertController {
constructor(private readonly alertService: AlertService) {}
@Post()
@ApiOkResponse({ type: Alert })
@UsePipes(validationPipe)
createAlert(@Request() req, @Body() createAlertInput: CreateAlertDto) {
const userId = req.user.id;
return this.alertService.create(createAlertInput, userId);
}
@Get("/project/:projectId/list")
@ApiOkResponse({ type: Alert, isArray: true })
@UsePipes(validationPipe)
getAlertsByProjectID(@Param("projectId") projectId) {
return this.alertService.getAlertsByProjectID(+projectId);
}
@Get()
@ApiOkResponse({ type: Alert })
async findAllForUser(
@Request() req,
@Query()
queryOptions: {
pageSize?: number;
pageOffset?: number;
startId?: number;
},
): Promise<Alert[]> {
const userId = req.user.id;
return this.alertService.findAllByUserId(userId, queryOptions);
}
@Get("/metric/:metricId/list")
@ApiOkResponse({ type: Alert, isArray: true })
@UsePipes(validationPipe)
getAlertsByMetricID(@Request() req, @Param("metricId") metricId) {
const userId = req.user.id;
return this.alertService.findMany({
userId: userId,
targetTable:
this.alertService.alertCategoryToTableMap[AlertCategory.METRIC],
targetFilter: { equals: JSON.stringify({ metricId: +metricId }) },
});
}
@Get(":id")
@ApiOkResponse({ type: Alert })
@UsePipes(validationPipe)
getAlert(@Param("id") id: string): Promise<Alert> {
return this.alertService.getAlert(+id);
}
@Patch(":id")
@ApiOkResponse({ type: Alert })
@UsePipes(new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true }))
update(
@Param("id") id: string,
@Body() updateAlertDto: UpdateAlertDto,
): Promise<Alert> {
return this.alertService.update(+id, updateAlertDto);
}
@Delete(":id")
@ApiOkResponse({ type: Alert })
@UsePipes(validationPipe)
deleteAlert(@Param("id") id: string): Promise<Alert> {
return this.alertService.updateAlertStatus(+id, AlertStatus.DELETED);
}
}