src/clients/clients.controller.ts
clients
Methods |
| Async bulkUpload | |||||||||
bulkUpload(orgId: string, file: Express.Multer.File)
|
|||||||||
Decorators :
@Post('upload')
|
|||||||||
|
Defined in src/clients/clients.controller.ts:95
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async create | |||||||||
create(orgId: string, dto: CreateClientDto)
|
|||||||||
Decorators :
@Post()
|
|||||||||
|
Defined in src/clients/clients.controller.ts:43
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async findAll | |||||||||
findAll(orgId: string, query: PaginationParams)
|
|||||||||
Decorators :
@Get()
|
|||||||||
|
Defined in src/clients/clients.controller.ts:53
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Async findOne |
findOne(orgId: string, id: string)
|
Decorators :
@Get(':id')
|
|
Defined in src/clients/clients.controller.ts:62
|
|
Returns :
unknown
|
| Async remove |
remove(orgId: string, id: string)
|
Decorators :
@Delete(':id')
|
|
Defined in src/clients/clients.controller.ts:83
|
|
Returns :
unknown
|
| Async update | ||||||||||||
update(orgId: string, id: string, dto: UpdateClientDto)
|
||||||||||||
Decorators :
@Patch(':id')
|
||||||||||||
|
Defined in src/clients/clients.controller.ts:72
|
||||||||||||
|
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 { ClientsService } from './clients.service';
import { CreateClientDto } from './dto/create-client.dto';
import { UpdateClientDto } from './dto/update-client.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';
/**
* Customer service & planners commonly need to add and update client
* records, so they're included alongside admins in the writer set.
*/
const CLIENT_WRITERS = ['SUPER_ADMIN', 'ADMIN', 'OPERATIONS_MANAGER', 'PLANNER', 'CUSTOMER_SERVICE'] as const;
@ApiTags('Clients')
@ApiBearerAuth()
@UseGuards(CombinedAuthGuard, RolesGuard)
@Controller('clients')
export class ClientsController {
constructor(private readonly clientsService: ClientsService) {}
@Post()
@Roles(...CLIENT_WRITERS)
@ApiOperation({ summary: 'Create a new client' })
async create(
@CurrentUser('organizationId') orgId: string,
@Body() dto: CreateClientDto,
) {
return this.clientsService.create(orgId, dto);
}
@Get()
@ApiPagination()
@ApiOperation({ summary: 'List all clients (org-scoped)' })
async findAll(
@CurrentUser('organizationId') orgId: string,
@Query() query: PaginationParams,
) {
return this.clientsService.findAll(orgId, query);
}
@Get(':id')
@ApiOperation({ summary: 'Get client by ID (org-scoped)' })
async findOne(
@CurrentUser('organizationId') orgId: string,
@Param('id') id: string,
) {
return this.clientsService.findOne(orgId, id);
}
@Patch(':id')
@Roles(...CLIENT_WRITERS)
@ApiOperation({ summary: 'Update a client (org-scoped)' })
async update(
@CurrentUser('organizationId') orgId: string,
@Param('id') id: string,
@Body() dto: UpdateClientDto,
) {
return this.clientsService.update(orgId, id, dto);
}
@Delete(':id')
@Roles('SUPER_ADMIN', 'ADMIN', 'OPERATIONS_MANAGER')
@ApiOperation({ summary: 'Delete a client (blocked when orders exist)' })
async remove(
@CurrentUser('organizationId') orgId: string,
@Param('id') id: string,
) {
return this.clientsService.remove(orgId, id);
}
@Post('upload')
@Roles(...CLIENT_WRITERS)
@ApiOperation({ summary: 'Bulk upload clients 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.clientsService.bulkUploadFromFile(orgId, file);
}
}