feat(entry-states): display entity state for editors

This commit is contained in:
Benedikt Rötsch
2017-10-24 15:12:26 +02:00
parent 63ff3e0426
commit fd52efd625
8 changed files with 77 additions and 4 deletions

25
lib/entry-state.js Normal file
View File

@@ -0,0 +1,25 @@
const { getEntry } = require('./../services/contentful')
async function getPublishedEntry (entry) {
try {
return await getEntry(entry.sys.id)
} catch (err) {
return null
}
}
module.exports = async function attachEntryState (entry) {
const publishedEntry = await getPublishedEntry(entry)
entry.draft = false
entry.pendingChanges = false
if (!publishedEntry) {
entry.draft = true
}
if (entry && publishedEntry && (entry.sys.updatedAt !== publishedEntry.sys.updatedAt)) {
entry.pendingChanges = true
}
return entry
}