87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
Req,
|
|
} from '@nestjs/common';
|
|
import { CurrentAuth } from '../auth/decorators/current-auth.decorator';
|
|
import { RequirePermissions } from '../authorization/decorators/require-permissions.decorator';
|
|
import type { AuthPrincipal, RequestWithContext } from '../common/http/request-context';
|
|
import { CloseInspectionFindingDto } from './dto/close-inspection-finding.dto';
|
|
import { CreateInspectionFindingDto } from './dto/create-inspection-finding.dto';
|
|
import { ListInspectionFindingsQueryDto } from './dto/list-inspection-findings-query.dto';
|
|
import { UpdateInspectionFindingDto } from './dto/update-inspection-finding.dto';
|
|
import { InspectionFindingsService } from './inspection-findings.service';
|
|
|
|
@Controller('inspection-acts/:actId/findings')
|
|
export class InspectionActFindingsController {
|
|
constructor(private readonly findings: InspectionFindingsService) {}
|
|
|
|
@Get()
|
|
@RequirePermissions('inspection_findings.read')
|
|
list(@Param('actId', new ParseUUIDPipe({ version: '4' })) actId: string) {
|
|
return this.findings.listForAct(actId);
|
|
}
|
|
|
|
@Post()
|
|
@RequirePermissions('inspection_findings.create')
|
|
create(
|
|
@Param('actId', new ParseUUIDPipe({ version: '4' })) actId: string,
|
|
@Body() dto: CreateInspectionFindingDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.findings.create(actId, dto, principal, request);
|
|
}
|
|
}
|
|
|
|
@Controller('inspection-findings')
|
|
export class InspectionFindingsController {
|
|
constructor(private readonly findings: InspectionFindingsService) {}
|
|
|
|
@Get()
|
|
@RequirePermissions('inspection_findings.read')
|
|
list(@Query() query: ListInspectionFindingsQueryDto) {
|
|
return this.findings.listGlobal(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePermissions('inspection_findings.read')
|
|
get(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
|
|
return this.findings.getById(id);
|
|
}
|
|
|
|
@Get(':id/verification-history')
|
|
@RequirePermissions('inspection_findings.read')
|
|
getVerificationHistory(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
|
|
return this.findings.getVerificationHistory(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@RequirePermissions('inspection_findings.update')
|
|
update(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: UpdateInspectionFindingDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.findings.update(id, dto, principal, request);
|
|
}
|
|
|
|
@Patch(':id/close')
|
|
@RequirePermissions('inspection_findings.close')
|
|
close(
|
|
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
|
@Body() dto: CloseInspectionFindingDto,
|
|
@CurrentAuth() principal: AuthPrincipal,
|
|
@Req() request: RequestWithContext,
|
|
) {
|
|
return this.findings.close(id, dto, principal, request);
|
|
}
|
|
}
|