feat: add manga and shows collections

This commit is contained in:
2026-02-04 15:41:23 -08:00
parent e5b15e02de
commit 11be34cd21
21 changed files with 2518 additions and 24 deletions
+99
View File
@@ -0,0 +1,99 @@
/**
* @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,
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,
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,
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,
createdAt: show.createdAt,
updatedAt: show.updatedAt,
};
}
async deleteShow(id: string): Promise<void> {
await this.prisma.show.delete({
where: { id },
});
}
}