File

src/clients/clients.controller.ts

Prefix

clients

Index

Methods

Methods

Async bulkUpload
bulkUpload(orgId: string, file: Express.Multer.File)
Decorators :
@Post('upload')
@Roles(undefined)
@ApiOperation({summary: 'Bulk upload clients 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: CreateClientDto)
Decorators :
@Post()
@Roles(undefined)
@ApiOperation({summary: 'Create a new client'})
Parameters :
Name Type Optional
orgId string No
dto CreateClientDto No
Returns : unknown
Async findAll
findAll(orgId: string, query: PaginationParams)
Decorators :
@Get()
@ApiPagination()
@ApiOperation({summary: 'List all clients (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 client 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('SUPER_ADMIN', 'ADMIN', 'OPERATIONS_MANAGER')
@ApiOperation({summary: 'Delete a client (blocked when orders exist)'})
Parameters :
Name Type Optional
orgId string No
id string No
Returns : unknown
Async update
update(orgId: string, id: string, dto: UpdateClientDto)
Decorators :
@Patch(':id')
@Roles(undefined)
@ApiOperation({summary: 'Update a client (org-scoped)'})
Parameters :
Name Type Optional
orgId string No
id string No
dto UpdateClientDto 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 { 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);
  }
}

results matching ""

    No results matching ""