|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
|
|
const Model = require('objection').Model
|
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Users model
|
|
|
|
@ -33,11 +34,18 @@ module.exports = class AssetFolder extends Model {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get full folder hierarchy starting from specified folder to root
|
|
|
|
|
*
|
|
|
|
|
* @param {Number} folderId Id of the folder
|
|
|
|
|
*/
|
|
|
|
|
static async getHierarchy(folderId) {
|
|
|
|
|
return WIKI.models.knex.withRecursive('ancestors', qb => {
|
|
|
|
|
const hier = await WIKI.models.knex.withRecursive('ancestors', qb => {
|
|
|
|
|
qb.select('id', 'name', 'slug', 'parentId').from('assetFolders').where('id', folderId).union(sqb => {
|
|
|
|
|
sqb.select('a.id', 'a.name', 'a.slug', 'a.parentId').from('assetFolders AS a').join('ancestors', 'ancestors.parentId', 'a.id')
|
|
|
|
|
})
|
|
|
|
|
}).select('*').from('ancestors')
|
|
|
|
|
// The ancestors are from children to grandparents, must reverse for correct path order.
|
|
|
|
|
return _.reverse(hier)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|