50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { UserRole } from '@prisma/client';
|
|
import { Roles } from '../auth/decorators/roles.decorator';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import { RolesGuard } from '../auth/guards/roles.guard';
|
|
import { CreateProductDto } from './dto/create-product.dto';
|
|
import { UpdateProductDto } from './dto/update-product.dto';
|
|
import { ProductsService } from './products.service';
|
|
|
|
@Controller('products')
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles(UserRole.Admin, UserRole.superAdmin)
|
|
export class ProductsController {
|
|
constructor(private readonly products: ProductsService) {}
|
|
|
|
@Get()
|
|
list() {
|
|
return this.products.list();
|
|
}
|
|
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string) {
|
|
return this.products.findOne(id);
|
|
}
|
|
|
|
@Post()
|
|
create(@Body() dto: CreateProductDto) {
|
|
return this.products.create(dto);
|
|
}
|
|
|
|
@Patch(':id')
|
|
update(@Param('id') id: string, @Body() dto: UpdateProductDto) {
|
|
return this.products.update(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
remove(@Param('id') id: string) {
|
|
return this.products.remove(id);
|
|
}
|
|
}
|