80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Patch,
|
|
Body,
|
|
Query,
|
|
Param,
|
|
NotFoundException,
|
|
HttpStatus,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { Prisma } from '@prisma/client';
|
|
import { ProductsService } from './products.service';
|
|
import { GetProductsDto } from './dto/get-products.dto';
|
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import { RolesGuard } from '../common/guards/roles.guard';
|
|
import { Roles } from '../common/decorators/roles.decorator';
|
|
|
|
@ApiTags('Products - مدیریت محصولات دارویی')
|
|
@Controller('products')
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: 'خطای داخلی سرور',
|
|
})
|
|
export class ProductsController {
|
|
constructor(private readonly productsService: ProductsService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'لیست و فیلتر محصولات' })
|
|
findAll(@Query() query: GetProductsDto) {
|
|
return this.productsService.findAll(query);
|
|
}
|
|
|
|
@Get('filters')
|
|
@ApiOperation({
|
|
summary: 'دریافت فیلترهای فعال محصولات (دسته، علائم، نوع پت)',
|
|
})
|
|
getActiveFilters() {
|
|
return this.productsService.getActiveFilters();
|
|
}
|
|
|
|
@Get('navigation-filters')
|
|
@ApiOperation({
|
|
summary: 'دریافت فیلترها و راهکارهای ناوبری (دسته با علائم مربوطه)',
|
|
})
|
|
getNavigationFilters() {
|
|
return this.productsService.getNavigationFilters();
|
|
}
|
|
|
|
@Get(':id/dosage-config')
|
|
@ApiOperation({ summary: 'دریافت پیکربندی دوز مصرف محصول' })
|
|
getDosageConfig(@Param('id') id: string) {
|
|
return this.productsService.getDosageConfig(id);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles('Admin')
|
|
@Patch(':id/dosage-config')
|
|
@ApiOperation({
|
|
summary: 'ویرایش پیکربندی دوز مصرف محصول (نیازمند دسترسی ادمین)',
|
|
})
|
|
updateDosageConfig(
|
|
@Param('id') id: string,
|
|
@Body() body: Prisma.InputJsonValue,
|
|
) {
|
|
return this.productsService.updateDosageConfig(id, body);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'دریافت اطلاعات محصول با شناسه یکتا (ID)' })
|
|
async findOne(@Param('id') id: string) {
|
|
const product = await this.productsService.findOne(id);
|
|
if (!product) {
|
|
throw new NotFoundException('محصول یافت نشد');
|
|
}
|
|
return product;
|
|
}
|
|
}
|