Skip to content

Commit

Permalink
Notes feature ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Oct 5, 2023
1 parent 5079fca commit 6a4c3fe
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 @@ -3225,6 +3228,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) || (pars.note.length === 0) ) {
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 6a4c3fe

Please sign in to comment.