Clean up page versioning logic to prevent duplicate versions
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-11-02 22:44:54 -06:00
parent c5be78d275
commit 5f5b750172
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -78,7 +78,7 @@ class Page extends Controller {
page.OrgUserId = req.user._id 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({}) 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.UpdatedAt = new Date
page.UpdateUserId = req.user._id 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) return res.api(page)
} }
@ -242,7 +246,7 @@ class Page extends Controller {
let delete_nodes = nodes let delete_nodes = nodes
for ( const node of updated_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 => { delete_nodes = delete_nodes.filter(n => {
return n.UUID !== node.UUID return n.UUID !== node.UUID
}) })
@ -253,7 +257,7 @@ class Page extends Controller {
} }
page.NodeIds = updated_nodes.map(x => x.UUID) 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) res.api(updated_nodes)
} }