I have a lambda function written in node, and I am trying to get data for a particular workout session.
The url looks something like this
workout/{workoutId}/sessions/{sessionId}
I know I can do something like the following if I just wanted to the workoutId
module.exports.getWorkoutSession = (event, context, callback) => {
const { workoutId } = event.pathParameters;
const params = {
TableName: workoutTable,
Key: {
id: workoutId,
},
};
return db.get(params).promise().then(res => {
if(res.item) {callback(null, response(200, res.Item));} else {
callback(null, response(404, {error: "workoutId not found"}))
}
})
};
but how can I modify this function so I can get the sessionData for a particular workout?
sessionIdfrom the path parameters, or how to fetch session data from DynamoDB? The answer to the first question isevent.pathParameters.sessionId. The answer to the second question depends on how you're storing the data in DDB. Or do I misunderstand your question?