fix: Fix Mario

This commit is contained in:
Khaled Garbaya
2017-12-14 13:55:51 +01:00
parent fca21ba3f1
commit 4ceb2697fe
2 changed files with 7 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ module.exports = async function attachEntryState (entry) {
entry.pendingChanges = false entry.pendingChanges = false
if (!publishedEntry) { if (!publishedEntry) {
entry.draft = true 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 // 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) => { 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 // If the field is a single reference we just check if it has pending changes
} else if (isLinkDraft(item[0], item[1])) { } else if (isLinkDraft(item[0], item[1])) {
entry.pendingChanges = true entry.pendingChanges = true
return return entry
} }
}) })
// We check if the root element has pending changes // 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 entry.pendingChanges = true
} }
@@ -51,7 +51,10 @@ module.exports = async function attachEntryState (entry) {
} }
function isLinkDraft (previewLink, deliveryLink) { 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) { function isDateEqual (lhs, rhs) {

View File

@@ -29,7 +29,6 @@ module.exports.getCourses = async (request, response, next) => {
let courses = [] let courses = []
let categories = [] let categories = []
courses = await getCourses(response.locals.currentLocale.code, response.locals.currentApi.id) courses = await getCourses(response.locals.currentLocale.code, response.locals.currentApi.id)
// Attach entry state flags when using preview API // Attach entry state flags when using preview API
if (shouldAttachEntryState(response)) { if (shouldAttachEntryState(response)) {
courses = await Promise.all(courses.map(attachEntryState)) courses = await Promise.all(courses.map(attachEntryState))