114 lines
4.1 KiB
TypeScript
114 lines
4.1 KiB
TypeScript
import { Controller, Get, Query, Param, NotFoundException, HttpStatus } from '@nestjs/common';
|
|
import { ProductsService } from './products.service';
|
|
import { GetProductsDto } from './dto/get-products.dto';
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiOkResponse, ApiNotFoundResponse } from '@nestjs/swagger';
|
|
|
|
@ApiTags('Products - مدیریت محصولات دارویی')
|
|
@Controller('products')
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: 'خطای داخلی سرور',
|
|
schema: {
|
|
example: {
|
|
success: false,
|
|
message: 'خطای داخلی سرور',
|
|
code: 'SERVER_ERROR',
|
|
details: {}
|
|
}
|
|
}
|
|
})
|
|
export class ProductsController {
|
|
constructor(private readonly productsService: ProductsService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'لیست و فیلتر محصولات' })
|
|
@ApiOkResponse({
|
|
description: 'لیست محصولات متناسب با فیلترها (دسته، پت و جستجو)',
|
|
schema: {
|
|
example: {
|
|
data: [
|
|
{
|
|
id: 'a1b2c3d4-1234-5678-abcd-ef1234567890',
|
|
artNo: 'canhydrox-gag',
|
|
name: 'Canhydrox GAG (کنهیدروکس)',
|
|
scientificTagline: 'برای تقویت مفاصل و استخوانها',
|
|
description: 'کنهیدروکس محصولی بینظیر برای مفاصل و سیستم حرکتی سگها...',
|
|
shortDescription: 'تقویت مفاصل و غضروفها',
|
|
category: 'سیستم حرکتی و مفاصل',
|
|
categorySlug: 'joints',
|
|
priceValue: '1750000.00',
|
|
priceDisplay: '۱,۷۵۰,۰۰۰ تومان',
|
|
unit: 'عدد قرص',
|
|
packageSize: '120.00',
|
|
dosageLogic: 'یک قرص به ازای هر ۱۰ کیلوگرم وزن بدن سگ',
|
|
suitableFor: 'سگ',
|
|
imageUrl: 'https://example.com/canhydrox.png',
|
|
createdAt: '2026-05-26T18:10:00.000Z',
|
|
ingredients: [],
|
|
symptoms: []
|
|
}
|
|
],
|
|
meta: {
|
|
total: 1,
|
|
page: 1,
|
|
lastPage: 1,
|
|
limit: 10
|
|
}
|
|
}
|
|
}
|
|
})
|
|
findAll(@Query() query: GetProductsDto) {
|
|
return this.productsService.findAll(query);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'دریافت اطلاعات محصول با شناسه یکتا (ID)' })
|
|
@ApiOkResponse({
|
|
description: 'اطلاعات کامل محصول شامل مواد تشکیلدهنده و علائم مرتبط',
|
|
schema: {
|
|
example: {
|
|
id: 'a1b2c3d4-1234-5678-abcd-ef1234567890',
|
|
artNo: 'canhydrox-gag',
|
|
name: 'Canhydrox GAG (کنهیدروکس)',
|
|
scientificTagline: 'برای تقویت مفاصل و استخوانها',
|
|
description: 'کنهیدروکس محصولی بینظیر برای مفاصل...',
|
|
shortDescription: 'تقویت مفاصل و غضروفها',
|
|
category: 'سیستم حرکتی و مفاصل',
|
|
categorySlug: 'joints',
|
|
priceValue: '1750000.00',
|
|
priceDisplay: '۱,۷۵۰,۰۰۰ تومان',
|
|
unit: 'عدد قرص',
|
|
packageSize: '120.00',
|
|
dosageLogic: 'یک قرص به ازای هر ۱۰ کیلوگرم وزن بدن سگ',
|
|
suitableFor: 'سگ',
|
|
imageUrl: 'https://example.com/canhydrox.png',
|
|
createdAt: '2026-05-26T18:10:00.000Z',
|
|
ingredients: [
|
|
{ productId: 'a1b2c3d4-1234-5678-abcd-ef1234567890', ingredient: 'صدف لبسبز' }
|
|
],
|
|
symptoms: [
|
|
{ productId: 'a1b2c3d4-1234-5678-abcd-ef1234567890', symptom: 'لنگیدن' }
|
|
]
|
|
}
|
|
}
|
|
})
|
|
@ApiNotFoundResponse({
|
|
description: 'محصول با شناسه ارسال شده پیدا نشد',
|
|
schema: {
|
|
example: {
|
|
success: false,
|
|
message: 'Product with ID a1b2c3d4-1234-5678-abcd-ef1234567890 not found',
|
|
code: 'NOT_FOUND',
|
|
details: {}
|
|
}
|
|
}
|
|
})
|
|
async findOne(@Param('id') id: string) {
|
|
const product = await this.productsService.findOne(id);
|
|
if (!product) {
|
|
throw new NotFoundException(`Product with ID ${id} not found`);
|
|
}
|
|
return product;
|
|
}
|
|
}
|