Add new file box API
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-02-04 09:19:04 -06:00
parent a59255a39b
commit 1545505c22
4 changed files with 326 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
const { Model } = require('flitter-orm')
const uuid = require('uuid').v4
const { ObjectId } = require('mongodb')
class FileBoxModel extends Model {
static get schema() {
return {
UUID: { type: String, default: uuid },
name: String,
pageId: String,
parentUUID: String,
rootUUID: String,
fileIds: [String],
active: { type: Boolean, default: true },
}
}
async parent() {
return this.constructor.findOne({
UUID: this.parentUUID,
active: true,
})
}
async root() {
return this.constructor.findOne({
UUID: this.rootUUID,
active: true,
})
}
async files() {
const File = this.models.get('upload::File')
return await File.find({
_id: {
$in: this.fileIds.map(x => ObjectId(x)),
}
})
}
async to_api() {
return {
UUID: this.UUID,
name: this.name,
pageId: this.pageId,
parentUUID: this.parentUUID,
rootUUID: this.rootUUID,
fileIds: this.fileIds || [],
}
}
}
module.exports = exports = FileBoxModel