Skip to content

Instantly share code, notes, and snippets.

@cadecairos
Created July 21, 2015 16:57
Show Gist options
  • Save cadecairos/02480198130cf005aff3 to your computer and use it in GitHub Desktop.
Save cadecairos/02480198130cf005aff3 to your computer and use it in GitHub Desktop.
var BulkPayloadSchema: {
actions: Joi.array().required().items(
Joi.object().keys({
type: Joi.string().valid('projects', 'pages', 'elements').required(),
method: Joi.string().valid('create', 'update', 'remove').required(),
data: Joi.object().keys({
id: numericSchema.when('method', {
is: 'create',
then: Joi.forbidden(),
otherwise: Joi.required()
}),
title: Joi.any().when('type', {
is: 'projects',
then: Joi.when('method', {
is: 'remove',
then: Joi.forbidden(),
otherwise: Joi.string().max(256).required()
}),
otherwise: Joi.forbidden()
}),
projectId: numericSchema.when('type', {
is: 'pages',
then: Joi.when('method', {
is: 'create',
then: Joi.required(),
otherwise: Joi.forbidden()
}),
otherwise: Joi.forbidden()
}),
pageId: numericSchema.when('type', {
is: 'elements',
then: Joi.when('method', {
is: 'create',
then: Joi.required(),
otherwise: Joi.forbidden()
}),
otherwise: Joi.forbidden()
}),
x: Joi.any().when('type', {
is: 'pages',
then: Joi.when('method', {
is: 'remove',
then: Joi.forbidden(),
otherwise: Joi.number().integer().required()
}),
otherwise: Joi.forbidden()
}),
y: Joi.any().when('type', {
is: 'pages',
then: Joi.when('method', {
is: 'remove',
then: Joi.forbidden(),
otherwise: Joi.number().integer().required()
}),
otherwise: Joi.forbidden()
}),
styles: Joi.any().when('type', {
is: 'projects',
then: Joi.forbidden(),
otherwise: Joi.when('method', {
is: 'remove',
then: Joi.forbidden(),
otherwise: Joi.object().required()
}),
}),
attributes: Joi.any().when('type', {
is: 'elements',
then: Joi.when('method', {
is: 'remove',
then: Joi.forbidden(),
otherwise: Joi.object().required()
}),
otherwise: Joi.forbidden(),
})
})
})
).min(1).max(1000)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment