Skip to content

Commit

Permalink
List violations statuses in an endpoint for admin filters
Browse files Browse the repository at this point in the history
  • Loading branch information
hkdobrev committed Jun 27, 2021
1 parent 2631f3a commit b581be8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/violations/api/violations-statuses.controller.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/violations/violations.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -22,6 +23,7 @@ import { SectionsModule } from 'src/sections/sections.module';
SectionsModule,
],
controllers: [
ViolationStatusesController,
ViolationsController,
ViolationCommentsController,
ViolationAssigneesController,
Expand Down

0 comments on commit b581be8

Please sign in to comment.