mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
db2ef7dbca
refs https://github.com/TryGhost/Team/issues/694 - The canary schedules controller was refactored to use newly introduced post-scheduling service in a previous commit. This is a follow up to match v2/v3 controllers as they had identical code to the canary one.
78 lines
2.4 KiB
JavaScript
78 lines
2.4 KiB
JavaScript
const models = require('../../models');
|
|
|
|
const postSchedulingService = require('../../services/posts/post-scheduling-service')('canary');
|
|
|
|
module.exports = {
|
|
docName: 'schedules',
|
|
publish: {
|
|
headers: {},
|
|
options: [
|
|
'id',
|
|
'resource'
|
|
],
|
|
data: [
|
|
'force'
|
|
],
|
|
validation: {
|
|
options: {
|
|
id: {
|
|
required: true
|
|
},
|
|
resource: {
|
|
required: true,
|
|
values: ['posts', 'pages']
|
|
}
|
|
}
|
|
},
|
|
permissions: {
|
|
docName: 'posts'
|
|
},
|
|
async query(frame) {
|
|
const resourceType = frame.options.resource;
|
|
const options = {
|
|
status: 'scheduled',
|
|
id: frame.options.id,
|
|
context: {
|
|
internal: true
|
|
}
|
|
};
|
|
|
|
const {scheduledResource, preScheduledResource} = await postSchedulingService.publish(resourceType, frame.options.id, frame.data.force, options);
|
|
const cacheInvalidate = postSchedulingService.handleCacheInvalidation(scheduledResource, preScheduledResource);
|
|
this.headers.cacheInvalidate = cacheInvalidate;
|
|
|
|
const response = {};
|
|
response[resourceType] = [scheduledResource];
|
|
return response;
|
|
}
|
|
},
|
|
|
|
getScheduled: {
|
|
// NOTE: this method is for internal use only by DefaultScheduler
|
|
// it is not exposed anywhere!
|
|
permissions: false,
|
|
validation: {
|
|
options: {
|
|
resource: {
|
|
required: true,
|
|
values: ['posts', 'pages']
|
|
}
|
|
}
|
|
},
|
|
query(frame) {
|
|
const resourceModel = 'Post';
|
|
const resourceType = (frame.options.resource === 'post') ? 'post' : 'page';
|
|
const cleanOptions = {};
|
|
cleanOptions.filter = `status:scheduled+type:${resourceType}`;
|
|
cleanOptions.columns = ['id', 'published_at', 'created_at', 'type'];
|
|
|
|
return models[resourceModel].findAll(cleanOptions)
|
|
.then((result) => {
|
|
let response = {};
|
|
response[resourceType] = result;
|
|
return response;
|
|
});
|
|
}
|
|
}
|
|
};
|