Files
tehran_tala/apps/api/src/modules/catalog/catalog.service.ts
T
2026-09-09 06:46:27 +03:30

29 lines
812 B
TypeScript

import { Injectable, NotFoundException } from '@nestjs/common';
import { PrismaService } from '../../prisma/prisma.service';
@Injectable()
export class CatalogService {
constructor(private readonly prisma: PrismaService) {}
listProducts() {
return this.prisma.product.findMany({
where: { isActive: true },
include: {
variants: true,
images: true,
category: true,
brand: true,
collections: { include: { collection: true } },
},
});
}
async getVariantOrThrow(variantId: string) {
const variant = await this.prisma.productVariant.findUnique({ where: { id: variantId } });
if (!variant || !variant.isActive) {
throw new NotFoundException(`Product variant ${variantId} not found or inactive`);
}
return variant;
}
}