nfp_sites/api/article/security.mjs
2019-09-14 19:03:38 +00:00

37 lines
797 B
JavaScript

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) {
let out = filter(ctx.state.filter.includes, ['staff', 'media', 'parent', 'banner', 'files'])
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(', ')}`)
}
}