refactor: Refactor draft check
This commit is contained in:
committed by
Khaled Garbaya
parent
777a8d4007
commit
7b47485652
@@ -31,13 +31,13 @@ module.exports = async function attachEntryState (entry) {
|
|||||||
// If the field is an array of reference we need to check its item if they have pending changes
|
// If the field is an array of reference we need to check its item if they have pending changes
|
||||||
if (isArray(originalItem)) {
|
if (isArray(originalItem)) {
|
||||||
originalItem.forEach((innerItem, index) => {
|
originalItem.forEach((innerItem, index) => {
|
||||||
if (!isArray(innerItem) && isObject(innerItem) && (!innerItem.fields || originalItem[index].sys.updatedAt !== publishedItem[index].sys.updatedAt)) {
|
if (!isArray(innerItem) && isLinkDraft(innerItem, publishedItem[index])) {
|
||||||
entry.pendingChanges = true
|
entry.pendingChanges = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 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 (isObject(item[0]) && (!item[0].fields || !isDateEqual(item[0].sys.updatedAt !== item[1].sys.updatedAt))) {
|
} else if (isLinkDraft(item[0], item[1])) {
|
||||||
entry.pendingChanges = true
|
entry.pendingChanges = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -50,8 +50,13 @@ module.exports = async function attachEntryState (entry) {
|
|||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLinkDraft (previewLink, deliveryLink) {
|
||||||
|
return isObject(previewLink) && (!previewLink.fields || !isDateEqual(previewLink.sys.updatedAt !== previewLink.sys.updatedAt))
|
||||||
|
}
|
||||||
|
|
||||||
function isDateEqual (lhs, rhs) {
|
function isDateEqual (lhs, rhs) {
|
||||||
const lhsDate = new Date(lhs)
|
const lhsDate = new Date(lhs)
|
||||||
const rhsDate = new Date(rhs)
|
const rhsDate = new Date(rhs)
|
||||||
return lhsDate.setMilliseconds(0) === rhsDate.setMilliseconds(0)
|
return lhsDate.setMilliseconds(0) === rhsDate.setMilliseconds(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user