Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed May 1, 2023
2 parents cd013a3 + d6c91c7 commit af0cced
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
56 changes: 56 additions & 0 deletions api/abstractplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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<any>[] = [];
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 {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit af0cced

Please sign in to comment.