import { Body, Controller, Get, Param, Patch, Post, Query } from '@nestjs/common'; import { BrandsService } from './brands.service'; import { AuthType } from '../common/decorators/auth.decorators'; import { CreateBrandDto, UpdateBrandDto } from './dto/brand.dto'; import { IsArray, IsString } from 'class-validator'; class SetBrandsBody { @IsArray() @IsString({ each: true }) brandIds!: string[]; } @Controller() export class BrandsController { constructor(private readonly brandsService: BrandsService) {} @AuthType('admin') @Get('admin/brands') list(@Query('activeOnly') activeOnly?: string) { return this.brandsService.list(activeOnly === 'true'); } @AuthType('admin') @Post('admin/brands') create(@Body() dto: CreateBrandDto) { return this.brandsService.create(dto); } @AuthType('admin') @Patch('admin/brands/:id') update(@Param('id') id: string, @Body() dto: UpdateBrandDto) { return this.brandsService.update(id, dto); } @AuthType('admin') @Get('admin/customers/:customerId/brands') customerBrands(@Param('customerId') customerId: string) { return this.brandsService.listCustomerBrands(customerId); } @AuthType('admin') @Post('admin/customers/:customerId/brands') setCustomerBrands( @Param('customerId') customerId: string, @Body() body: SetBrandsBody, ) { return this.brandsService.setCustomerBrands(customerId, body.brandIds ?? []); } }