����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 mongoose from "mongoose";
import { errorMessages } from "../config/Constants.js";
export const createEventSchema = (lang = "en") => {
const messages = errorMessages[lang] || errorMessages.en;
return Joi.object({
title: Joi.object({
en: Joi.string().allow("", null),
ar: Joi.string().allow("", null),
}).or("en", "ar") // At least one language must be provided
.required()
.messages({
"object.missing": messages.event_title_required || "Title is required",
}),
description: Joi.object({
en: Joi.string().allow("", null),
ar: Joi.string().allow("", null),
}).optional(),
location: Joi.object({
en: Joi.string().allow("", null),
ar: Joi.string().allow("", null),
}).or("en", "ar").optional(),
startDate: Joi.date().required().messages({
"date.base": messages.event_startDate_invalid || "Start date is invalid",
"any.required": messages.event_startDate_required || "Start date is required",
}),
endDate: Joi.date().required().messages({
"date.base": messages.event_endDate_invalid || "End date is invalid",
"any.required": messages.event_endDate_required || "End date is required",
}),
allDay: Joi.boolean().default(false),
type: Joi.string().valid("academic", "administrative", "holiday", "exam", "other").default("other"),
isPrivate: Joi.boolean().default(false),
participants: Joi.array().items(
Joi.object({
userId: Joi.string().custom((value, helpers) => {
if (!mongoose.Types.ObjectId.isValid(value)) return helpers.error("any.invalid");
return value;
}).required(),
role: Joi.string().allow("", null),
})
),
visibility: Joi.string().valid("all", "teachers", "students", "admins").default("all"),
// createdBy: Joi.string().custom((value, helpers) => {
// if (!mongoose.Types.ObjectId.isValid(value)) return helpers.error("any.invalid");
// return value;
// }).required(),
color: Joi.string().optional(),
reminder: Joi.boolean().default(false),
status: Joi.string().valid("scheduled", "cancelled", "completed", "postponed").default("scheduled"),
});
};
export const updateEventSchema = (lang = "en") => {
const messages = errorMessages[lang] || errorMessages.en;
return Joi.object({
title: Joi.object({
en: Joi.string().allow("", null),
ar: Joi.string().allow("", null),
}).or("en", "ar").optional()
.messages({
"object.missing": messages.event_title_required || "Title is required",
}),
description: Joi.object({
en: Joi.string().allow("", null),
ar: Joi.string().allow("", null),
}).optional(),
location: Joi.object({
en: Joi.string().allow("", null),
ar: Joi.string().allow("", null),
}).or("en", "ar").optional(),
startDate: Joi.date().messages({
"date.base": messages.event_startDate_invalid || "Invalid start date",
}),
endDate: Joi.date().messages({
"date.base": messages.event_endDate_invalid || "Invalid end date",
}),
allDay: Joi.boolean(),
type: Joi.string().valid("academic", "administrative", "holiday", "exam", "other"),
isPrivate: Joi.boolean(),
participants: Joi.array().items(
Joi.object({
userId: Joi.string().custom((value, helpers) => {
if (!mongoose.Types.ObjectId.isValid(value)) return helpers.error("any.invalid");
return value;
}),
role: Joi.string().allow("", null),
})
),
visibility: Joi.string().valid("all", "teachers", "students", "admins"),
createdBy: Joi.string().custom((value, helpers) => {
if (!mongoose.Types.ObjectId.isValid(value)) return helpers.error("any.invalid");
return value;
}),
color: Joi.string(),
reminder: Joi.boolean(),
status: Joi.string().valid("scheduled", "cancelled", "completed", "postponed"),
});
};
export const createContractSchema = (lang = "en") => {
const messages = errorMessages[lang] || errorMessages.en;
return Joi.object({
teacherId: Joi.string()
.custom((value, helpers) => {
if (!mongoose.Types.ObjectId.isValid(value)) {
return helpers.error("any.invalid");
}
return value;
})
.required()
.messages({
"any.invalid": messages.contract_invalid_teacherId || "Invalid teacherId",
"any.required": messages.contract_teacherId_required || "teacherId is required",
}),
type: Joi.string()
.valid("Contract", "Agreement", "NOC", "Warning")
.required()
.messages({
"any.only": messages.contract_type_invalid || "Invalid contract type",
"any.required": messages.contract_type_required || "Contract type is required",
}),
uploadDate: Joi.date().required().messages({
"date.base": messages.contract_uploadDate_invalid || "Invalid upload date",
"any.required": messages.contract_uploadDate_required || "Upload date is required",
}),
expiryDate: Joi.date().required().messages({
"date.base": messages.contract_expiryDate_invalid || "Invalid expiry date",
"any.required": messages.contract_expiryDate_required || "Expiry date is required",
}),
});
};
export const updateContractSchema = (lang = "en") => {
const messages = errorMessages[lang] || errorMessages.en;
return Joi.object({
teacherId: Joi.string().custom((value, helpers) => {
if (!mongoose.Types.ObjectId.isValid(value)) {
return helpers.error("any.invalid");
}
return value;
}),
type: Joi.string().valid("Contract", "Agreement", "NOC", "Warning"),
uploadDate: Joi.date().messages({
"date.base": messages.contract_uploadDate_invalid || "Invalid upload date",
}),
expiryDate: Joi.date().messages({
"date.base": messages.contract_expiryDate_invalid || "Invalid expiry date",
}),
}).min(1);
};
export const createTimetableSchema = (lang = "en") => {
return Joi.object({
classId: Joi.string()
.pattern(/^[0-9a-fA-F]{24}$/)
.required()
.messages({
"any.required": lang === "ar" ? "الفصل مطلوب" : "Class is required",
"string.pattern.base": lang === "ar" ? "معرف الفصل غير صالح" : "Invalid class ID format"
}),
academicYear: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
})
.custom((value, helpers) => {
if (!value?.en && !value?.ar) {
return helpers.error("custom.atLeastOne");
}
return value;
})
.messages({
"custom.atLeastOne": lang === "ar"
? "يجب توفير العام الدراسي بلغة واحدة على الأقل"
: "At least one language is required for academic year"
}),
level: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
})
.custom((value, helpers) => {
if (!value?.en && !value?.ar) {
return helpers.error("custom.atLeastOne");
}
return value;
})
.messages({
"custom.atLeastOne": lang === "ar"
? "يجب توفير المستوى بلغة واحدة على الأقل"
: "At least one language is required for level"
}),
semester: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
})
.custom((value, helpers) => {
if (!value?.en && !value?.ar) {
return helpers.error("custom.atLeastOne");
}
return value;
})
.messages({
"custom.atLeastOne": lang === "ar"
? "يجب توفير الفصل الدراسي بلغة واحدة على الأقل"
: "At least one language is required for semester"
}),
section: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
}).optional(),
courseId: Joi.string()
.pattern(/^[0-9a-fA-F]{24}$/)
.optional()
.messages({
"string.pattern.base": lang === "ar" ? "معرف الكورس غير صالح" : "Invalid course ID format"
}),
teacherId: Joi.string()
.pattern(/^[0-9a-fA-F]{24}$/)
.optional()
.messages({
"string.pattern.base": lang === "ar" ? "معرف المعلم غير صالح" : "Invalid teacher ID format"
}),
active: Joi.boolean().optional()
});
};
export const updateTimetableSchema = (lang = "en") => {
return Joi.object({
classId: Joi.string()
.pattern(/^[0-9a-fA-F]{24}$/)
.optional()
.messages({
"string.pattern.base": lang === "ar" ? "معرف الفصل غير صالح" : "Invalid class ID format"
}),
academicYear: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
}).optional(),
level: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
}).optional(),
semester: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
}).optional(),
section: Joi.object({
en: Joi.string().trim().max(50).allow("", null),
ar: Joi.string().trim().max(50).allow("", null)
}).optional(),
courseId: Joi.string()
.pattern(/^[0-9a-fA-F]{24}$/)
.optional(),
teacherId: Joi.string()
.pattern(/^[0-9a-fA-F]{24}$/)
.optional(),
active: Joi.boolean().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 |
|