From 8b1dd8d4e8c31c99e9b321684e6369e2a4c5eaa3 Mon Sep 17 00:00:00 2001 From: pvanwamelen Date: Sun, 30 Apr 2023 11:49:08 -0400 Subject: [PATCH 1/2] Persisting exploration --- api/abstractplay.ts | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/api/abstractplay.ts b/api/abstractplay.ts index 95c84e5..7a8e075 100644 --- a/api/abstractplay.ts +++ b/api/abstractplay.ts @@ -199,6 +199,10 @@ module.exports.authQuery = async (event: { body: { query: any; pars: any; }; cog return await submitMove(event.cognitoPoolClaims.sub, pars); case "submit_comment": return await submitComment(event.cognitoPoolClaims.sub, pars); + case "save_exploration": + return await saveExploration(event.cognitoPoolClaims.sub, pars); + case "get_exploration": + return await getExploration(event.cognitoPoolClaims.sub, pars); case "get_game": return await game(event.cognitoPoolClaims.sub, pars); case "update_game_settings": @@ -2108,6 +2112,58 @@ async function submitComment(userid: string, pars: { id: string; comment: string } } +async function saveExploration(userid: string, pars: { game: string; move: number; tree: any; }) { + await ddbDocClient.send(new PutCommand({ + TableName: process.env.ABSTRACT_PLAY_TABLE, + Item: { + "pk": "GAMEEXPLORATION#" + pars.game, + "sk": userid + "#" + pars.move, + "user": userid, + "game": pars.game, + "move": pars.move, + "tree": pars.tree + } + })); +} + +async function getExploration(userid: string, pars: { game: string; move: number }) { + let work: Promise[] = []; + try { + work.push(ddbDocClient.send( + new GetCommand({ + TableName: process.env.ABSTRACT_PLAY_TABLE, + Key: { + "pk": "GAMEEXPLORATION#" + pars.game, + "sk": userid + "#" + pars.move + }, + }) + )); + + if (pars.move > 1) { + work.push(ddbDocClient.send( + new GetCommand({ + TableName: process.env.ABSTRACT_PLAY_TABLE, + Key: { + "pk": "GAMEEXPLORATION#" + pars.game, + "sk": userid + "#" + (pars.move - 2) + }, + }) + )); + } + } + catch (error) { + logGetItemError(error); + return formatReturnError(`Unable to get exploration data for game ${pars.game} from table ${process.env.ABSTRACT_PLAY_TABLE}`); + } + let data = await Promise.all(work); + let trees = data.map((d: any) => d.Item); + return { + statusCode: 200, + body: JSON.stringify(trees), + headers + }; +} + async function updateMetaGameCounts(userId: string) { // Make sure people aren't getting clever try { From d6c91c7a72c29d6ce1bd66e76cd56e0e74e43159 Mon Sep 17 00:00:00 2001 From: pvanwamelen Date: Sun, 30 Apr 2023 15:26:14 -0400 Subject: [PATCH 2/2] Update to gameslib-0.6.5 --- README.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d268d4c..23d6993 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ After the pool is created copy the arn to serverless.yml for the authQuery funct ## Deployment Running -```npm run full-deploy-dev``` +```npm run full-dev``` and -```npm run full-deploy-prod``` +```npm run full-prod``` for the first time will create the DynamoDB and also the lambdas with the back end functionality (it is completely specified in serverless.yml). On subsequent runs it will just update the lambdas (and the DynamoDB is case you made changes). But don't run this before doing ```npm install```. sls needs to deploy the node_modules folder and unless that has the correct packages stuff don't work. If you are using PowerShell as your Terminal in VSCode, you might need to run `Remove-Item alias:sls` before `sls` will work. By default it is an alias for the `Select-String` PowerShell cmdlet. Or just use `serverless` instead of `sls`. diff --git a/package.json b/package.json index 2967e61..4cd75fc 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ }, "homepage": "https://github.com/AbstractPlay/node-backend#readme", "dependencies": { - "@abstractplay/gameslib": "file:../gameslib/abstractplay-gameslib-0.6.0.tgz", + "@abstractplay/gameslib": "file:../gameslib/abstractplay-gameslib-0.6.5.tgz", "@aws-sdk/client-dynamodb": "^3.321.1", "@aws-sdk/client-ses": "^3.321.1", "@aws-sdk/lib-dynamodb": "^3.321.1",