CoreID/app/jobs/PopulateAnnouncement.job.js
garrettmills 9b5216431d
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Make jobs use built-in job logging
2020-12-04 20:40:27 -06:00

31 lines
882 B
JavaScript

const { Job } = require('flitter-jobs')
class PopulateAnnouncementJob extends Job {
static get services() {
return [...super.services, 'models', 'output']
}
async execute(job) {
const { data } = job
const { announcement_id } = data
try {
const Announcement = this.models.get('system:Announcement')
const announcement = await Announcement.findById(announcement_id)
if ( !announcement ) {
this.error(`Unable to find announcement with ID: ${announcement_id}`)
throw new Error('Unable to find announcement with that ID.')
}
await announcement.populate()
this.success('Populated announcements.')
} catch (e) {
this.error(e)
throw e
}
}
}
module.exports = exports = PopulateAnnouncementJob