����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 { getCommonSchemas,createNotificationSchema,updateNotificationSchema } from "./commonSchema.js";
import { errorMessages } from "../config/Constants.js";
import {
createUserSchema,
userLoginSchema,
updateUserSchema,
forgotPasswordSchema,
resetPasswordSchema,
} from "./userValidation.js";
import {
createQuizSchema,
updateQuizSchema,
replyQuerySchema,
queryStatusSchema,
changePasswordSchema,
updatePreferencesSchema,
uploadGradeSchema
} from "./teacherValidation.js";
import {
createClassSchema,
updateClassSchema,
createDepartmentSchema,
updateDepartmentSchema,
} from "./adminValidation.js";
export const getLoginSchema = (lang = "en") => {
const { emailSchema, passwordSchema } = getCommonSchemas(lang);
return Joi.object({
email: emailSchema,
password: passwordSchema,
});
};
export const getRegisterSchema = (lang = "en") => {
const { emailSchema, passwordSchema } = getCommonSchemas(lang);
const messages = errorMessages[lang] || errorMessages.en;
const singleNameSchema = Joi.string()
.max(80)
.allow("")
.messages({
"string.max": messages.nameMax || "Must be at most 80 characters long",
});
const langNameObject = Joi.object({
firstName: singleNameSchema.label("First Name"),
lastName: singleNameSchema.label("Last Name"),
});
return Joi.object({
// Both are optional at the field level; model enforces that at least one is present
en: langNameObject.optional(),
ar: langNameObject.optional(),
email: emailSchema,
password: passwordSchema,
}).custom((value, helpers) => {
const hasEn =
value.en &&
typeof value.en.firstName === "string" &&
value.en.firstName.trim() !== "" &&
typeof value.en.lastName === "string" &&
value.en.lastName.trim() !== "";
const hasAr =
value.ar &&
typeof value.ar.firstName === "string" &&
value.ar.firstName.trim() !== "" &&
typeof value.ar.lastName === "string" &&
value.ar.lastName.trim() !== "";
if (!hasEn && !hasAr) {
return helpers.error("any.custom");
}
return value;
}).messages({
"any.custom":
messages.nameRequired ||
"At least one language (EN or AR) full name must be provided",
});
};
export const getUpdateAdminProfileSchema = (lang = "en") => {
const messages = errorMessages[lang] || errorMessages.en;
return Joi.object({
en: Joi.object().optional(),
ar: Joi.object().optional(),
fcmToken: Joi.string().optional()
})
.min(1)
.messages({
"object.min": messages.updateRequired || "At least one field must be provided for update",
});
};
export {
// User validations
createUserSchema,
userLoginSchema,
updateUserSchema,
forgotPasswordSchema,
resetPasswordSchema,
// Teacher validations
createQuizSchema,
updateQuizSchema,
replyQuerySchema,
queryStatusSchema,
changePasswordSchema,
updatePreferencesSchema,
uploadGradeSchema,
// Admin validations
createClassSchema,
updateClassSchema,
createDepartmentSchema,
updateDepartmentSchema,
// Notification validations
createNotificationSchema,
updateNotificationSchema
};
| 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 |
|