Add version tracking for page nodes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-11-02 12:31:05 -06:00
parent 6469beb341
commit 40eb3bb1f2
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
4 changed files with 16 additions and 15 deletions

View File

@ -272,7 +272,7 @@ class OfflineController extends Controller {
existing_node.UpdatedAt = new Date(rec.UpdatedAt) existing_node.UpdatedAt = new Date(rec.UpdatedAt)
existing_node.UpdateUserId = req.user.id existing_node.UpdateUserId = req.user.id
await existing_node.save() await existing_node.version_save('Updated from offline sync', req.user)
uuid_mapping[rec.UUID] = existing_node.UUID uuid_mapping[rec.UUID] = existing_node.UUID
} }
} else if ( !existing_node && online_page && !rec.deleted ) { } else if ( !existing_node && online_page && !rec.deleted ) {

View File

@ -119,7 +119,7 @@ class Page extends Controller {
assoc_nodes[node.UUID].update_from_raw(node) assoc_nodes[node.UUID].update_from_raw(node)
assoc_nodes[node.UUID].UpdatedAt = new Date assoc_nodes[node.UUID].UpdatedAt = new Date
assoc_nodes[node.UUID].UpdateUserId = req.user._id assoc_nodes[node.UUID].UpdateUserId = req.user._id
assoc_nodes[node.UUID].save() await assoc_nodes[node.UUID].version_save(`Updated in page`, req.user.id)
return res.api(assoc_nodes[node.UUID]) return res.api(assoc_nodes[node.UUID])
} else { } else {
const node_obj = new Node({ const node_obj = new Node({
@ -137,7 +137,7 @@ class Page extends Controller {
} }
} }
await node_obj.save() await node_obj.version_save(`Added to page "${page.Name}"`)
page.NodeIds.push(node_obj.UUID); page.NodeIds.push(node_obj.UUID);
await page.version_save(`Added ${node_obj.Type.split('_')[0]} node to page`, req.user.id); await page.version_save(`Added ${node_obj.Type.split('_')[0]} node to page`, req.user.id);
@ -183,7 +183,6 @@ class Page extends Controller {
CreatedUserId: req.user._id, CreatedUserId: req.user._id,
UpdateUserId: req.user._id, UpdateUserId: req.user._id,
}) })
await node_obj.save()
updated_nodes.push(node_obj) updated_nodes.push(node_obj)
} }
@ -193,7 +192,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.save() await node.version_save(`Bulk updated 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
}) })
@ -249,7 +248,7 @@ class Page extends Controller {
UpdateUserId: req.user.id UpdateUserId: req.user.id
}) })
await starter_node.save() await starter_node.version_save(`Added to page "${new_page.Name}"`, req.user.id)
new_page.NodeIds.push(starter_node.UUID) new_page.NodeIds.push(starter_node.UUID)
await new_page.version_save('Added paragraph node to page', req.user.id) await new_page.version_save('Added paragraph node to page', req.user.id)
} }
@ -308,7 +307,7 @@ class Page extends Controller {
UpdateUserId: req.user.id UpdateUserId: req.user.id
}) })
await starter_node.save() await starter_node.version_save(`Added to page "${new_page.Name}"`, req.user.id)
new_page.NodeIds.push(starter_node.UUID) new_page.NodeIds.push(starter_node.UUID)
await new_page.version_save('Added paragraph node to page', req.user.id) await new_page.version_save('Added paragraph node to page', req.user.id)
} }

View File

@ -17,17 +17,18 @@ class VersionedModel extends Model {
} }
async new_version(message = undefined, user_id = undefined) { async new_version(message = undefined, user_id = undefined) {
const version_data = await this.cast_to_version_data()
version_data.version_UUID = uuid()
version_data.version_message = message
if ( !this.version_num ) this.version_num = 1 if ( !this.version_num ) this.version_num = 1
if ( !this.version_archive ) this.version_archive = [] if ( !this.version_archive ) this.version_archive = []
this.version_num += 1 this.version_num += 1
this.version_archive.push(version_data)
this.version_create_date = new Date() this.version_create_date = new Date()
this.version_user_id = user_id this.version_user_id = user_id
const version_data = await this.cast_to_version_data()
version_data.version_UUID = uuid()
version_data.version_message = message
this.version_archive.push(version_data)
} }
async cast_to_version_data() { async cast_to_version_data() {

View File

@ -1,12 +1,12 @@
const Model = require("flitter-orm/src/model/Model"); const VersionedModel = require('../VersionedModel')
const uuid = require('uuid/v4'); const uuid = require('uuid/v4')
/* /*
* Node Model * Node Model
* ------------------------------------------------------------- * -------------------------------------------------------------
* Put some description here! * Put some description here!
*/ */
class Node extends Model { class Node extends VersionedModel {
static get services() { static get services() {
return [...super.services, 'models'] return [...super.services, 'models']
} }
@ -14,6 +14,7 @@ class Node extends Model {
static get schema() { static get schema() {
// Return a flitter-orm schema here. // Return a flitter-orm schema here.
return { return {
...super.schema,
UUID: { type: String, default: () => uuid() }, UUID: { type: String, default: () => uuid() },
Type: String, Type: String,
Value: { Value: {