mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
Nest runs class and method guards together, so a class gate naming only the view key silently required view AND action. Staff granted just an action were denied before their key was checked. Each class gate now names every key its routes use, and FleetView accepts an array so the fleet controllers keep their coarse fallback. Drops the one-off grant mapping SQL with it: already applied to dev, and this fix removes the companion-view rule that was its recurring part.
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { Controller, Post, Get, Patch, Delete, Body, Param, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
import { BookingStaff } from '../../common/booking-guards';
|
|
import { FREIGHT_PERMS } from '../../seed/freight-permissions.registry';
|
|
import { ComplianceService } from './compliance.service';
|
|
import {
|
|
CreateComplianceRecordDto,
|
|
UpdateComplianceRecordDto,
|
|
} from './dto/create-compliance-record.dto';
|
|
import { ComplianceType } from './entities/compliance-record.entity';
|
|
|
|
@ApiTags('Vehicle Compliance')
|
|
@Controller('compliance')
|
|
// Class gate lists every key its routes use: Nest runs class AND method
|
|
// guards, so a key missing here would deny before the route's own key runs.
|
|
@BookingStaff([
|
|
FREIGHT_PERMS.compliance.view,
|
|
FREIGHT_PERMS.compliance.manage,
|
|
])
|
|
export class ComplianceController {
|
|
constructor(private readonly complianceService: ComplianceService) {}
|
|
|
|
@Post()
|
|
@BookingStaff(FREIGHT_PERMS.compliance.manage)
|
|
@ApiOperation({ summary: 'Create a compliance record' })
|
|
create(@Body() dto: CreateComplianceRecordDto) {
|
|
return this.complianceService.create(dto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List compliance records' })
|
|
findAll(
|
|
@Query('vehicleId') vehicleId?: string,
|
|
@Query('type') type?: ComplianceType,
|
|
) {
|
|
return this.complianceService.findAll({ vehicleId, type });
|
|
}
|
|
|
|
@Get('alerts')
|
|
@ApiOperation({ summary: 'List overdue / due-soon compliance & expiry alerts' })
|
|
getAlerts() {
|
|
return this.complianceService.getAlerts();
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get a compliance record by ID' })
|
|
findOne(@Param('id') id: string) {
|
|
return this.complianceService.findById(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@BookingStaff(FREIGHT_PERMS.compliance.manage)
|
|
@ApiOperation({ summary: 'Update a compliance record' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateComplianceRecordDto) {
|
|
return this.complianceService.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@BookingStaff(FREIGHT_PERMS.compliance.manage)
|
|
@ApiOperation({ summary: 'Soft-delete a compliance record' })
|
|
remove(@Param('id') id: string) {
|
|
return this.complianceService.remove(id);
|
|
}
|
|
}
|