cancel hook on certain events before calculating data

ensure all required fields are present and cancel when thats not the case
This commit is contained in:
Ulf Gebhardt 2022-02-14 16:39:19 +01:00
parent d433d7df9f
commit a62b7e0d28
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9

View File

@ -53,6 +53,18 @@ export const elopageWebhook = async (req: any, res: any): Promise<void> => {
membership,
} = req.body
// Do not process certain events
if (['lesson.viewed', 'lesson.completed', 'lesson.commented'].includes(event)) {
// eslint-disable-next-line no-console
console.log('User viewed, completed or commented - not saving hook')
return
}
if (!product || !publisher || !membership || !payer) {
// eslint-disable-next-line no-console
console.log('Elopage Hook: Not an event we can process')
return
}
loginElopageBuy.affiliateProgramId = parseInt(product.affiliate_program_id) || null
loginElopageBuy.publisherId = parseInt(publisher.id) || null
loginElopageBuy.orderId = parseInt(order_id) || null
@ -72,13 +84,6 @@ export const elopageWebhook = async (req: any, res: any): Promise<void> => {
const firstName = payer.first_name
const lastName = payer.last_name
// Do not process certain events
if (['lesson.viewed', 'lesson.completed', 'lesson.commented'].includes(loginElopageBuy.event)) {
// eslint-disable-next-line no-console
console.log('User viewed, completed or commented - not saving hook')
return
}
// Save the hook data
try {
await LoginElopageBuys.save(loginElopageBuy)