diff --git a/controllers/plant_sub_section.controller.js b/controllers/plant_sub_section.controller.js index e175307..919b3fa 100644 --- a/controllers/plant_sub_section.controller.js +++ b/controllers/plant_sub_section.controller.js @@ -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 diff --git a/validate/plant_sub_section.schema.js b/validate/plant_sub_section.schema.js new file mode 100644 index 0000000..8a78b65 --- /dev/null +++ b/validate/plant_sub_section.schema.js @@ -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 +}; diff --git a/validate/sub_section.schema.js b/validate/sub_section.schema.js deleted file mode 100644 index 1eac3ea..0000000 --- a/validate/sub_section.schema.js +++ /dev/null @@ -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 -};