feat: initial prototype works

I can log in and create a book! Woo!
This commit is contained in:
2026-02-04 12:17:05 -08:00
parent e167a17bd9
commit b6d66d34cb
44 changed files with 3695 additions and 493 deletions
+106
View File
@@ -0,0 +1,106 @@
/**
* @copyright 2026 NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Game, GameStatus, CreateGameDto, UpdateGameDto } from "@library/shared-types";
import { prisma } from "../lib/prisma";
export class GameService {
private prisma = prisma;
constructor() {}
/**
* Get all games.
*/
async getAllGames(): Promise<Game[]> {
const games = await this.prisma.game.findMany({
orderBy: { updatedAt: "desc" },
});
return games.map((game) => ({
...game,
status: game.status.toLowerCase() as GameStatus,
dateAdded: game.dateAdded,
dateCompleted: game.dateCompleted || undefined,
createdAt: game.createdAt,
updatedAt: game.updatedAt,
}));
}
/**
* Get game by ID.
*/
async getGameById(id: string): Promise<Game | null> {
const game = await this.prisma.game.findUnique({
where: { id },
});
if (!game) return null;
return {
...game,
status: game.status.toLowerCase() as GameStatus,
dateAdded: game.dateAdded,
dateCompleted: game.dateCompleted || undefined,
createdAt: game.createdAt,
updatedAt: game.updatedAt,
};
}
/**
* Create new game.
*/
async createGame(data: CreateGameDto): Promise<Game> {
const game = await this.prisma.game.create({
data: {
...data,
status: data.status.toUpperCase() as any,
},
});
return {
...game,
status: game.status.toLowerCase() as GameStatus,
dateAdded: game.dateAdded,
dateCompleted: game.dateCompleted || undefined,
createdAt: game.createdAt,
updatedAt: game.updatedAt,
};
}
/**
* Update game by ID.
*/
async updateGame(id: string, data: UpdateGameDto): Promise<Game> {
const updateData = { ...data };
if (updateData.status) {
updateData.status = updateData.status.toUpperCase() as any;
}
const game = await this.prisma.game.update({
where: { id },
data: updateData,
});
return {
...game,
status: game.status.toLowerCase() as GameStatus,
dateAdded: game.dateAdded,
dateCompleted: game.dateCompleted || undefined,
createdAt: game.createdAt,
updatedAt: game.updatedAt,
};
}
/**
* Delete game by ID.
*/
async deleteGame(id: string): Promise<void> {
await this.prisma.game.delete({
where: { id },
});
}
}