fix: plant sub section validate
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const SubSectionService = require('../services/plant_sub_section.service');
|
||||
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
|
||||
const { insertSubSectionSchema, updateSubSectionSchema } = require('../validate/sub_section.schema');
|
||||
const { insertSubSectionSchema, updateSubSectionSchema } = require('../validate/plant_sub_section.schema');
|
||||
|
||||
class SubSectionController {
|
||||
// Get all sub sections
|
||||
|
||||
65
validate/plant_sub_section.schema.js
Normal file
65
validate/plant_sub_section.schema.js
Normal file
@@ -0,0 +1,65 @@
|
||||
const Joi = require("joi");
|
||||
|
||||
// ========================
|
||||
// Plant Sub Section Validation
|
||||
// ========================
|
||||
const insertSubSectionSchema = Joi.object({
|
||||
plant_sub_section_name: Joi.string()
|
||||
.max(200)
|
||||
.required()
|
||||
.messages({
|
||||
"string.base": "Sub section name must be a string",
|
||||
"string.max": "Sub section name cannot exceed 200 characters",
|
||||
"any.required": "Sub section name is required"
|
||||
}),
|
||||
plant_sub_section_description: Joi.string()
|
||||
.max(200)
|
||||
.allow('')
|
||||
.optional()
|
||||
.messages({
|
||||
"string.base": "Description must be a string",
|
||||
"string.max": "Description cannot exceed 200 characters"
|
||||
}),
|
||||
table_name_value: Joi.string()
|
||||
.max(255)
|
||||
.allow('')
|
||||
.optional()
|
||||
.messages({
|
||||
"string.base": "Table name value must be a string",
|
||||
"string.max": "Table name value cannot exceed 255 characters"
|
||||
}),
|
||||
is_active: Joi.boolean()
|
||||
.default(true)
|
||||
.optional()
|
||||
});
|
||||
|
||||
const updateSubSectionSchema = Joi.object({
|
||||
plant_sub_section_name: Joi.string()
|
||||
.max(200)
|
||||
.messages({
|
||||
"string.base": "Sub section name must be a string",
|
||||
"string.max": "Sub section name cannot exceed 200 characters",
|
||||
}).optional(),
|
||||
plant_sub_section_description: Joi.string()
|
||||
.max(200)
|
||||
.allow('')
|
||||
.optional()
|
||||
.messages({
|
||||
"string.base": "Description must be a string",
|
||||
"string.max": "Description cannot exceed 200 characters"
|
||||
}),
|
||||
table_name_value: Joi.string()
|
||||
.max(255)
|
||||
.allow('')
|
||||
.optional()
|
||||
.messages({
|
||||
"string.base": "Table name value must be a string",
|
||||
"string.max": "Table name value cannot exceed 255 characters"
|
||||
}),
|
||||
is_active: Joi.boolean().optional()
|
||||
}).min(1);
|
||||
|
||||
module.exports = {
|
||||
insertSubSectionSchema,
|
||||
updateSubSectionSchema
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
const Joi = require("joi");
|
||||
|
||||
// ========================
|
||||
// Plant Sub Section Validation
|
||||
// ========================
|
||||
const insertSubSectionSchema = Joi.object({
|
||||
plant_sub_section_name: Joi.string()
|
||||
.max(200)
|
||||
.required()
|
||||
.messages({
|
||||
"string.base": "Sub section name must be a string",
|
||||
"string.max": "Sub section name cannot exceed 200 characters",
|
||||
"any.required": "Sub section name is required"
|
||||
}).required(),
|
||||
is_active: Joi.boolean().required(),
|
||||
value: Joi.string().max(100).optional()
|
||||
});
|
||||
|
||||
const updateSubSectionSchema = Joi.object({
|
||||
plant_sub_section_namesub_section_name: Joi.string()
|
||||
.max(200)
|
||||
.messages({
|
||||
"string.base": "Sub section name must be a string",
|
||||
"string.max": "Sub section name cannot exceed 200 characters",
|
||||
}).optional(),
|
||||
is_active: Joi.boolean().optional(),
|
||||
value: Joi.string().max(100).optional()
|
||||
}).min(1).messages({
|
||||
"object.min": "At least one field must be provided to update",
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
insertSubSectionSchema,
|
||||
updateSubSectionSchema
|
||||
};
|
||||
Reference in New Issue
Block a user