diff --git a/app/controllers/api/v1/File.controller.js b/app/controllers/api/v1/File.controller.js index d66251d..798e32f 100644 --- a/app/controllers/api/v1/File.controller.js +++ b/app/controllers/api/v1/File.controller.js @@ -39,7 +39,7 @@ class File extends Controller { } } - await group.save() + await group.version_save(`Added to page "${page.Name}"`, req.user.id) req.user.allow(`files:${group.UUID}`) await req.user.save() @@ -85,11 +85,12 @@ class File extends Controller { if ( !group ) return res.status(404).message('Invalid file group.').api({}) // if ( !group.accessible_by(req.user) ) return req.security.deny() + let file_name = '' if ( req.uploads.uploaded_file ) { group.FileIds.push(req.uploads.uploaded_file.id) } - await group.save() + await group.version_save(`Added file${file_name ? ' "'+file_name+'"' : ''}`, req.user.id) return res.redirect(req.body.redirectTo ? req.body.redirectTo : '/') } diff --git a/app/models/api/FileGroup.model.js b/app/models/api/FileGroup.model.js index c89db76..36d5182 100644 --- a/app/models/api/FileGroup.model.js +++ b/app/models/api/FileGroup.model.js @@ -1,4 +1,4 @@ -const Model = require('flitter-orm/src/model/Model') +const VersionedModel = require('../VersionedModel') const uuid = require('uuid/v4') /* @@ -6,10 +6,11 @@ const uuid = require('uuid/v4') * ------------------------------------------------------------- * Put some description here! */ -class FileGroup extends Model { +class FileGroup extends VersionedModel { static get schema() { // Return a flitter-orm schema here. return { + ...super.schema, NodeId: String, PageId: String, FileIds: [String], diff --git a/app/models/api/Node.model.js b/app/models/api/Node.model.js index f306bde..d315b87 100644 --- a/app/models/api/Node.model.js +++ b/app/models/api/Node.model.js @@ -69,6 +69,12 @@ class Node extends VersionedModel { if ( code ) { data.associated_type_version_num = code.version_num } + } else if ( this.Type === 'file_ref' && this.Value?.Value ) { + const FileGroup = this.models.get('api:FileGroup') + const group = await FileGroup.findOne({ UUID: this.Value?.Value }) + if ( group ) { + data.associated_type_version_num = group.version_num + } } return data