import { Body , Controller , Delete , Get , Param , Post , Put , UseGuards , } from '@nestjs/common' ; import { AuthGuard } from '@nestjs/passport' ; import { SellerGuard } from '../guards/seller.guard' ; import { Product } from '../types/product' ; import { User as UserDocument } from '../types/user' ; import { User } from '../utilities/user.decorator' ; import { CreateProductDTO , UpdateProductDTO } from './product.dto' ; import { ProductService } from './product.service' ; @ Controller ( 'product' ) export class ProductController { constructor ( private productService ) { } @ Get ( ) async listAll ( ) { return await this . productService . findAll ( ) ; } @ Get ( '/mine' ) @ UseGuards ( AuthGuard ( 'jwt' ) , SellerGuard ) async listMine ( @ User ( ) user ) { const { id } = user ; return await this . productService . findByOwner ( id ) ; } @ Get ( '/seller/:id' ) async listBySeller ( @ Param ( 'id' ) id ) { return await this . productService . findByOwner ( id ) ; } @ Post ( ) @ UseGuards ( AuthGuard ( 'jwt' ) , SellerGuard ) async create ( @ Body ( ) product , @ User ( ) user ) { return await this . productService . create ( product , user ) ; } @ Get ( ':id' ) async read ( @ Param ( 'id' ) id ) { return await this . productService . findById ( id ) ; } @ Put ( ':id' ) @ UseGuards ( AuthGuard ( 'jwt' ) , SellerGuard ) async update ( @ Param ( 'id' ) id , @ Body ( ) product , @ User ( ) user ) { const { id : userId } = user ; return await this . productService . update ( id , product , userId ) ; } @ Delete ( ':id' ) @ UseGuards ( AuthGuard ( 'jwt' ) , SellerGuard ) async delete ( @ Param ( 'id' ) id , @ User ( ) user ) { const { id : userId } = user ; return await this . productService . delete ( id , userId ) ; } }