From b581be81b81bb1dacfdb123b3b767d36250df2f4 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Sun, 27 Jun 2021 15:08:03 +0300 Subject: [PATCH] List violations statuses in an endpoint for admin filters --- .../api/violations-statuses.controller.ts | 34 +++++++++++++++++++ src/violations/violations.module.ts | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 src/violations/api/violations-statuses.controller.ts diff --git a/src/violations/api/violations-statuses.controller.ts b/src/violations/api/violations-statuses.controller.ts new file mode 100644 index 00000000..ad8d56be --- /dev/null +++ b/src/violations/api/violations-statuses.controller.ts @@ -0,0 +1,34 @@ +import { Ability } from '@casl/ability'; +import { + Controller, + Get, + HttpCode, + UsePipes, + ValidationPipe, + UseGuards, +} from '@nestjs/common'; +import { Action } from 'src/casl/action.enum'; +import { CheckPolicies } from 'src/casl/check-policies.decorator'; +import { PoliciesGuard } from 'src/casl/policies.guard'; +import { Violation, ViolationStatus } from '../entities/violation.entity'; +import { ViolationDto } from './violation.dto'; + +@Controller('violations/statuses') +export class ViolationStatusesController { + @Get() + @HttpCode(200) + @UseGuards(PoliciesGuard) + @CheckPolicies((ability: Ability) => ability.can(Action.Manage, Violation)) + @UsePipes(new ValidationPipe({ transform: true })) + index(): ViolationDto[] { + const result: ViolationDto[] = []; + + Object.values(ViolationStatus).forEach((status: ViolationStatus) => { + const v = new ViolationDto(); + v.status = status; + result.push(v); + }); + + return result; + } +} diff --git a/src/violations/violations.module.ts b/src/violations/violations.module.ts index 680ab39b..6ef371ef 100644 --- a/src/violations/violations.module.ts +++ b/src/violations/violations.module.ts @@ -12,6 +12,7 @@ import { Violation } from './entities/violation.entity'; import { ViolationsRepository } from './entities/violations.repository'; import { UsersModule } from 'src/users/users.module'; import { SectionsModule } from 'src/sections/sections.module'; +import { ViolationStatusesController } from './api/violations-statuses.controller'; @Module({ imports: [ @@ -22,6 +23,7 @@ import { SectionsModule } from 'src/sections/sections.module'; SectionsModule, ], controllers: [ + ViolationStatusesController, ViolationsController, ViolationCommentsController, ViolationAssigneesController,