/** * @copyright 2026 NHCarrigan * @license Naomi's Public License * @author Naomi Carrigan */ import { Show, ShowStatus, ShowType, CreateShowDto, UpdateShowDto } from "@library/shared-types"; import { prisma } from "../lib/prisma"; export class ShowService { private prisma = prisma; constructor() {} async getAllShows(): Promise { const shows = await this.prisma.show.findMany({ orderBy: { updatedAt: "desc" }, }); return shows.map((show) => ({ ...show, type: show.type as unknown as ShowType, status: show.status as unknown as ShowStatus, dateAdded: show.dateAdded, dateCompleted: show.dateCompleted || undefined, tags: show.tags ?? [], links: show.links ?? [], createdAt: show.createdAt, updatedAt: show.updatedAt, })); } async getShowById(id: string): Promise { const show = await this.prisma.show.findUnique({ where: { id }, }); if (!show) return null; return { ...show, type: show.type as unknown as ShowType, status: show.status as unknown as ShowStatus, dateAdded: show.dateAdded, dateCompleted: show.dateCompleted || undefined, tags: show.tags ?? [], links: show.links ?? [], createdAt: show.createdAt, updatedAt: show.updatedAt, }; } async createShow(data: CreateShowDto): Promise { const show = await this.prisma.show.create({ data: { ...data, type: data.type.toUpperCase() as any, status: data.status.toUpperCase() as any, }, }); return { ...show, type: show.type as unknown as ShowType, status: show.status as unknown as ShowStatus, dateAdded: show.dateAdded, dateCompleted: show.dateCompleted || undefined, tags: show.tags ?? [], links: show.links ?? [], createdAt: show.createdAt, updatedAt: show.updatedAt, }; } async updateShow(id: string, data: UpdateShowDto): Promise { const updateData = { ...data }; if (updateData.type) { updateData.type = updateData.type.toUpperCase() as any; } if (updateData.status) { updateData.status = updateData.status.toUpperCase() as any; } const show = await this.prisma.show.update({ where: { id }, data: updateData, }); return { ...show, type: show.type as unknown as ShowType, status: show.status as unknown as ShowStatus, dateAdded: show.dateAdded, dateCompleted: show.dateCompleted || undefined, tags: show.tags ?? [], links: show.links ?? [], createdAt: show.createdAt, updatedAt: show.updatedAt, }; } async deleteShow(id: string): Promise { await this.prisma.show.delete({ where: { id }, }); } }