Files
canina/backend/src/ingredients/ingredients.service.ts
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation.
- Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings.
- Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors.
- Fixed unmount lifecycle guards, promise error handling, and component edge cases.
2026-10-13 16:01:00 +00:00

55 lines
1.5 KiB
TypeScript

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 } });
}
}