Track code snippet versions & include in the node version data
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Garrett Mills 2020-11-02 12:47:34 -06:00
parent 3b9d8acccb
commit a584631b75
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 21 additions and 5 deletions

View File

@ -43,7 +43,7 @@ class FormCode extends Controller {
}
}
await code.save()
await code.version_save(`Added to page "${page.Name}"`, req.user.id)
return res.api(code)
}
@ -84,7 +84,7 @@ class FormCode extends Controller {
code.Language = req.body.Language
code.NodeId = node.UUID
code.PageId = page.UUID
await code.save()
await code.version_save(`Updated in page "${page.Name}"`, req.user.id)
return res.api(code)
}
@ -104,7 +104,7 @@ class FormCode extends Controller {
if ( !code ) return res.status(404).message('Unable to find code with that ID.').api({})
code.Active = false
await code.save()
await code.version_save(`Deleted`, req.user.id)
return res.api({})
}
}

View File

@ -1,4 +1,4 @@
const Model = require('flitter-orm/src/model/Model')
const VersionedModel = require('../VersionedModel')
const uuid = require('uuid/v4')
const ActiveScope = require('../scopes/Active.scope')
@ -7,10 +7,11 @@ const ActiveScope = require('../scopes/Active.scope')
* -------------------------------------------------------------
* Put some description here!
*/
class Codium extends Model {
class Codium extends VersionedModel {
static get schema() {
// Return a flitter-orm schema here.
return {
...super.schema,
Language: {type: String, default: 'javascript'},
NodeId: String,
PageId: String,

View File

@ -58,6 +58,21 @@ class Node extends VersionedModel {
if ( data.Type ) this.Type = data.Type
if ( data.Value ) this.Value = data.Value
}
async cast_to_version_data() {
const data = await super.cast_to_version_data()
// If supported, fetch the current version of the node item
if ( this.Type === 'code_ref' && this.Value?.Value ) {
const Codium = this.models.get('api:Codium')
const code = await Codium.findOne({ UUID: this.Value?.Value, Active: true })
if ( code ) {
data.associated_type_version_num = code.version_num
}
}
return data
}
}
module.exports = exports = Node;