UNPKG

paradigm-core

Version:
36 lines (25 loc) 1.02 kB
const {Queue, ApplicationsPlugin: {ApplicationModel}} = require('structure-core') const AppleNewsArticleModel = require('../models/apple-news-article') class CreateUpdateArticleQueue extends Queue { constructor(options = {}) { super({label: 'apple-news--create-update-article'}) } async handler(job) { const applicationModel = new ApplicationModel({ organizationId: job.data.organizationId, logger: this.logger, }) const app = await applicationModel.getById(job.data.applicationId) if (!app.appleNewsChannelId || !app.appleNewsApiId || !app.appleNewsApiSecret) { this.logger.debug('No apple news config set on application') return } const appleNewsArticleModel = new AppleNewsArticleModel({ organizationId: job.data.organizationId, applicationId: job.data.applicationId, logger: this.logger }) await appleNewsArticleModel.createOrUpdateForDocument(job.data.documentId) } } module.exports = new CreateUpdateArticleQueue()