UNPKG

paradigm-core

Version:
42 lines (31 loc) 1.03 kB
const {Dispatcher: {registerHook}} = require('structure-core') const deleteArticleQueue = require('../queues/delete-article') /** * Hook for deleting facebook instant articles when a document is unpublished * or deleted * * @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 onAfterUnpublishDelete(req, response) { try { const applicationId = req.headers.applicationid const organizationId = req.headers.organizationid const document = response.pkg deleteArticleQueue.add({ organizationId, applicationId, documentId: document.id }) } catch(e) { req.logger.error('After Unpublish Or Delete Hook Error', e) } return response } registerHook({ when: 'after', serviceName: 'documents', actionNames: ['deleteById', 'unpublishById'], }, onAfterUnpublishDelete)