generated from nhcarrigan/template
108 lines
2.8 KiB
TypeScript
108 lines
2.8 KiB
TypeScript
/**
|
|
* @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<Show[]> {
|
|
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<Show | null> {
|
|
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<Show> {
|
|
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<Show> {
|
|
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<void> {
|
|
await this.prisma.show.delete({
|
|
where: { id },
|
|
});
|
|
}
|
|
}
|