File

src/drivers/drivers.controller.ts

Prefix

drivers

Index

Methods

Methods

Async bulkUpload
bulkUpload(orgId: string, file: Express.Multer.File)
Decorators :
@Post('upload')
@Roles(undefined)
@ApiOperation({summary: 'Bulk upload drivers from Excel/CSV'})
@ApiConsumes('multipart/form-data')
@UseInterceptors(undefined)
Parameters :
Name Type Optional
orgId string No
file Express.Multer.File No
Returns : unknown
Async create
create(orgId: string, dto: CreateDriverDto)
Decorators :
@Post()
@Roles(undefined)
@ApiOperation({summary: 'Create a new driver'})
Parameters :
Name Type Optional
orgId string No
dto CreateDriverDto No
Returns : unknown
Async findAll
findAll(orgId: string, query: PaginationParams)
Decorators :
@Get()
@ApiPagination()
@ApiOperation({summary: 'List all drivers (org-scoped)'})
Parameters :
Name Type Optional
orgId string No
query PaginationParams No
Returns : unknown
Async findOne
findOne(orgId: string, id: string)
Decorators :
@Get(':id')
@ApiOperation({summary: 'Get driver by ID (org-scoped)'})
Parameters :
Name Type Optional
orgId string No
id string No
Returns : unknown
Async remove
remove(orgId: string, id: string)
Decorators :
@Delete(':id')
@Roles(undefined)
@ApiOperation({summary: 'Delete a driver (blocked when in use by an active trip)'})
Parameters :
Name Type Optional
orgId string No
id string No
Returns : unknown
Async update
update(orgId: string, id: string, dto: UpdateDriverDto)
Decorators :
@Patch(':id')
@Roles(undefined)
@ApiOperation({summary: 'Update a driver (org-scoped)'})
Parameters :
Name Type Optional
orgId string No
id string No
dto UpdateDriverDto No
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 { DriversService } from './drivers.service';
import { CreateDriverDto } from './dto/create-driver.dto';
import { UpdateDriverDto } from './dto/update-driver.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';

/**
 * Drivers contain PII (license number, phone). Mutations are restricted
 * to admins; reads are kept open so dispatch can see who's available.
 */
const DRIVER_WRITERS = ['SUPER_ADMIN', 'ADMIN', 'OPERATIONS_MANAGER'] as const;

@ApiTags('Drivers')
@ApiBearerAuth()
@UseGuards(CombinedAuthGuard, RolesGuard)
@Controller('drivers')
export class DriversController {
  constructor(private readonly driversService: DriversService) {}

  @Post()
  @Roles(...DRIVER_WRITERS)
  @ApiOperation({ summary: 'Create a new driver' })
  async create(
    @CurrentUser('organizationId') orgId: string,
    @Body() dto: CreateDriverDto,
  ) {
    return this.driversService.create(orgId, dto);
  }

  @Get()
  @ApiPagination()
  @ApiOperation({ summary: 'List all drivers (org-scoped)' })
  async findAll(
    @CurrentUser('organizationId') orgId: string,
    @Query() query: PaginationParams,
  ) {
    return this.driversService.findAll(orgId, query);
  }

  @Get(':id')
  @ApiOperation({ summary: 'Get driver by ID (org-scoped)' })
  async findOne(
    @CurrentUser('organizationId') orgId: string,
    @Param('id') id: string,
  ) {
    return this.driversService.findOne(orgId, id);
  }

  @Patch(':id')
  @Roles(...DRIVER_WRITERS)
  @ApiOperation({ summary: 'Update a driver (org-scoped)' })
  async update(
    @CurrentUser('organizationId') orgId: string,
    @Param('id') id: string,
    @Body() dto: UpdateDriverDto,
  ) {
    return this.driversService.update(orgId, id, dto);
  }

  @Delete(':id')
  @Roles(...DRIVER_WRITERS)
  @ApiOperation({ summary: 'Delete a driver (blocked when in use by an active trip)' })
  async remove(
    @CurrentUser('organizationId') orgId: string,
    @Param('id') id: string,
  ) {
    return this.driversService.remove(orgId, id);
  }

  @Post('upload')
  @Roles(...DRIVER_WRITERS)
  @ApiOperation({ summary: 'Bulk upload drivers 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.driversService.bulkUploadFromFile(orgId, file);
  }
}

results matching ""

    No results matching ""