2019-08-09 17:11:24 +03:00
|
|
|
const models = require('../../models');
|
2021-09-03 20:53:33 +03:00
|
|
|
|
|
|
|
const postSchedulingService = require('../../services/posts/post-scheduling-service')('canary');
|
2019-08-09 17:11:24 +03:00
|
|
|
|
|
|
|
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'
|
|
|
|
},
|
2021-09-03 20:53:33 +03:00
|
|
|
async query(frame) {
|
2019-08-09 17:11:24 +03:00
|
|
|
const resourceType = frame.options.resource;
|
2020-10-08 12:25:27 +03:00
|
|
|
const options = {
|
|
|
|
status: 'scheduled',
|
|
|
|
id: frame.options.id,
|
|
|
|
context: {
|
|
|
|
internal: true
|
|
|
|
}
|
|
|
|
};
|
2019-08-09 17:11:24 +03:00
|
|
|
|
2021-09-03 20:53:33 +03:00
|
|
|
const {scheduledResource, preScheduledResource} = await postSchedulingService.publish(resourceType, frame.options.id, frame.data.force, options);
|
|
|
|
const cacheInvalidate = postSchedulingService.handleCacheInvalidation(scheduledResource, preScheduledResource);
|
|
|
|
this.headers.cacheInvalidate = cacheInvalidate;
|
2019-08-09 17:11:24 +03:00
|
|
|
|
2021-09-03 20:53:33 +03:00
|
|
|
const response = {};
|
|
|
|
response[resourceType] = [scheduledResource];
|
|
|
|
return response;
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
2019-09-23 19:12:53 +03:00
|
|
|
const resourceModel = 'Post';
|
|
|
|
const resourceType = (frame.options.resource === 'post') ? 'post' : 'page';
|
2019-08-09 17:11:24 +03:00
|
|
|
const cleanOptions = {};
|
2019-09-23 19:12:53 +03:00
|
|
|
cleanOptions.filter = `status:scheduled+type:${resourceType}`;
|
|
|
|
cleanOptions.columns = ['id', 'published_at', 'created_at', 'type'];
|
2019-08-09 17:11:24 +03:00
|
|
|
|
|
|
|
return models[resourceModel].findAll(cleanOptions)
|
|
|
|
.then((result) => {
|
|
|
|
let response = {};
|
|
|
|
response[resourceType] = result;
|
|
|
|
return response;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|