mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-13 13:58:35 +03:00
add support for custom fields
This commit is contained in:
@@ -1,30 +1,42 @@
|
||||
import Joi from 'joi'
|
||||
|
||||
const eventSchema = Joi.object().keys({
|
||||
id: Joi.string().allow(''),
|
||||
description: Joi.string().allow('').required(),
|
||||
date: Joi.string().allow(''),
|
||||
time: Joi.string().allow(''),
|
||||
time_precision: Joi.string().allow(''),
|
||||
location: Joi.string().allow(''),
|
||||
latitude: Joi.string().allow(''),
|
||||
longitude: Joi.string().allow(''),
|
||||
type: Joi.string().allow(''),
|
||||
category: Joi.string().allow(''),
|
||||
category_full: Joi.string().allow(''),
|
||||
narratives: Joi.array(),
|
||||
sources: Joi.array(),
|
||||
filters: Joi.array().allow(''),
|
||||
tags: Joi.array().allow(''),
|
||||
comments: Joi.string().allow(''),
|
||||
time_display: Joi.string().allow(''),
|
||||
function joiFromCustom (custom) {
|
||||
const output = {}
|
||||
custom.forEach(field => {
|
||||
if (field.kind === 'text' || field.kind === 'link') {
|
||||
output[field.key] = Joi.string().allow('')
|
||||
}
|
||||
})
|
||||
return output
|
||||
}
|
||||
|
||||
// nested
|
||||
narrative___stepStyles: Joi.array(),
|
||||
shape: Joi.string().allow(''),
|
||||
colour: Joi.string().allow('')
|
||||
})
|
||||
.and('latitude', 'longitude')
|
||||
.or('date', 'latitude')
|
||||
function createEventSchema (custom) {
|
||||
return Joi.object().keys({
|
||||
id: Joi.string().allow(''),
|
||||
description: Joi.string().allow('').required(),
|
||||
date: Joi.string().allow(''),
|
||||
time: Joi.string().allow(''),
|
||||
time_precision: Joi.string().allow(''),
|
||||
location: Joi.string().allow(''),
|
||||
latitude: Joi.string().allow(''),
|
||||
longitude: Joi.string().allow(''),
|
||||
type: Joi.string().allow(''),
|
||||
category: Joi.string().allow(''),
|
||||
category_full: Joi.string().allow(''),
|
||||
narratives: Joi.array(),
|
||||
sources: Joi.array(),
|
||||
filters: Joi.array().allow(''),
|
||||
tags: Joi.array().allow(''),
|
||||
comments: Joi.string().allow(''),
|
||||
time_display: Joi.string().allow(''),
|
||||
// nested
|
||||
narrative___stepStyles: Joi.array(),
|
||||
shape: Joi.string().allow(''),
|
||||
colour: Joi.string().allow(''),
|
||||
...joiFromCustom(custom)
|
||||
})
|
||||
.and('latitude', 'longitude')
|
||||
.or('date', 'latitude')
|
||||
}
|
||||
|
||||
export default eventSchema
|
||||
export default createEventSchema
|
||||
|
||||
Reference in New Issue
Block a user