in event-driven-developers-tale/functions/createVacationRequest/app.js [13:53]
submitVacationRequest: async (ctx) => {
// PERSIST DATA
var params = {
TableName: table,
Item: ctx.arguments.input
}
const data = await DBclient.put(params).promise()
if (data.$response.error) {
console.error("Unable to add item. Error JSON:", JSON.stringify(data.$response.error, null, 2));
}
else {
console.log("Successfully added item to database. " + JSON.stringify(ctx.arguments.input))
// SEND EVENT AFTER SUCCESSFULLY PERSISTING DATA
params = {
"Entries": [
{
"Detail": JSON.stringify(ctx.arguments.input),
"DetailType": "VacationRequestSubmited",
"EventBusName": eventBusName,
"Source": "VacationTrackerApp",
"Time": new Date()
}
]
}
var result = await EVBclient.putEvents(params).promise()
if (result.$response.error) {
console.error("Unable to send event. Error JSON:", JSON.stringify(result.$response.error, null, 2));
}
else {
console.log("Successfully sent event. " + JSON.stringify(result.$response.data))
return ctx.arguments.input;
}
}
}