Async - AWS SDK for Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updatePlayCount(your_object) { | |
return new Promise((resolve, reject) => { | |
const LAST_PLAYED_TIME = Math.round(new Date() / 1000); | |
var params = { | |
TableName: "your_table", | |
Key: { | |
"cognitoid": your_object.userId, | |
"creationtime": your_object.creationtime | |
}, | |
UpdateExpression: "SET lastPlayed = :time ADD playedCount :val", | |
ExpressionAttributeValues:{ | |
":val": 1, | |
":time": LAST_PLAYED_TIME | |
} | |
}; | |
var documentClient = new AWS.DynamoDB.DocumentClient(); | |
documentClient.update(params, (err, data) => { | |
if (err) { | |
console.log("Error when updating DynamoDB"); | |
console.log(err); // an error occurred | |
console.log(JSON.stringify(params,null,2)); | |
reject(err); | |
} else { | |
// console.log(data); // successful response | |
resolve(data); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment