mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 08:32:54 +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.
95 lines
2.8 KiB
TypeScript
95 lines
2.8 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Patch,
|
|
Delete,
|
|
Param,
|
|
Body,
|
|
Query,
|
|
ParseUUIDPipe,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { BookingStaff } from '../../common/booking-guards';
|
|
import { FREIGHT_PERMS } from '../../seed/freight-permissions.registry';
|
|
import { VehiclesService } from './vehicles.service';
|
|
import { CreateVehicleDto } from './dto/create-vehicle.dto';
|
|
import { UpdateVehicleDto } from './dto/update-vehicle.dto';
|
|
import { FleetHistoryService } from '../fleet-history/fleet-history.service';
|
|
|
|
@ApiTags('vehicles')
|
|
@ApiBearerAuth()
|
|
@Controller('vehicles')
|
|
// 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.vehicles.view,
|
|
FREIGHT_PERMS.vehicles.create,
|
|
FREIGHT_PERMS.vehicles.update,
|
|
FREIGHT_PERMS.vehicles.delete,
|
|
])
|
|
export class VehiclesController {
|
|
constructor(
|
|
private readonly vehiclesService: VehiclesService,
|
|
private readonly fleetHistory: FleetHistoryService,
|
|
) {}
|
|
|
|
@Post()
|
|
@BookingStaff(FREIGHT_PERMS.vehicles.create)
|
|
@ApiOperation({ summary: 'Create a new vehicle' })
|
|
create(@Body() createVehicleDto: CreateVehicleDto) {
|
|
return this.vehiclesService.create(createVehicleDto);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'Get all vehicles with filters' })
|
|
findAll(
|
|
@Query('search') search?: string,
|
|
@Query('status') status?: string,
|
|
@Query('availability') availability?: string,
|
|
@Query('page') page?: string,
|
|
@Query('limit') limit?: string,
|
|
@Query('sortBy') sortBy?: string,
|
|
@Query('sortOrder') sortOrder?: 'ASC' | 'DESC',
|
|
) {
|
|
return this.vehiclesService.findAll({
|
|
search,
|
|
status: status as any,
|
|
availability: availability as any,
|
|
page: page ? parseInt(page) : undefined,
|
|
limit: limit ? parseInt(limit) : undefined,
|
|
sortBy,
|
|
sortOrder,
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get vehicle by id' })
|
|
findOne(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.vehiclesService.findById(id);
|
|
}
|
|
|
|
@Get(':id/history')
|
|
@ApiOperation({ summary: 'Get vehicle assignment, status & mile history' })
|
|
history(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.fleetHistory.getVehicleHistory(id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@BookingStaff(FREIGHT_PERMS.vehicles.update)
|
|
@ApiOperation({ summary: 'Update a vehicle' })
|
|
update(
|
|
@Param('id', ParseUUIDPipe) id: string,
|
|
@Body() updateVehicleDto: UpdateVehicleDto,
|
|
) {
|
|
return this.vehiclesService.update(id, updateVehicleDto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@BookingStaff(FREIGHT_PERMS.vehicles.delete)
|
|
@ApiOperation({ summary: 'Delete a vehicle' })
|
|
remove(@Param('id', ParseUUIDPipe) id: string) {
|
|
return this.vehiclesService.remove(id);
|
|
}
|
|
}
|