UNPKG

paradigm-facebook-ia

Version:
46 lines (34 loc) 1.06 kB
const {registerHook} = require('structure-dispatcher') const CreateUpdateArticleJob = require('../jobs/create-update-article') /** * Hook for creating/updating an facebook instant 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) { try { const applicationId = req.headers.applicationid const organizationId = req.headers.organizationid const document = response.pkg const job = new CreateUpdateArticleJob({ organizationId, applicationId, logger: req.logger }) job.queue({ documentId: document.id }) } catch(e) { req.logger.error('After Publish Hook Error', e) } return response } registerHook({ when: 'after', serviceName: 'documents', actionNames: ['publishById'], }, onAfterPublish)