2020-08-13 02:49:02 +00:00
|
|
|
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 ) {
|
2020-12-05 02:40:27 +00:00
|
|
|
this.error(`Unable to find announcement with ID: ${announcement_id}`)
|
2020-08-13 02:49:02 +00:00
|
|
|
throw new Error('Unable to find announcement with that ID.')
|
|
|
|
}
|
|
|
|
|
|
|
|
await announcement.populate()
|
2020-12-05 02:40:27 +00:00
|
|
|
this.success('Populated announcements.')
|
2020-08-13 02:49:02 +00:00
|
|
|
} catch (e) {
|
2020-12-05 02:40:27 +00:00
|
|
|
this.error(e)
|
|
|
|
throw e
|
2020-08-13 02:49:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = PopulateAnnouncementJob
|