Commit 2a54fab1 authored by Diego Iván's avatar Diego Iván
Browse files

agregando controlador para category

parent 3350b1bc
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
import { Controller, Get, Post, Body, Param, Delete, UseGuards } from '@nestjs/common';
import { CategoryService } from './category.service';
import { AuthAdminGuard } from 'src/auth/admin/authAdmin.guard';
import { Roles } from 'src/auth/role.decorator';
import { SUPERADMIN_ROLES } from 'src/shared/enum/admin-role.enum';
import { ApiBearerAuth, ApiBody, ApiTags } from '@nestjs/swagger';
import { CreateCategoryReqDto } from './dto/create-category-req.dto';
import { LANGUAGES } from 'src/shared/enum/languages.enum';

@Controller('category')
@ApiTags('Category')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) {}

  @UseGuards(AuthAdminGuard)
  @Roles(SUPERADMIN_ROLES)
  @ApiBearerAuth('jwt')
  @ApiBody({ type: CreateCategoryReqDto })
  @Post()
  create(@Body() createCategoryDto: CreateCategoryReqDto) {
    this.categoryService.create(createCategoryDto);
    return { message: 'Category created successfully' };
  }

  @Get(':lang')
  findAll(@Param('lang') lang: LANGUAGES) {
    return this.categoryService.findAll(lang);
  }

  // @Patch(':id')
  // update(@Param('id') id: string, @Body() updateCategoryDto: UpdateCategoryDto) {
  //   return this.categoryService.update(+id, updateCategoryDto);
  // }

  @UseGuards(AuthAdminGuard)
  @Roles(SUPERADMIN_ROLES)
  @ApiBearerAuth('jwt')
  @Delete(':id')
  remove(@Param('id') id: string) {
    this.categoryService.remove(+id);
    return { message: 'Category deleted successfully' };
  }
}