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',
|
2019-10-02 00:16:11 +00:00
|
|
|
'published_at',
|
|
|
|
'is_featured',
|
2019-09-13 13:33:10 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
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(', ')}`)
|
|
|
|
}
|
2019-10-02 00:16:11 +00:00
|
|
|
|
|
|
|
if (ctx.request.body.published_at) {
|
|
|
|
ctx.request.body.published_at = new Date(ctx.request.body.published_at)
|
|
|
|
}
|
2019-09-13 13:33:10 +00:00
|
|
|
}
|