import { Body, Controller, Delete, Get, Param, Post, Put, Query, UseGuards } from '@nestjs/common'; import { HqAuthGuard } from '../../common/guards/hq-auth.guard'; import { HqOperation } from '../../common/hq-operation/hq-operation.decorator'; import { HqOperationAction } from '../../common/hq-operation/hq-operation.constants'; import { CityWarehouseService } from '../city-scope/city-warehouse.service'; import { CreateCityWarehouseDto, UpdateCityWarehouseDto } from './dto/admin-mutate.dto'; import { AdminCityWarehousesQueryDto } from './dto/admin-query.dto'; import type { WarehouseManagerType, WarehouseStatus } from '@prisma/client'; @Controller('admin/cities/:cityId/warehouses') @UseGuards(HqAuthGuard) export class AdminCityWarehousesController { constructor(private readonly service: CityWarehouseService) {} @Get() list(@Param('cityId') cityId: string) { return this.service.listByCity(BigInt(cityId)); } @Post() @HqOperation({ action: HqOperationAction.WAREHOUSE_CREATE, refType: 'WAREHOUSE', refIdField: 'id', includeBody: true, }) create(@Param('cityId') cityId: string, @Body() dto: CreateCityWarehouseDto) { return this.service.create(BigInt(cityId), { name: dto.name, address: dto.address, contactName: dto.contactName, contactPhone: dto.contactPhone, managerType: dto.managerType as WarehouseManagerType, partnerAccountId: dto.partnerAccountId ? BigInt(dto.partnerAccountId) : undefined, status: dto.status as WarehouseStatus | undefined, }); } } @Controller('admin/city-warehouses') @UseGuards(HqAuthGuard) export class AdminCityWarehouseMutationsController { constructor(private readonly service: CityWarehouseService) {} @Get() listAll(@Query() query: AdminCityWarehousesQueryDto) { return this.service.listAll(query); } @Put(':id') @HqOperation({ action: HqOperationAction.WAREHOUSE_UPDATE, refType: 'WAREHOUSE', refIdParam: 'id', includeBody: true, }) update(@Param('id') id: string, @Body() dto: UpdateCityWarehouseDto) { return this.service.update(BigInt(id), { name: dto.name, address: dto.address, contactName: dto.contactName, contactPhone: dto.contactPhone, managerType: dto.managerType as WarehouseManagerType | undefined, partnerAccountId: dto.partnerAccountId === null ? undefined : dto.partnerAccountId ? BigInt(dto.partnerAccountId) : undefined, status: dto.status as WarehouseStatus | undefined, }); } @Delete(':id') @HqOperation({ action: HqOperationAction.WAREHOUSE_DELETE, refType: 'WAREHOUSE', refIdParam: 'id', }) remove(@Param('id') id: string) { return this.service.remove(BigInt(id)); } }