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,