File

src/alert/alert.controller.ts

Prefix

alert

Index

Methods

Methods

createAlert
createAlert(req, createAlertInput: CreateAlertDto)
Decorators :
@Post()
@ApiOkResponse({type: Alert})
@UsePipes(validationPipe)
Parameters :
Name Type Optional
req No
createAlertInput CreateAlertDto No
Returns : any
deleteAlert
deleteAlert(id: string)
Decorators :
@Delete(':id')
@ApiOkResponse({type: Alert})
@UsePipes(validationPipe)
Parameters :
Name Type Optional
id string No
Returns : Promise<Alert>
Async findAllForUser
findAllForUser(req, queryOptions: literal type)
Decorators :
@Get()
@ApiOkResponse({type: Alert})
Parameters :
Name Type Optional
req No
queryOptions literal type No
Returns : Promise<Alert[]>
getAlert
getAlert(id: string)
Decorators :
@Get(':id')
@ApiOkResponse({type: Alert})
@UsePipes(validationPipe)
Parameters :
Name Type Optional
id string No
Returns : Promise<Alert>
getAlertsByMetricID
getAlertsByMetricID(req, metricId)
Decorators :
@Get('/metric/:metricId/list')
@ApiOkResponse({type: Alert, isArray: true})
@UsePipes(validationPipe)
Parameters :
Name Optional
req No
metricId No
Returns : any
getAlertsByProjectID
getAlertsByProjectID(projectId)
Decorators :
@Get('/project/:projectId/list')
@ApiOkResponse({type: Alert, isArray: true})
@UsePipes(validationPipe)
Parameters :
Name Optional
projectId No
Returns : any
update
update(id: string, updateAlertDto: UpdateAlertDto)
Decorators :
@Patch(':id')
@ApiOkResponse({type: Alert})
@UsePipes(new ValidationPipe())
Parameters :
Name Type Optional
id string No
updateAlertDto UpdateAlertDto No
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);
  }
}

results matching ""

    No results matching ""