UNPKG

paradigm-core

Version:
48 lines (34 loc) 1.13 kB
const {Dispatcher: {registerHook}} = require('structure-core') const createUpdateArticleQueue = require('../queues/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 published = ['published', 'scheduled'].indexOf(document.status) > -1 if (published) { createUpdateArticleQueue.add({ organizationId, applicationId, documentId: document.id }) } } catch(e) { req.logger.error('After Publish Hook Error', e) } return response } registerHook({ when: 'after', serviceName: 'documents', actionNames: ['create'], }, onAfterPublish)