paradigm-core
Version:
Paradigm Core Modules
44 lines (32 loc) • 1.04 kB
JavaScript
const {Dispatcher: {registerHook}} = require('structure-core')
const createUpdateArticleQueue = require('../queues/create-update-article')
/**
* 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) {
try {
const applicationId = req.headers.applicationid
const organizationId = req.headers.organizationid
const document = response.pkg
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: ['publishById'],
}, onAfterPublish)
module.exports = onAfterPublish