feat: add art component

This commit is contained in:
2026-02-04 13:40:52 -08:00
parent d338c8b52f
commit cbd6499079
12 changed files with 1162 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
/**
* @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<Art[]> {
const artPieces = await this.prisma.art.findMany({
orderBy: { createdAt: "desc" },
});
return artPieces.map((art) => ({
...art,
description: art.description || undefined,
dateAdded: art.dateAdded,
createdAt: art.createdAt,
updatedAt: art.updatedAt,
}));
}
/**
* Get art by ID.
*/
async getArtById(id: string): Promise<Art | null> {
const art = await this.prisma.art.findUnique({
where: { id },
});
if (!art) return null;
return {
...art,
description: art.description || undefined,
dateAdded: art.dateAdded,
createdAt: art.createdAt,
updatedAt: art.updatedAt,
};
}
/**
* Create new art piece.
*/
async createArt(data: CreateArtDto): Promise<Art> {
const art = await this.prisma.art.create({
data,
});
return {
...art,
description: art.description || undefined,
dateAdded: art.dateAdded,
createdAt: art.createdAt,
updatedAt: art.updatedAt,
};
}
/**
* Update art by ID.
*/
async updateArt(id: string, data: UpdateArtDto): Promise<Art> {
const art = await this.prisma.art.update({
where: { id },
data,
});
return {
...art,
description: art.description || undefined,
dateAdded: art.dateAdded,
createdAt: art.createdAt,
updatedAt: art.updatedAt,
};
}
/**
* Delete art by ID.
*/
async deleteArt(id: string): Promise<void> {
await this.prisma.art.delete({
where: { id },
});
}
}