add: brand validate
This commit is contained in:
78
validate/brand.schema.js
Normal file
78
validate/brand.schema.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const Joi = require("joi");
|
||||
|
||||
// ========================
|
||||
// Brand Validation
|
||||
// ========================
|
||||
const insertBrandSchema = Joi.object({
|
||||
brand_name: Joi.string().max(100).required(),
|
||||
brand_type: Joi.string().max(50).optional(),
|
||||
brand_manufacture: Joi.string().max(100).optional(),
|
||||
brand_model: Joi.string().max(100).optional(),
|
||||
is_active: Joi.boolean().required(),
|
||||
description: Joi.string().max(255).optional(),
|
||||
error_code: Joi.array().items(
|
||||
Joi.object({
|
||||
error_code: Joi.string().max(100).required(),
|
||||
error_code_name: Joi.string().max(100).required(),
|
||||
error_code_description: Joi.string().optional(),
|
||||
is_active: Joi.boolean().required(),
|
||||
solution: Joi.array().items(
|
||||
Joi.object({
|
||||
solution_name: Joi.string().max(100).required(),
|
||||
type_solution: Joi.string().valid('text', 'pdf', 'image', 'video', 'link').required(),
|
||||
text_solution: Joi.when('type_solution', {
|
||||
is: 'text',
|
||||
then: Joi.string().required(),
|
||||
otherwise: Joi.string().optional().allow('')
|
||||
}),
|
||||
path_solution: Joi.when('type_solution', {
|
||||
is: 'text',
|
||||
then: Joi.string().optional().allow(''),
|
||||
otherwise: Joi.string().required()
|
||||
}),
|
||||
is_active: Joi.boolean().required()
|
||||
})
|
||||
).min(1).required()
|
||||
})
|
||||
).min(1).required()
|
||||
});
|
||||
|
||||
// Update Brand Validation
|
||||
const updateBrandSchema = Joi.object({
|
||||
brand_name: Joi.string().max(100).required(),
|
||||
brand_type: Joi.string().max(50).optional(),
|
||||
brand_manufacture: Joi.string().max(100).optional(),
|
||||
brand_model: Joi.string().max(100).optional(),
|
||||
is_active: Joi.boolean().required(),
|
||||
description: Joi.string().max(255).optional(),
|
||||
error_code: Joi.array().items(
|
||||
Joi.object({
|
||||
error_code: Joi.string().max(100).required(),
|
||||
error_code_name: Joi.string().max(100).required(),
|
||||
error_code_description: Joi.string().optional(),
|
||||
is_active: Joi.boolean().required(),
|
||||
solution: Joi.array().items(
|
||||
Joi.object({
|
||||
solution_name: Joi.string().max(100).required(),
|
||||
type_solution: Joi.string().valid('text', 'pdf', 'image', 'video', 'link').required(),
|
||||
text_solution: Joi.when('type_solution', {
|
||||
is: 'text',
|
||||
then: Joi.string().required(),
|
||||
otherwise: Joi.string().optional().allow('')
|
||||
}),
|
||||
path_solution: Joi.when('type_solution', {
|
||||
is: 'text',
|
||||
then: Joi.string().optional().allow(''),
|
||||
otherwise: Joi.string().required()
|
||||
}),
|
||||
is_active: Joi.boolean().optional()
|
||||
})
|
||||
).min(1).required()
|
||||
})
|
||||
).optional()
|
||||
}).min(1);
|
||||
|
||||
module.exports = {
|
||||
insertBrandSchema,
|
||||
updateBrandSchema
|
||||
};
|
||||
Reference in New Issue
Block a user