Improve file box api - add delete endpoints, categories

This commit is contained in:
2021-02-04 12:57:11 -06:00
parent 1545505c22
commit 83b81ed84f
3 changed files with 81 additions and 3 deletions

View File

@@ -3,6 +3,10 @@ const uuid = require('uuid').v4
const { ObjectId } = require('mongodb')
class FileBoxModel extends Model {
static get services() {
return [...super.services, 'models']
}
static get schema() {
return {
UUID: { type: String, default: uuid },
@@ -29,6 +33,13 @@ class FileBoxModel extends Model {
})
}
async children() {
return this.constructor.find({
parentUUID: this.UUID,
active: true,
})
}
async files() {
const File = this.models.get('upload::File')
return await File.find({
@@ -40,8 +51,10 @@ class FileBoxModel extends Model {
async to_api() {
return {
type: 'folder',
UUID: this.UUID,
name: this.name,
title: this.name,
pageId: this.pageId,
parentUUID: this.parentUUID,
rootUUID: this.rootUUID,