fix: Fix Mario

This commit is contained in:
Khaled Garbaya
2017-12-14 13:55:51 +01:00
committed by Khaled Garbaya
parent 1ef4d1c51a
commit e772281fca
2 changed files with 7 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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))