2019-09-13 13:33:10 +00:00
|
|
|
import filter from '../filter.mjs'
|
|
|
|
|
|
|
|
const requiredFields = [
|
|
|
|
'name',
|
|
|
|
'path',
|
|
|
|
]
|
|
|
|
|
|
|
|
const validFields = [
|
|
|
|
'name',
|
|
|
|
'path',
|
|
|
|
'description',
|
|
|
|
'parent_id',
|
|
|
|
'media_id',
|
|
|
|
'banner_id',
|
|
|
|
]
|
|
|
|
|
|
|
|
export async function ensureIncludes(ctx) {
|
2019-09-14 19:03:38 +00:00
|
|
|
let out = filter(ctx.state.filter.includes, ['staff', 'media', 'parent', 'banner', 'files'])
|
2019-09-13 13:33:10 +00:00
|
|
|
|
|
|
|
if (out.length > 0) {
|
|
|
|
ctx.throw(422, `Includes had following invalid values: ${out.join(', ')}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function validUpdate(ctx) {
|
|
|
|
requiredFields.forEach(item => {
|
|
|
|
if (ctx.request.body[item] == null) {
|
|
|
|
ctx.throw(422, `Property was missing: ${item}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
let out = filter(Object.keys(ctx.request.body), validFields)
|
|
|
|
|
|
|
|
if (out.length > 0) {
|
|
|
|
ctx.throw(422, `Body had following invalid properties: ${out.join(', ')}`)
|
|
|
|
}
|
|
|
|
}
|