src/transporters/transporters.controller.ts
transporters
Methods |
| Async bulkUpload | |||||||||
bulkUpload(orgId: string, file: Express.Multer.File)
|
|||||||||
Decorators :
@Post('upload')
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async create | ||||||||||||
create(orgId: string, userId: string, dto: CreateTransporterDto)
|
||||||||||||
Decorators :
@Post()
|
||||||||||||
|
Parameters :
Returns :
unknown
|
| Async findAll | |||||||||
findAll(orgId: string, query: PaginationParams)
|
|||||||||
Decorators :
@Get()
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async findOne |
findOne(orgId: string, id: string)
|
Decorators :
@Get(':id')
|
|
Returns :
unknown
|
| Async remove |
remove(orgId: string, id: string)
|
Decorators :
@Delete(':id')
|
|
Returns :
unknown
|
| Async update | |||||||||||||||
update(orgId: string, id: string, userId: string, dto: UpdateTransporterDto)
|
|||||||||||||||
Decorators :
@Patch(':id')
|
|||||||||||||||
|
Parameters :
Returns :
unknown
|
import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
Query,
UseGuards,
UseInterceptors,
UploadedFile,
BadRequestException,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiConsumes } from '@nestjs/swagger';
import { TransportersService } from './transporters.service';
import { CreateTransporterDto } from './dto/create-transporter.dto';
import { UpdateTransporterDto } from './dto/update-transporter.dto';
import { CombinedAuthGuard } from '../auth/guards/combined-auth.guard';
import { RolesGuard } from '../auth/guards/roles.guard';
import { Roles } from '../auth/decorators/roles.decorator';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import { ApiPagination } from '../common/decorators/api-pagination.decorator';
import { PaginationParams } from '../common/utils/pagination.util';
/**
* Carrier (transporter) records describe sub-contracted fleet operators.
* Adding/editing them is an admin-only operation because it affects
* billing relationships and vehicle ownership.
*/
const CARRIER_WRITERS = ['SUPER_ADMIN', 'ADMIN', 'OPERATIONS_MANAGER'] as const;
@ApiTags('Transporters')
@ApiBearerAuth()
@UseGuards(CombinedAuthGuard, RolesGuard)
@Controller('transporters')
export class TransportersController {
constructor(private readonly transportersService: TransportersService) {}
@Post()
@Roles(...CARRIER_WRITERS)
@ApiOperation({ summary: 'Create a new carrier' })
async create(
@CurrentUser('organizationId') orgId: string,
@CurrentUser('id') userId: string,
@Body() dto: CreateTransporterDto,
) {
return this.transportersService.create(orgId, dto, userId);
}
@Get()
@ApiPagination()
@ApiOperation({ summary: 'List all carriers (org-scoped)' })
async findAll(
@CurrentUser('organizationId') orgId: string,
@Query() query: PaginationParams,
) {
return this.transportersService.findAll(orgId, query);
}
@Get(':id')
@ApiOperation({ summary: 'Get carrier by ID (org-scoped)' })
async findOne(
@CurrentUser('organizationId') orgId: string,
@Param('id') id: string,
) {
return this.transportersService.findOne(orgId, id);
}
@Patch(':id')
@Roles(...CARRIER_WRITERS)
@ApiOperation({ summary: 'Update a carrier (org-scoped)' })
async update(
@CurrentUser('organizationId') orgId: string,
@Param('id') id: string,
@CurrentUser('id') userId: string,
@Body() dto: UpdateTransporterDto,
) {
return this.transportersService.update(orgId, id, dto, userId);
}
@Delete(':id')
@Roles(...CARRIER_WRITERS)
@ApiOperation({ summary: 'Delete a carrier (blocked when vehicles still belong)' })
async remove(
@CurrentUser('organizationId') orgId: string,
@Param('id') id: string,
) {
return this.transportersService.remove(orgId, id);
}
@Post('upload')
@Roles(...CARRIER_WRITERS)
@ApiOperation({ summary: 'Bulk upload carriers from Excel/CSV' })
@ApiConsumes('multipart/form-data')
@UseInterceptors(FileInterceptor('file', { limits: { fileSize: 10 * 1024 * 1024 } }))
async bulkUpload(
@CurrentUser('organizationId') orgId: string,
@UploadedFile() file: Express.Multer.File,
) {
if (!file) throw new BadRequestException('No file uploaded');
return this.transportersService.bulkUploadFromFile(orgId, file);
}
}