|
|
|
@ -10,26 +10,26 @@ export class ProductsController { |
|
|
|
|
const { name, description, price } = body; |
|
|
|
|
const product = await this.productsService.create(name, description, price); |
|
|
|
|
return { |
|
|
|
|
message: 'Product created successfully!', |
|
|
|
|
product |
|
|
|
|
message: "Product created successfully!", |
|
|
|
|
product, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
@Get() |
|
|
|
|
async findAll(@Query() query: { search?: string; priceMin?: number; priceMax?: number }){ |
|
|
|
|
async findAll(@Query() query: { search?: string; priceMin?: number; priceMax?: number }) { |
|
|
|
|
const { search, priceMin, priceMax } = query; |
|
|
|
|
return this.productsService.findAll(search, priceMin, priceMax); |
|
|
|
|
} |
|
|
|
|
@Get(':id') |
|
|
|
|
async findOne(@Param('id') id: string): Promise<Product> { |
|
|
|
|
@Get(":id") |
|
|
|
|
async findOne(@Param("id") id: string): Promise<Product> { |
|
|
|
|
return this.productsService.findOne(id); |
|
|
|
|
} |
|
|
|
|
@Put(':id') |
|
|
|
|
async update( |
|
|
|
|
@Param('id') id: string, |
|
|
|
|
@Body() body: { name?: string; description?: string; price?: number }, |
|
|
|
|
): Promise<Product> { |
|
|
|
|
@Put(":id") |
|
|
|
|
async update(@Param("id") id: string, @Body() body: { name?: string; description?: string; price?: number }): Promise<Product> { |
|
|
|
|
const { name, description, price } = body; |
|
|
|
|
return this.productsService.update(id, name, description, price); |
|
|
|
|
} |
|
|
|
|
@Delete(':id') |
|
|
|
|
async remove(@Param('id') id: string): Promise<{ message: string }> { |
|
|
|
|
return this.productsService.remove(id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|