Track code snippet versions & include in the node version data
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user