Files
canina/backend/src/testimonials/testimonials.service.ts
T

47 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 TestimonialsService {
constructor(private prisma: PrismaService) {}
async findAll() {
return this.prisma.testimonial.findMany({
orderBy: { order: 'asc' },
});
}
async findHomepage() {
return this.prisma.testimonial.findMany({
where: { isActive: true, showOnHome: true },
orderBy: { order: 'asc' },
});
}
async create(data: Prisma.TestimonialCreateInput) {
return this.prisma.testimonial.create({
data,
});
}
async update(id: string, data: Prisma.TestimonialUpdateInput) {
const item = await this.prisma.testimonial.findUnique({ where: { id } });
if (!item) {
throw new NotFoundException(`Testimonial with ID ${id} not found`);
}
return this.prisma.testimonial.update({
where: { id },
data,
});
}
async remove(id: string) {
const item = await this.prisma.testimonial.findUnique({ where: { id } });
if (!item) {
throw new NotFoundException(`Testimonial with ID ${id} not found`);
}
return this.prisma.testimonial.delete({ where: { id } });
}
}