const VersionedModel = require('../VersionedModel') const uuid = require('uuid/v4') /* * Node Model * ------------------------------------------------------------- * Put some description here! */ class Node extends VersionedModel { static get services() { return [...super.services, 'models'] } static get schema() { // Return a flitter-orm schema here. return { ...super.schema, UUID: { type: String, default: () => uuid() }, Type: String, Value: { Mode: {type: String, default: 'norm'}, Value: String, }, PageId: String, CreatedAt: { type: Date, default: () => new Date }, UpdatedAt: { type: Date, default: () => new Date }, CreatedUserId: String, UpdateUserId: String }; } // Static and instance methods can go here get page() { const Page = this.models.get('api:Page') return this.belongs_to_one(Page, "PageId", "UUID") } to_html() { switch(this.Type){ case 'paragraph': return '

' + this.Value.Value + '

' case 'header1': return '

' + this.Value.Value + '

' case 'header2': return '

' + this.Value.Value + '

' case 'header3': return '

' + this.Value.Value + '

' case 'header4': return '

' + this.Value.Value + '

' case 'block_code': return '
' + this.Value.Value + '
' case 'click_link': return '' + this.Value.Value + '' } } update_from_raw(data) { 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;