fix: plant sub section validate

This commit is contained in:
2025-10-24 12:46:34 +07:00
parent ea2905d558
commit 26f7420688
3 changed files with 66 additions and 36 deletions

View File

@@ -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

View 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
};

View File

@@ -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
};