apps/recallassess/recallassess-api/src/api/client/testimonial/testimonial.service.ts
Methods |
|
constructor(prisma: BNestPrismaService)
|
||||||
|
Parameters :
|
| Async getPublishedTestimonials |
getPublishedTestimonials()
|
|
Returns :
Promise<CLTestimonialDto[]>
|
| Private mapThemeColor | ||||||
mapThemeColor(color: TestimonialThemeColor)
|
||||||
|
Parameters :
Returns :
string
|
| Private mapToDto | ||||||
mapToDto(testimonial: TestimonialWithCourse)
|
||||||
|
Parameters :
Returns :
CLTestimonialDto
|
import { BNestPrismaService } from "@bish-nest/core/services";
import { Injectable } from "@nestjs/common";
import { Course, Testimonial, TestimonialThemeColor } from "@prisma/client";
import { CLTestimonialDto } from "./dto";
type TestimonialWithCourse = Testimonial & {
course: Pick<Course, "id" | "title"> | null;
};
@Injectable()
export class CLTestimonialService {
constructor(private prisma: BNestPrismaService) {}
async getPublishedTestimonials(): Promise<CLTestimonialDto[]> {
const testimonials = await this.prisma.client.testimonial.findMany({
where: {
is_published: true,
},
include: {
course: {
select: {
id: true,
title: true,
},
},
},
orderBy: [{ sort_order: "asc" }, { created_at: "desc" }],
});
return testimonials.map((testimonial) => this.mapToDto(testimonial));
}
private mapToDto(testimonial: TestimonialWithCourse): CLTestimonialDto {
return {
id: testimonial.id,
participant_name: testimonial.participant_name,
role_title: testimonial.role_title ?? null,
organization: testimonial.organization ?? null,
course_id: testimonial.course?.id ?? null,
course_title: testimonial.course?.title ?? "",
quote: testimonial.quote,
rating: testimonial.rating,
theme_color: this.mapThemeColor(testimonial.theme_color),
is_featured: testimonial.is_featured,
sort_order: testimonial.sort_order,
};
}
private mapThemeColor(color: TestimonialThemeColor): string {
switch (color) {
case "BLUE":
return "blue";
case "GREEN":
return "green";
case "ORANGE":
default:
return "orange";
}
}
}