Skip to content

Commit

Permalink
Fixes message structure from sqs
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanwrightAND committed Apr 24, 2024
1 parent a3a4377 commit aed3d43
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,18 @@ const updateElasticIndex = async (contentfulEntry, action) => {
};

export const handler = async (message) => {
console.log(message);
const contentfulEntryId = message.contentfulEntryId;
console.log(`contentful entry ID: ${message.contentfulEntryId}`);
console.log(`action: ${message.type}`);
for (record of messages.Records) {
console.log('Message Recieved: ', message);
if (!record.body || !record.body.contentfulEntryId || !record.body.type)
throw new Error(`Invalid Message: ${record.body}`);

const grant = await getGrantById(contentfulEntryId);
await updateElasticIndex(grant, message.type);
const contentfulEntryId = record.body.contentfulEntryId;
console.log(`contentful entry ID: ${record.body.contentfulEntryId}`);
console.log(`action: ${message.type}`);

return { statusCode: 200 };
const grant = await getGrantById(contentfulEntryId);
await updateElasticIndex(grant, message.type);

return { statusCode: 200 };
}
};

0 comments on commit aed3d43

Please sign in to comment.