UNPKG

paradigm-channels

Version:
51 lines (37 loc) 1.23 kB
const {registerHook} = require('structure-dispatcher') const {ApplicationModel} = require('structure-applications') const jobPurgeChannel = require('../jobs/purge') /** * Hook for purging channel data. Simply queues a purge job. * * @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 */ async function purgeChannel(req, response) { try { const applicationId = req.headers.applicationid const organizationId = req.headers.organizationid const applicationModel = new ApplicationModel({ logger: req.logger, organizationId }) const application = await applicationModel.getById(applicationId) const channel = response.pkg jobPurgeChannel.queue({ applicationId, channelSlug: channel.slug, logger: req.logger, hostname: application.host }) } catch(e) { req.logger.error('Failed to purge channel', e) } return response } registerHook({ when: 'after', serviceName: 'channels', actionNames: ['create', 'updateById'], }, purgeChannel)