58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import {
|
|||
|
|
Body,
|
||
|
|
Controller,
|
||
|
|
Get,
|
||
|
|
Param,
|
||
|
|
Patch,
|
||
|
|
Post,
|
||
|
|
Query,
|
||
|
|
} from '@nestjs/common';
|
||
|
|
import { CatalogsService } from './catalogs.service';
|
||
|
|
import { AuthType } from '../common/decorators/auth.decorators';
|
||
|
|
import {
|
||
|
|
CreateCatalogDto,
|
||
|
|
SetCatalogActiveDto,
|
||
|
|
UpdateCatalogDto,
|
||
|
|
} from './dto/catalog.dto';
|
||
|
|
|
||
|
|
@Controller('catalogs')
|
||
|
|
export class CatalogsController {
|
||
|
|
constructor(private readonly catalogsService: CatalogsService) {}
|
||
|
|
|
||
|
|
@AuthType('any')
|
||
|
|
@Get()
|
||
|
|
findAll(
|
||
|
|
@Query('companyId') companyId?: string,
|
||
|
|
@Query('activeOnly') activeOnly?: string,
|
||
|
|
) {
|
||
|
|
return this.catalogsService.findAll(
|
||
|
|
companyId,
|
||
|
|
activeOnly === 'true' || activeOnly === '1',
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@AuthType('any')
|
||
|
|
@Get(':id')
|
||
|
|
findOne(@Param('id') id: string) {
|
||
|
|
return this.catalogsService.findOne(id);
|
||
|
|
}
|
||
|
|
|
||
|
|
@AuthType('admin')
|
||
|
|
@Post()
|
||
|
|
create(@Body() dto: CreateCatalogDto) {
|
||
|
|
return this.catalogsService.create(dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@AuthType('admin')
|
||
|
|
@Patch(':id')
|
||
|
|
update(@Param('id') id: string, @Body() dto: UpdateCatalogDto) {
|
||
|
|
return this.catalogsService.update(id, dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@AuthType('admin')
|
||
|
|
@Patch(':id/active')
|
||
|
|
setActive(@Param('id') id: string, @Body() dto: SetCatalogActiveDto) {
|
||
|
|
return this.catalogsService.setActive(id, dto.isActive);
|
||
|
|
}
|
||
|
|
}
|