2021-05-24 15:00:59 +04:00
|
|
|
const models = require('../../../models');
|
2021-10-01 05:38:13 -04:00
|
|
|
const tpl = require('@tryghost/tpl');
|
2021-05-24 15:00:59 +04:00
|
|
|
const errors = require('@tryghost/errors');
|
|
|
|
|
2021-10-01 05:38:13 -04:00
|
|
|
const messages = {
|
|
|
|
resourceNotFound: '{resource} not found.'
|
|
|
|
};
|
|
|
|
|
2021-05-24 15:00:59 +04:00
|
|
|
/**
|
|
|
|
* @description Load the internal scheduler integration
|
|
|
|
*
|
|
|
|
* @return {Promise}
|
|
|
|
*/
|
|
|
|
const getSchedulerIntegration = function () {
|
|
|
|
return models.Integration.findOne({slug: 'ghost-scheduler'}, {withRelated: 'api_keys'})
|
|
|
|
.then((integration) => {
|
|
|
|
if (!integration) {
|
|
|
|
throw new errors.NotFoundError({
|
2021-10-01 05:38:13 -04:00
|
|
|
message: tpl(messages.resourceNotFound, {resource: 'Integration'})
|
2021-05-24 15:00:59 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return integration.toJSON();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = getSchedulerIntegration;
|