Implemented the ability to add/remove games from collections.
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user