UNPKG

prism-ad-campaigns

Version:
53 lines (39 loc) 1.18 kB
const {registerHook} = require('structure-dispatcher') const CreateAdCampaignJob = require('../jobs/create-ad-campaign') /** * Hook for creating/updating an apple news article when a document has been * published * * @param {Object} req - express request object * @param {Object} response - the response from the dispatcher, which cointains * the data from the previous controller method. * @returns {Object} response - the response to be returned to the user */ function onAfterPublish(req, response) { return new Promise(async (resolve) => { const applicationId = req.headers.applicationid const organizationId = req.headers.organizationid const document = response.pkg const logger = req.logger || console try { const job = new CreateAdCampaignJob({ organizationId, applicationId, logger }) job.queue({ organizationId, applicationId, document, }) } catch(e) { logger.error('After Publish Hook Error', e) } resolve(response) }) } registerHook({ when: 'after', serviceName: 'documents', actionNames: ['publishById'], }, onAfterPublish)