From 4ceb2697febd1f439da1fde21604ae8d9c7405cb Mon Sep 17 00:00:00 2001 From: Khaled Garbaya Date: Thu, 14 Dec 2017 13:55:51 +0100 Subject: [PATCH] fix: Fix Mario --- lib/entry-state.js | 11 +++++++---- routes/courses.js | 1 - 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/entry-state.js b/lib/entry-state.js index d8cf844..35f72bd 100644 --- a/lib/entry-state.js +++ b/lib/entry-state.js @@ -15,7 +15,7 @@ module.exports = async function attachEntryState (entry) { entry.pendingChanges = false if (!publishedEntry) { entry.draft = true - return + return entry } // We group fields of type link (i.e. Only objects/array) from the same entry in preview and delivery const entriesToCompare = Object.keys(entry.fields).map((key) => { @@ -39,11 +39,11 @@ module.exports = async function attachEntryState (entry) { // If the field is a single reference we just check if it has pending changes } else if (isLinkDraft(item[0], item[1])) { entry.pendingChanges = true - return + return entry } }) // We check if the root element has pending changes - if (entry && publishedEntry && (!isDateEqual(entry.sys.updatedAt !== publishedEntry.sys.updatedAt))) { + if (entry && publishedEntry && (entry.sys.updatedAt !== publishedEntry.sys.updatedAt)) { entry.pendingChanges = true } @@ -51,7 +51,10 @@ module.exports = async function attachEntryState (entry) { } function isLinkDraft (previewLink, deliveryLink) { - return isObject(previewLink) && (!previewLink.fields || !isDateEqual(previewLink.sys.updatedAt !== previewLink.sys.updatedAt)) + if (isObject(previewLink)) { + return !previewLink.fields || !isDateEqual(previewLink.sys.updatedAt, previewLink.sys.updatedAt) + } + return false } function isDateEqual (lhs, rhs) { diff --git a/routes/courses.js b/routes/courses.js index 37dd244..e66c6c0 100644 --- a/routes/courses.js +++ b/routes/courses.js @@ -29,7 +29,6 @@ module.exports.getCourses = async (request, response, next) => { let courses = [] let categories = [] courses = await getCourses(response.locals.currentLocale.code, response.locals.currentApi.id) - // Attach entry state flags when using preview API if (shouldAttachEntryState(response)) { courses = await Promise.all(courses.map(attachEntryState))