42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { Controller, Get, Post, Patch, Delete, Body, Param, UsePipes } from '@nestjs/common';
|
|
import { WishlistCategoriesService } from './categories.service';
|
|
import { CreateWishlistCategoryDto, UpdateWishlistCategoryDto } from './dto/category.dto';
|
|
import { ZodValidationPipe } from '../pipes/zod-validation.pipe';
|
|
import { CreateWishlistCategorySchema, UpdateWishlistCategorySchema } from './dto/category.dto';
|
|
|
|
@Controller('api/wishlist/categories')
|
|
export class WishlistCategoriesController {
|
|
constructor(private readonly categoriesService: WishlistCategoriesService) { }
|
|
|
|
@Get()
|
|
async findAll() {
|
|
return this.categoriesService.findAll();
|
|
}
|
|
|
|
@Get(':id')
|
|
async findOne(@Param('id') id: string) {
|
|
return this.categoriesService.findOne(id);
|
|
}
|
|
|
|
@Post()
|
|
@UsePipes(new ZodValidationPipe(CreateWishlistCategorySchema))
|
|
async create(@Body() dto: CreateWishlistCategoryDto) {
|
|
return this.categoriesService.create(dto);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@UsePipes(new ZodValidationPipe(UpdateWishlistCategorySchema))
|
|
async update(
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateWishlistCategoryDto
|
|
) {
|
|
return this.categoriesService.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
async delete(@Param('id') id: string) {
|
|
await this.categoriesService.delete(id);
|
|
return { message: 'Category deleted successfully' };
|
|
}
|
|
}
|