category
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { productService } from '../providers/product.service';
|
||||
import { ProductService } from '../providers/product.service';
|
||||
import { CreateproductDto } from '../dto/create-product.dto';
|
||||
import { UpdateproductDto } from '../dto/update-product.dto';
|
||||
import { FindproductsDto } from '../dto/find-products.dto';
|
||||
@@ -17,11 +17,17 @@ import { UserId } from 'src/common/decorators';
|
||||
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
||||
import { Permission } from 'src/common/enums/permission.enum';
|
||||
import { Permissions } from 'src/common/decorators/permissions.decorator';
|
||||
import { CreateCategoryDto } from '../dto/create-category.dto';
|
||||
import { CategoryService } from '../providers/category.service';
|
||||
import { FindCategoriesDto } from '../dto/find-categories.dto';
|
||||
|
||||
@ApiTags('products')
|
||||
@Controller()
|
||||
export class productController {
|
||||
constructor(private readonly productsService: productService) { }
|
||||
constructor(
|
||||
private readonly productService: ProductService,
|
||||
private readonly categoryService: CategoryService,
|
||||
) { }
|
||||
|
||||
|
||||
// @Get('public/products/:productId')
|
||||
@@ -43,7 +49,7 @@ export class productController {
|
||||
@ApiOperation({ summary: 'Create a new product' })
|
||||
@ApiBody({ type: CreateproductDto })
|
||||
create(@Body() createproductDto: CreateproductDto) {
|
||||
return this.productsService.create(createproductDto);
|
||||
return this.productService.create(createproductDto);
|
||||
}
|
||||
|
||||
@Get('admin/products')
|
||||
@@ -59,7 +65,7 @@ export class productController {
|
||||
@ApiQuery({ name: 'categoryId', required: false, type: String })
|
||||
@ApiQuery({ name: 'isActive', required: false, type: Boolean })
|
||||
async findAll(@Query() dto: FindproductsDto) {
|
||||
const result = await this.productsService.findAll(dto);
|
||||
const result = await this.productService.findAll(dto);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -70,7 +76,7 @@ export class productController {
|
||||
@ApiOperation({ summary: 'Get a product by id' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
findById(@Param('id') id: string,) {
|
||||
return this.productsService.findById(id);
|
||||
return this.productService.findById(id);
|
||||
}
|
||||
|
||||
@Patch('admin/products/:id')
|
||||
@@ -81,7 +87,7 @@ export class productController {
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
@ApiBody({ type: UpdateproductDto })
|
||||
update(@Param('id') id: string, @Body() updateproductDto: UpdateproductDto) {
|
||||
return this.productsService.update(id, updateproductDto);
|
||||
return this.productService.update(id, updateproductDto);
|
||||
}
|
||||
|
||||
@Delete('admin/products/:id')
|
||||
@@ -91,6 +97,33 @@ export class productController {
|
||||
@ApiOperation({ summary: 'Delete (soft) a product' })
|
||||
@ApiParam({ name: 'id', required: true })
|
||||
remove(@Param('id') id: string,) {
|
||||
return this.productsService.remove(id);
|
||||
return this.productService.remove(id);
|
||||
}
|
||||
|
||||
/**CATEGORY */
|
||||
@Post('admin/product/category')
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_productS)
|
||||
@ApiOperation({ summary: 'Create a new category' })
|
||||
@ApiBody({ type: CreateCategoryDto })
|
||||
createCategory(@Body() createproductDto: CreateCategoryDto) {
|
||||
return this.categoryService.create(createproductDto);
|
||||
}
|
||||
|
||||
@Get('admin/products/category')
|
||||
// @UseGuards(AdminAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@Permissions(Permission.MANAGE_productS)
|
||||
@ApiOperation({ summary: 'Get a paginated list of Categories' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'limit', required: false, type: Number })
|
||||
@ApiQuery({ name: 'search', required: false, type: String })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'order', required: false, enum: ['asc', 'desc'] })
|
||||
@ApiQuery({ name: 'isActive', required: false, type: Boolean })
|
||||
async findAllCategories(@Query() dto: FindCategoriesDto) {
|
||||
const result = await this.categoryService.findAll(dto);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user