mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 09:42:53 +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.
88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
ParseUUIDPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { FleetManage, FleetView } from '../../common/booking-guards';
|
|
import { FREIGHT_PERMS } from '../../seed/freight-permissions.registry';
|
|
import { CreateCargoDto } from './dto/create-cargo.dto';
|
|
import { UpdateCargoDto } from './dto/update-cargo.dto';
|
|
import { LoadCargoDto } from './dto/load-cargo.dto';
|
|
import { DeliverCargoDto } from './dto/deliver-cargo.dto';
|
|
import { CargoesService } from './cargoes.service';
|
|
|
|
@ApiTags('cargoes')
|
|
@Controller('cargoes')
|
|
// 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.
|
|
@FleetView([
|
|
FREIGHT_PERMS.cargoes.view,
|
|
FREIGHT_PERMS.cargoes.create,
|
|
FREIGHT_PERMS.cargoes.update,
|
|
FREIGHT_PERMS.cargoes.delete,
|
|
])
|
|
export class CargoesController {
|
|
constructor(private readonly cargoesService: CargoesService) {}
|
|
|
|
@Post()
|
|
@FleetManage(FREIGHT_PERMS.cargoes.create)
|
|
@ApiOperation({ summary: 'Create a new cargo' })
|
|
create(@Body() dto: CreateCargoDto) {
|
|
return this.cargoesService.create(dto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List all cargoes' })
|
|
findAll(@Query() query: Record<string, string | undefined>) {
|
|
return this.cargoesService.findAll(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get a cargo by ID' })
|
|
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.cargoesService.findById(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@FleetManage(FREIGHT_PERMS.cargoes.update)
|
|
@ApiOperation({ summary: 'Update a cargo' })
|
|
update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateCargoDto) {
|
|
return this.cargoesService.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@FleetManage(FREIGHT_PERMS.cargoes.delete)
|
|
@ApiOperation({ summary: 'Delete a cargo' })
|
|
remove(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.cargoesService.remove(id);
|
|
}
|
|
|
|
@Post(':id/load')
|
|
@FleetManage(FREIGHT_PERMS.cargoes.update)
|
|
@ApiOperation({ summary: 'Load cargo into a container' })
|
|
load(@Param('id', ParseUUIDPipe) id: string, @Body() dto: LoadCargoDto) {
|
|
return this.cargoesService.loadCargo(id, dto);
|
|
}
|
|
|
|
@Post(':id/unload')
|
|
@FleetManage(FREIGHT_PERMS.cargoes.update)
|
|
@ApiOperation({ summary: 'Unload cargo from container' })
|
|
unload(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.cargoesService.unloadCargo(id);
|
|
}
|
|
|
|
@Post(':id/deliver')
|
|
@FleetManage(FREIGHT_PERMS.cargoes.update)
|
|
@ApiOperation({ summary: 'Mark cargo as delivered' })
|
|
deliver(@Param('id', ParseUUIDPipe) id: string, @Body() dto?: DeliverCargoDto) {
|
|
return this.cargoesService.deliverCargo(id, dto);
|
|
}
|
|
}
|