����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 } from "./commonSchema.js";
import { errorMessages } from "../config/Constants.js";
export const createUserSchema = (lang = "en") => {
const { emailSchema, passwordSchema } = getCommonSchemas(lang);
const messages = errorMessages[lang] || errorMessages.en;
const nameField = Joi.string()
.max(80)
.allow('')
.messages({
"string.max": messages.nameMax || "Must be at most 80 characters long",
});
return Joi.object({
name: Joi.object({
en: Joi.object({
firstName: nameField.label("English First Name"),
lastName: nameField.label("English Last Name"),
}).default({ firstName: '', lastName: '' }),
ar: Joi.object({
firstName: nameField.label("Arabic First Name"),
lastName: nameField.label("Arabic Last Name"),
}).default({ firstName: '', lastName: '' }),
})
.required()
.custom((value, helpers) => {
const enFirstName = value.en?.firstName?.trim() || '';
const enLastName = value.en?.lastName?.trim() || '';
const arFirstName = value.ar?.firstName?.trim() || '';
const arLastName = value.ar?.lastName?.trim() || '';
const hasEnglishName = enFirstName.length > 0 || enLastName.length > 0;
const hasArabicName = arFirstName.length > 0 || arLastName.length > 0;
if (!hasEnglishName && !hasArabicName) {
return helpers.error('name.required');
}
return value;
})
.messages({
"any.required": messages.nameRequired || "Name object is required",
"name.required": messages.nameRequired || "Full name is required in at least one language (English or Arabic)",
}),
email: emailSchema,
password: passwordSchema,
role: Joi.string()
.valid("student", "teacher", "hr", "admin", "accountant")
.required()
.messages({
"string.empty": "Role is required",
"any.required": "Role is required",
"any.only": "Role must be student, teacher, hr, admin, or accountant",
}),
phoneNumber: Joi.string()
.pattern(/^\+?[0-9]{7,15}$/)
.allow('', null)
.optional()
.messages({
"string.pattern.base": "Phone number must be a valid number",
}),
joiningDate: Joi.date()
.allow(null)
.optional()
.messages({
"date.base": "Joining date must be a valid date",
}),
department: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Department must be a valid ID",
}),
course: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Course must be a valid course ID",
}),
className: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Class name must be valid",
}),
section: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Section must be valid",
}),
});
};
export const updateUserSchema = (lang = "en") => {
const { emailSchema } = getCommonSchemas(lang);
const messages = errorMessages[lang] || errorMessages.en;
const nameField = Joi.string()
.max(80)
.allow('')
.messages({
"string.max": messages.nameMax || "Must be at most 80 characters long",
});
return Joi.object({
name: Joi.object({
en: Joi.object({
firstName: nameField.label("English First Name"),
lastName: nameField.label("English Last Name"),
}),
ar: Joi.object({
firstName: nameField.label("Arabic First Name"),
lastName: nameField.label("Arabic Last Name"),
}),
})
.optional()
.custom((value, helpers) => {
if (!value) return value;
const enFirstName = value.en?.firstName?.trim() || '';
const enLastName = value.en?.lastName?.trim() || '';
const arFirstName = value.ar?.firstName?.trim() || '';
const arLastName = value.ar?.lastName?.trim() || '';
const hasEnglishName = enFirstName.length > 0 || enLastName.length > 0;
const hasArabicName = arFirstName.length > 0 || arLastName.length > 0;
if (!hasEnglishName && !hasArabicName) {
return helpers.error('name.atLeastOne');
}
return value;
})
.messages({
"name.atLeastOne": messages.nameRequired || "Full name is required in at least one language",
}),
email: emailSchema.optional(),
role: Joi.string()
.valid("student", "teacher", "hr", "admin", "accountant")
.optional()
.messages({
"any.only": messages.roleInvalid || "Role must be student, teacher, hr, admin, or accountant",
}),
languagePreference: Joi.string()
.valid("en", "ar")
.optional()
.messages({
"any.only": "Language preference must be either 'en' or 'ar'",
}),
phoneNumber: Joi.string()
.pattern(/^\+?[0-9]{7,15}$/)
.allow('', null)
.optional()
.messages({
"string.pattern.base": messages.phoneInvalid || "Phone number must be a valid number",
}),
joiningDate: Joi.date()
.allow(null)
.optional()
.messages({
"date.base": messages.dateInvalid || "Joining date must be a valid date",
}),
department: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Department must be a valid ID",
}),
course: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Course must be a valid course ID",
}),
className: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Class name must be valid",
}),
section: Joi.string()
.allow('', null)
.optional()
.messages({
"string.base": "Section must be valid",
}),
});
};
export const userLoginSchema = (lang = "en") => {
const { passwordSchema } = getCommonSchemas(lang);
const messages = errorMessages[lang] || errorMessages.en;
return Joi.object({
id: Joi.string().required().messages({
"string.empty": "User ID is required",
"any.required": "User ID is required",
}),
password: passwordSchema,
});
};
export const forgotPasswordSchema = (lang = "en") => {
return Joi.object({
id: Joi.string().required().messages({
"string.empty": "User ID is required",
"any.required": "User ID is required",
}),
email: Joi.string()
.email({ tlds: { allow: false } })
.required()
.messages({
"string.email": errorMessages[lang].emailInvalid,
"string.empty": errorMessages[lang].emailRequired,
"any.required": errorMessages[lang].emailRequired,
}),
});
};
export const resetPasswordSchema = (lang = "en") => {
const { passwordSchema } = getCommonSchemas(lang);
return Joi.object({
id: Joi.string().optional().allow(''),
email: Joi.string().email().optional().allow(''),
token: Joi.string().optional().allow(''),
otp: Joi.string().optional().allow(''),
password: passwordSchema,
confirmPassword: Joi.string()
.valid(Joi.ref("password"))
.required()
.messages({
"string.empty": "Confirm password is required",
"any.required": "Confirm password is required",
"any.only": "Passwords must match",
}),
}).or('token', 'otp');
};
| 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 |
|