refactor: server code (#2545)
+ Remove duplicated await + Replace some legacy codes with ES6 + Fix some of eslint problems
This commit is contained in:
@@ -47,8 +47,7 @@ module.exports = class AssetFolder extends Model {
|
||||
sqb.select('a.id', 'a.name', 'a.slug', 'a.parentId').from('assetFolders AS a').join('ancestors', 'ancestors.parentId', 'a.id')
|
||||
})
|
||||
}).select('*').from('ancestors')
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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')
|
||||
|
@@ -231,7 +231,7 @@ module.exports = class Page extends Model {
|
||||
*/
|
||||
static async createPage(opts) {
|
||||
// -> Validate path
|
||||
if (opts.path.indexOf('.') >= 0 || opts.path.indexOf(' ') >= 0 || opts.path.indexOf('\\') >= 0 || opts.path.indexOf('//') >= 0) {
|
||||
if (opts.path.includes('.') || opts.path.includes(' ') || opts.path.includes('\\') || opts.path.includes('//')) {
|
||||
throw new WIKI.Error.PageIllegalPath()
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ module.exports = class Page extends Model {
|
||||
}
|
||||
|
||||
// -> Validate path
|
||||
if (opts.destinationPath.indexOf('.') >= 0 || opts.destinationPath.indexOf(' ') >= 0 || opts.destinationPath.indexOf('\\') >= 0 || opts.destinationPath.indexOf('//') >= 0) {
|
||||
if (opts.destinationPath.includes('.') || opts.destinationPath.includes(' ') || opts.destinationPath.includes('\\') || opts.destinationPath.includes('//')) {
|
||||
throw new WIKI.Error.PageIllegalPath()
|
||||
}
|
||||
|
||||
@@ -514,7 +514,7 @@ module.exports = class Page extends Model {
|
||||
}
|
||||
|
||||
// -> Check for existing page at destination path
|
||||
const destPage = await await WIKI.models.pages.query().findOne({
|
||||
const destPage = await WIKI.models.pages.query().findOne({
|
||||
path: opts.destinationPath,
|
||||
localeCode: opts.destinationLocale
|
||||
})
|
||||
@@ -575,7 +575,7 @@ module.exports = class Page extends Model {
|
||||
path: opts.destinationPath,
|
||||
mode: 'move'
|
||||
})
|
||||
|
||||
|
||||
// -> Reconnect Links : Validate invalid links to the new path
|
||||
await WIKI.models.pages.reconnectLinks({
|
||||
locale: opts.destinationLocale,
|
||||
@@ -595,7 +595,7 @@ module.exports = class Page extends Model {
|
||||
if (_.has(opts, 'id')) {
|
||||
page = await WIKI.models.pages.query().findById(opts.id)
|
||||
} else {
|
||||
page = await await WIKI.models.pages.query().findOne({
|
||||
page = await WIKI.models.pages.query().findOne({
|
||||
path: opts.path,
|
||||
localeCode: opts.locale
|
||||
})
|
||||
|
Reference in New Issue
Block a user