Implemented the ability to add/remove games from collections.

This commit is contained in:
jd
2026-02-21 17:27:46 +00:00
parent 59d2819750
commit afa1c13e13
5 changed files with 98 additions and 2 deletions

View File

@@ -1,8 +1,12 @@
import { orm } from '../orm/orm';
import { UnwrappedRequest } from '../utilities/guard';
import { CreatedResponse, ErrorResponse, OkResponse } from '../utilities/responseHelper';
import { CreateCollectionRequest, UpdateCollectionRequest } from '../utilities/requestModels';
import { CollectionId } from '../utilities/secureIds';
import {
GameToCollectionRequest,
CreateCollectionRequest,
UpdateCollectionRequest,
} from '../utilities/requestModels';
import { CollectionId, GameId } from '../utilities/secureIds';
async function create(request: UnwrappedRequest<CreateCollectionRequest>): Promise<Response> {
try {
@@ -47,10 +51,40 @@ async function drop(request: UnwrappedRequest): Promise<Response> {
}
}
async function addGame(request: UnwrappedRequest<GameToCollectionRequest>): Promise<Response> {
try {
return new OkResponse(
await orm.collections.addGame(
CollectionId.fromHash(request.params.id),
GameId.fromHash(request.body.gameId),
request.claims,
),
);
} catch (error: any) {
return new ErrorResponse(error as Error);
}
}
async function removeGame(request: UnwrappedRequest<GameToCollectionRequest>): Promise<Response> {
try {
return new OkResponse(
await orm.collections.removeGame(
CollectionId.fromHash(request.params.id),
GameId.fromHash(request.body.gameId),
request.claims,
),
);
} catch (error: any) {
return new ErrorResponse(error as Error);
}
}
export default {
create,
get,
list,
update,
drop,
addGame,
removeGame,
};