import { Controller } from "@nestjs/common" ; import { MessagePattern , EventPattern } from "@nestjs/microservices" ; import { ProductEntity } from "./product.entity" ; import { ProductService } from "./product.service" ; @ Controller ( "products" ) export class ProductController { constructor ( private readonly products ) { } @ MessagePattern ( "products" ) index ( data = undefined ) { return this . products . get ( data ) ; } @ MessagePattern ( "create-product" ) store ( data ) { return this . products . store ( data ) ; } @ MessagePattern ( "update-product" ) update ( { id , title , description , image , price , user_id } ) { return this . products . update ( id , { title , description , image , price } , user_id ) ; } @ MessagePattern ( "show-product" ) show ( id ) { return this . products . show ( id ) ; } @ MessagePattern ( "fetch-products-by-ids" ) fetchProductsByIds ( ids ) { return this . products . fetchProductsByIds ( ids ) ; } @ EventPattern ( "order_deleted" ) async handleOrderDeleted ( products ) { this . products . incrementProductsStock ( products ) ; } @ EventPattern ( "order_created" ) async handleOrderCreated ( products ) { this . products . decrementProductsStock ( products ) ; } @ MessagePattern ( "delete-product" ) destroy ( { id , user_id } ) { return this . products . destroy ( id , user_id ) ; } }