diff --git a/core/server/adapters/scheduling/index.js b/core/server/adapters/scheduling/index.js index 15152b9948..25baef8eda 100644 --- a/core/server/adapters/scheduling/index.js +++ b/core/server/adapters/scheduling/index.js @@ -1,4 +1,4 @@ -var postScheduling = require(__dirname + '/post-scheduling'); +const postScheduling = require(__dirname + '/post-scheduling'); /** * scheduling modules: diff --git a/core/server/adapters/scheduling/post-scheduling/index.js b/core/server/adapters/scheduling/post-scheduling/index.js index 24d7149164..15ba3db0b6 100644 --- a/core/server/adapters/scheduling/post-scheduling/index.js +++ b/core/server/adapters/scheduling/post-scheduling/index.js @@ -1,4 +1,4 @@ -var Promise = require('bluebird'), +const Promise = require('bluebird'), moment = require('moment'), localUtils = require('../utils'), common = require('../../../lib/common'), @@ -8,13 +8,11 @@ var Promise = require('bluebird'), _private = {}; _private.normalize = function normalize(options) { - var object = options.object, - apiUrl = options.apiUrl, - client = options.client; + const {object, apiUrl, client} = options; return { time: moment(object.get('published_at')).valueOf(), - url: urlService.utils.urlJoin(apiUrl, 'schedules', 'posts', object.get('id')) + '?client_id=' + client.get('slug') + '&client_secret=' + client.get('secret'), + url: `${urlService.utils.urlJoin(apiUrl, 'schedules', 'posts', object.get('id'))}?client_id=${client.get('slug')}&client_secret=${client.get('secret')}`, extra: { httpMethod: 'PUT', oldTime: object.updated('published_at') ? moment(object.updated('published_at')).valueOf() : null @@ -28,18 +26,17 @@ _private.loadClient = function loadClient() { _private.loadScheduledPosts = function () { return schedules.getScheduledPosts() - .then(function (result) { + .then((result) => { return result.posts || []; }); }; -exports.init = function init(options) { - var config = options || {}, - apiUrl = config.apiUrl, - adapter = null, +exports.init = function init(options = {}) { + const {apiUrl} = options; + let adapter = null, client = null; - if (!config) { + if (!Object.keys(options).length) { return Promise.reject(new common.errors.IncorrectUsageError({message: 'post-scheduling: no config was provided'})); } @@ -48,49 +45,49 @@ exports.init = function init(options) { } return _private.loadClient() - .then(function (_client) { + .then((_client) => { client = _client; - return localUtils.createAdapter(config); + return localUtils.createAdapter(options); }) - .then(function (_adapter) { + .then((_adapter) => { adapter = _adapter; if (!adapter.rescheduleOnBoot) { return []; } return _private.loadScheduledPosts(); }) - .then(function (scheduledPosts) { + .then((scheduledPosts) => { if (!scheduledPosts.length) { return; } - scheduledPosts.forEach(function (object) { - adapter.reschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client})); + scheduledPosts.forEach((object) => { + adapter.reschedule(_private.normalize({object, apiUrl, client})); }); }) - .then(function () { + .then(() => { adapter.run(); }) - .then(function () { + .then(() => { common.events.onMany([ 'post.scheduled', 'page.scheduled' - ], function (object) { - adapter.schedule(_private.normalize({object: object, apiUrl: apiUrl, client: client})); + ], (object) => { + adapter.schedule(_private.normalize({object, apiUrl, client})); }); common.events.onMany([ 'post.rescheduled', 'page.rescheduled' - ], function (object) { - adapter.reschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client})); + ], (object) => { + adapter.reschedule(_private.normalize({object, apiUrl, client})); }); common.events.onMany([ 'post.unscheduled', 'page.unscheduled' - ], function (object) { - adapter.unschedule(_private.normalize({object: object, apiUrl: apiUrl, client: client})); + ], (object) => { + adapter.unschedule(_private.normalize({object, apiUrl, client})); }); }); };