61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Put,
|
|
Param,
|
|
Delete,
|
|
ParseUUIDPipe,
|
|
HttpStatus, Query,
|
|
} from '@nestjs/common';
|
|
import { ProductService } from './product.service';
|
|
import { ProductCategoriesService } from './product-categories.service';
|
|
import { CreateCategoriesProductDto } from './dto/categories/create-categories-product.dto';
|
|
|
|
@Controller({
|
|
path: 'product',
|
|
version: '1',
|
|
})
|
|
export class ProductController {
|
|
constructor(
|
|
private readonly productService: ProductService,
|
|
private readonly productCategoriesService: ProductCategoriesService,
|
|
) {}
|
|
|
|
@Post('categories')
|
|
async createCategories(
|
|
@Body() createCategoriesProductDto: CreateCategoriesProductDto,
|
|
) {
|
|
return {
|
|
data: await this.productCategoriesService.create(
|
|
createCategoriesProductDto,
|
|
),
|
|
statusCode: HttpStatus.CREATED,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get()
|
|
async findAll(@Query('page') page: number) {
|
|
const [data, count] = await this.productService.findAll(page);
|
|
|
|
return {
|
|
data,
|
|
count,
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
@Get(':id')
|
|
async findOne(@Param('id', ParseUUIDPipe) id: string) {
|
|
return {
|
|
data: await this.productService.findOne(id),
|
|
statusCode: HttpStatus.OK,
|
|
message: 'success',
|
|
};
|
|
}
|
|
|
|
}
|