diff --git a/ghost/api-framework/lib/headers.js b/ghost/api-framework/lib/headers.js index fa99a9eeab..bd552059e2 100644 --- a/ghost/api-framework/lib/headers.js +++ b/ghost/api-framework/lib/headers.js @@ -122,12 +122,8 @@ module.exports = { } } - const locationHeaderDisabled = apiConfigHeaders && apiConfigHeaders.location === false; - const hasFrameData = frame - && (frame.method === 'add') - && result[frame.docName] - && result[frame.docName][0] - && result[frame.docName][0].id; + const locationHeaderDisabled = apiConfigHeaders?.location === false; + const hasFrameData = frame?.method === 'add' && result[frame.docName]?.[0]?.id; if (!locationHeaderDisabled && hasFrameData) { const protocol = (frame.original.url.secure === false) ? 'http://' : 'https://'; diff --git a/ghost/api-framework/lib/http.js b/ghost/api-framework/lib/http.js index ddcf7d8405..72848e19a1 100644 --- a/ghost/api-framework/lib/http.js +++ b/ghost/api-framework/lib/http.js @@ -30,7 +30,7 @@ const http = (apiImpl) => { }; } - if (req.user && req.user.id) { + if (req.user?.id) { user = req.user.id; } diff --git a/ghost/api-framework/lib/serializers/handle.js b/ghost/api-framework/lib/serializers/handle.js index 84766a72ec..962f949799 100644 --- a/ghost/api-framework/lib/serializers/handle.js +++ b/ghost/api-framework/lib/serializers/handle.js @@ -68,10 +68,10 @@ module.exports.input = (apiConfig, apiSerializers, frame) => { }; const getBestMatchSerializer = function (apiSerializers, docName, method) { - if (apiSerializers[docName] && apiSerializers[docName][method]) { + if (apiSerializers[docName]?.[method]) { debug(`Calling ${docName}.${method}`); return apiSerializers[docName][method].bind(apiSerializers[docName]); - } else if (apiSerializers[docName] && apiSerializers[docName].all) { + } else if (apiSerializers[docName]?.all) { debug(`Calling ${docName}.all`); return apiSerializers[docName].all.bind(apiSerializers[docName]); } @@ -108,7 +108,7 @@ module.exports.output = (response = {}, apiConfig, apiSerializers, frame) => { // ##### API VERSION RESOURCE SERIALIZATION - if (apiSerializers.all && apiSerializers.all.before) { + if (apiSerializers.all?.before) { tasks.push(function allSerializeBefore() { return apiSerializers.all.before(response, apiConfig, frame); }); @@ -129,7 +129,7 @@ module.exports.output = (response = {}, apiConfig, apiSerializers, frame) => { }); } - if (apiSerializers.all && apiSerializers.all.after) { + if (apiSerializers.all?.after) { tasks.push(function allSerializeAfter() { return apiSerializers.all.after(apiConfig, frame); }); diff --git a/ghost/api-framework/lib/validators/input/all.js b/ghost/api-framework/lib/validators/input/all.js index f2769c0b3d..c6a8709408 100644 --- a/ghost/api-framework/lib/validators/input/all.js +++ b/ghost/api-framework/lib/validators/input/all.js @@ -53,7 +53,7 @@ const validate = (config, attrs) => { errors = errors.concat(validator.validate(value, key, GLOBAL_VALIDATORS[key])); } - if (config && config[key]) { + if (config?.[key]) { const allowedValues = Array.isArray(config[key]) ? config[key] : config[key].values; if (allowedValues) {