46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
import { Prisma } from '@prisma/client';
|
|
|
|
@Injectable()
|
|
export class SmartAdvisorService {
|
|
constructor(private prisma: PrismaService) {}
|
|
|
|
async findAll() {
|
|
return this.prisma.smartAdvisorRule.findMany({
|
|
include: { product: true },
|
|
});
|
|
}
|
|
|
|
async create(data: Prisma.SmartAdvisorRuleCreateInput) {
|
|
return this.prisma.smartAdvisorRule.create({
|
|
data,
|
|
include: { product: true },
|
|
});
|
|
}
|
|
|
|
async update(id: string, data: Prisma.SmartAdvisorRuleUpdateInput) {
|
|
const rule = await this.prisma.smartAdvisorRule.findUnique({
|
|
where: { id },
|
|
});
|
|
if (!rule) {
|
|
throw new NotFoundException(`SmartAdvisorRule with ID ${id} not found`);
|
|
}
|
|
return this.prisma.smartAdvisorRule.update({
|
|
where: { id },
|
|
data,
|
|
include: { product: true },
|
|
});
|
|
}
|
|
|
|
async remove(id: string) {
|
|
const rule = await this.prisma.smartAdvisorRule.findUnique({
|
|
where: { id },
|
|
});
|
|
if (!rule) {
|
|
throw new NotFoundException(`SmartAdvisorRule with ID ${id} not found`);
|
|
}
|
|
return this.prisma.smartAdvisorRule.delete({ where: { id } });
|
|
}
|
|
}
|