Clean up page versioning logic to prevent duplicate versions
This commit is contained in:
parent
c5be78d275
commit
5f5b750172
@ -78,7 +78,7 @@ class Page extends Controller {
|
||||
page.OrgUserId = req.user._id
|
||||
}
|
||||
|
||||
let save_message = 'Page contents saved'
|
||||
let save_message
|
||||
|
||||
if ( !req.body.Name ) return res.status(400).message('Missing required: Name').api({})
|
||||
|
||||
@ -113,7 +113,11 @@ class Page extends Controller {
|
||||
|
||||
page.UpdatedAt = new Date
|
||||
page.UpdateUserId = req.user._id
|
||||
await page.version_save(save_message, req.user.id)
|
||||
if ( save_message ) {
|
||||
await page.version_save(save_message, req.user.id)
|
||||
} else {
|
||||
await page.save()
|
||||
}
|
||||
return res.api(page)
|
||||
}
|
||||
|
||||
@ -242,7 +246,7 @@ class Page extends Controller {
|
||||
|
||||
let delete_nodes = nodes
|
||||
for ( const node of updated_nodes ) {
|
||||
await node.version_save(`Bulk updated in page "${page.Name}"`, req.user.id)
|
||||
await node.version_save(`Contents saved in page "${page.Name}"`, req.user.id)
|
||||
delete_nodes = delete_nodes.filter(n => {
|
||||
return n.UUID !== node.UUID
|
||||
})
|
||||
@ -253,7 +257,7 @@ class Page extends Controller {
|
||||
}
|
||||
|
||||
page.NodeIds = updated_nodes.map(x => x.UUID)
|
||||
await page.version_save('Bulk-updated nodes on page', req.user.id)
|
||||
await page.version_save('Saved page contents', req.user.id)
|
||||
res.api(updated_nodes)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user