Skip to content

Commit

Permalink
Function for player-specific, game-specific notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Oct 5, 2023
1 parent 43ec4e9 commit 067eb79
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions api/abstractplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ type Game = {
lastMoveTime: number;
clockHard: boolean;
toMove: string | boolean[];
note?: string;
seen?: number;
winner?: number[];
numMoves?: number;
Expand Down Expand Up @@ -251,6 +252,8 @@ module.exports.authQuery = async (event: { body: { query: any; pars: any; }; cog
return await submitMove(event.cognitoPoolClaims.sub, pars);
case "invoke_pie":
return await invokePie(event.cognitoPoolClaims.sub, pars);
case "update_note":
return await updateNote(event.cognitoPoolClaims.sub, pars);
case "set_lastSeen":
return await setLastSeen(event.cognitoPoolClaims.sub, pars);
case "submit_comment":
Expand Down Expand Up @@ -3219,6 +3222,56 @@ async function invokePie(userid: string, pars: {id: string, metaGame: string, cb
}
}

async function updateNote(userId: string, pars: {gameId: string; note?: string;}) {
// get USER rec
let user: FullUser|undefined;
try {
const data = await ddbDocClient.send(
new GetCommand({
TableName: process.env.ABSTRACT_PLAY_TABLE,
Key: {
"pk": "USER",
"sk": userId
},
})
);
if (data.Item !== undefined) {
user = data.Item as FullUser;
}
} catch (err) {
logGetItemError(err);
return formatReturnError(`Unable to updateNote ${userId}`);
}
if (user !== undefined) {
// find matching game
const game = user.games.find(g => g.id === pars.gameId);
if (game !== undefined) {
// set note
if ( (pars.note === undefined) || (pars.note === null) ) {
delete game.note;
} else {
game.note = pars.note.substring(0, 250);
}
console.log(`Setting note for user ${userId}, game ${game.id}.`);
// save USER rec
await ddbDocClient.send(new PutCommand({
TableName: process.env.ABSTRACT_PLAY_TABLE,
Item: user
}));
return {
statusCode: 200,
body: "",
headers
};
}
}
return {
statusCode: 406,
body: "",
headers
};
}

async function setLastSeen(userId: string, pars: {gameId: string; interval?: number;}) {
// get USER rec
let user: FullUser|undefined;
Expand Down

0 comments on commit 067eb79

Please sign in to comment.