/** * @copyright 2026 NHCarrigan * @license Naomi's Public License * @author Naomi Carrigan */ import { Art, CreateArtDto, UpdateArtDto } from "@library/shared-types"; import { prisma } from "../lib/prisma"; export class ArtService { private prisma = prisma; constructor() {} /** * Get all art pieces. */ async getAllArt(): Promise { const artPieces = await this.prisma.art.findMany({ orderBy: { createdAt: "desc" }, }); return artPieces.map((art) => ({ ...art, description: art.description || undefined, tags: art.tags ?? [], links: art.links ?? [], dateAdded: art.dateAdded, createdAt: art.createdAt, updatedAt: art.updatedAt, })); } /** * Get art by ID. */ async getArtById(id: string): Promise { const art = await this.prisma.art.findUnique({ where: { id }, }); if (!art) return null; return { ...art, description: art.description || undefined, tags: art.tags ?? [], links: art.links ?? [], dateAdded: art.dateAdded, createdAt: art.createdAt, updatedAt: art.updatedAt, }; } /** * Create new art piece. */ async createArt(data: CreateArtDto): Promise { const art = await this.prisma.art.create({ data, }); return { ...art, description: art.description || undefined, tags: art.tags ?? [], links: art.links ?? [], dateAdded: art.dateAdded, createdAt: art.createdAt, updatedAt: art.updatedAt, }; } /** * Update art by ID. */ async updateArt(id: string, data: UpdateArtDto): Promise { const art = await this.prisma.art.update({ where: { id }, data, }); return { ...art, description: art.description || undefined, tags: art.tags ?? [], links: art.links ?? [], dateAdded: art.dateAdded, createdAt: art.createdAt, updatedAt: art.updatedAt, }; } /** * Delete art by ID. */ async deleteArt(id: string): Promise { await this.prisma.art.delete({ where: { id }, }); } }