feat(entry-states): display entity state for editors
This commit is contained in:
25
lib/entry-state.js
Normal file
25
lib/entry-state.js
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user