Files
drop/server/api/v1/client/collection/[id]/entry.post.ts
2025-08-10 15:51:10 +10:00

28 lines
759 B
TypeScript

import { type } from "arktype";
import { throwingArktype } from "~/server/arktype";
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
import userLibraryManager from "~/server/internal/userlibrary";
const AddEntry = type({
id: "string",
}).configure(throwingArktype);
/**
* Add entry to collection by game ID
* @param id Collection ID
*/
export default defineClientEventHandler(async (h3, { fetchUser, body }) => {
const user = await fetchUser();
const id = getRouterParam(h3, "id");
if (!id)
throw createError({
statusCode: 400,
statusMessage: "ID required in route params",
});
const gameId = body.id;
return await userLibraryManager.collectionAdd(gameId, id, user.id);
}, AddEntry);