File

apps/recallassess/recallassess-api/src/api/client/testimonial/testimonial.service.ts

Index

Methods

Constructor

constructor(prisma: BNestPrismaService)
Parameters :
Name Type Optional
prisma BNestPrismaService No

Methods

Async getPublishedTestimonials
getPublishedTestimonials()
Private mapThemeColor
mapThemeColor(color: TestimonialThemeColor)
Parameters :
Name Type Optional
color TestimonialThemeColor No
Returns : string
Private mapToDto
mapToDto(testimonial: TestimonialWithCourse)
Parameters :
Name Type Optional
testimonial TestimonialWithCourse No
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";
    }
  }
}

results matching ""

    No results matching ""