feat(backend): implement Phase A database models and controllers for cross-boundary dependencies
Deploy Canina / deploy (push) Failing after 28s

This commit is contained in:
parsa committed 2026-08-06 23:45:51 +03:30
1 parent 74fcaa6a4e
commit 1ae4c99ffc
26 files changed
+1205 -345

No files matched your search

@@ -0,0 +1,60 @@
import {
Controller,
Get,
Post,
Patch,
Delete,
Body,
Param,
UseGuards,
} from '@nestjs/common';
import { IngredientsService } from './ingredients.service';
import { ApiTags, ApiOperation, ApiBearerAuth } 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('Ingredients - دانشنامه ترکیبات و مواد موثره')
@Controller('ingredients')
export class IngredientsController {
constructor(private readonly ingredientsService: IngredientsService) {}
@Get()
@ApiOperation({ summary: 'دریافت لیست ترکیبات فعال' })
findAll() {
return this.ingredientsService.findAll();
}
@Get(':idOrSlug')
@ApiOperation({ summary: 'دریافت اطلاعات یک ترکیب بر اساس آیدی یا اسلاگ' })
findOne(@Param('idOrSlug') idOrSlug: string) {
return this.ingredientsService.findOne(idOrSlug);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Post()
@ApiOperation({ summary: 'ایجاد ترکیب جدید (نیازمند ادمین)' })
create(@Body() body: any) {
return this.ingredientsService.create(body);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Patch(':id')
@ApiOperation({ summary: 'ویرایش اطلاعات ترکیب (نیازمند ادمین)' })
update(@Param('id') id: string, @Body() body: any) {
return this.ingredientsService.update(id, body);
}
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('Admin')
@ApiBearerAuth()
@Delete(':id')
@ApiOperation({ summary: 'حذف ترکیب (نیازمند ادمین)' })
remove(@Param('id') id: string) {
return this.ingredientsService.remove(id);
}
}
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { IngredientsController } from './ingredients.controller';
import { IngredientsService } from './ingredients.service';
import { PrismaModule } from '../prisma/prisma.module';
@Module({
imports: [PrismaModule],
controllers: [IngredientsController],
providers: [IngredientsService],
exports: [IngredientsService],
})
export class IngredientsModule {}
@@ -0,0 +1,54 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { Prisma } from '@prisma/client';
@Injectable()
export class IngredientsService {
constructor(private prisma: PrismaService) {}
async findAll() {
return this.prisma.ingredient.findMany({
orderBy: { nameFa: 'asc' },
});
}
async findOne(idOrSlug: string) {
const isUuid =
/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(
idOrSlug,
);
const ingredient = await this.prisma.ingredient.findFirst({
where: isUuid ? { id: idOrSlug } : { slug: idOrSlug },
});
if (!ingredient) {
throw new NotFoundException(`Ingredient ${idOrSlug} not found`);
}
return ingredient;
}
async create(data: Prisma.IngredientCreateInput) {
return this.prisma.ingredient.create({
data,
});
}
async update(id: string, data: Prisma.IngredientUpdateInput) {
const item = await this.prisma.ingredient.findUnique({ where: { id } });
if (!item) {
throw new NotFoundException(`Ingredient with ID ${id} not found`);
}
return this.prisma.ingredient.update({
where: { id },
data,
});
}
async remove(id: string) {
const item = await this.prisma.ingredient.findUnique({ where: { id } });
if (!item) {
throw new NotFoundException(`Ingredient with ID ${id} not found`);
}
return this.prisma.ingredient.delete({ where: { id } });
}
}