����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";
// Factory that returns localized schema pieces
export const getCommonSchemas = (lang) => {
const messages = errorMessages[lang];
const emailSchema = Joi.string()
.email({ tlds: { allow: false } })
.required()
.messages({
"string.email": messages.emailInvalid,
"string.empty": messages.emailRequired,
"any.required": messages.emailRequired,
});
const passwordSchema = Joi.string()
.pattern(/^(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*:;]).{8,15}$/)
.required()
.messages({
"string.pattern.base": messages.passwordPattern,
"string.empty": messages.passwordRequired,
"any.required": messages.passwordRequired,
});
//add and return common schema here
return { emailSchema, passwordSchema };
};
// validators/notificationValidator.js
const bilingualTextSchema = (fieldLabel, lang = "en") =>
Joi.object({
en: Joi.string().allow("").optional(),
ar: Joi.string().allow("").optional(),
})
.custom((value, helpers) => {
if (!value) return helpers.error("any.required");
const hasEn = typeof value.en === "string" && value.en.trim() !== "";
const hasAr = typeof value.ar === "string" && 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`,
});
export const createNotificationSchema = (lang = "en") => {
return Joi.object({
title: bilingualTextSchema("Title", lang).required(),
message: bilingualTextSchema("Message", lang).required(),
type: Joi.string()
.valid(
"announcement",
"event",
"assignment",
"quiz",
"grade",
"fee",
"attendance",
"other"
)
.default("announcement"),
priority: Joi.string()
.valid("low", "medium", "high", "urgent")
.default("medium"),
targetAudience: Joi.string()
.valid(
"all",
"students",
"teachers",
"staff",
"parents",
"admin",
"specific"
)
.required(),
targetClasses: Joi.array()
.items(Joi.string().pattern(/^[0-9a-fA-F]{24}$/))
.optional(),
targetUsers: Joi.array()
.items(Joi.string().pattern(/^[0-9a-fA-F]{24}$/))
.optional(),
validFrom: Joi.date().optional(),
validUntil: Joi.date()
.greater(Joi.ref("validFrom"))
.optional()
.messages({
"date.greater":
lang === "ar"
? "تاريخ الانتهاء يجب أن يكون بعد تاريخ البدء"
: "validUntil must be greater than validFrom",
}),
link: Joi.object({
url: Joi.string().uri().optional(),
text: Joi.object({
en: Joi.string().allow("").optional(),
ar: Joi.string().allow("").optional(),
}).optional(),
}).optional(),
relatedResource: Joi.object({
resourceId: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).optional(),
resourceType: Joi.string()
.valid("assignment", "quiz", "event", "fee", "class", "other")
.optional(),
}).optional(),
// Added status field here
status: Joi.string()
.valid("draft", "published", "archived")
.default("draft")
.optional()
});
};
export const updateNotificationSchema = (lang = "en") => {
return Joi.object({
title: bilingualTextSchema("Title", lang).optional(),
message: bilingualTextSchema("Message", lang).optional(),
type: Joi.string()
.valid(
"announcement",
"event",
"assignment",
"quiz",
"grade",
"fee",
"attendance",
"other"
)
.optional(),
priority: Joi.string()
.valid("low", "medium", "high", "urgent")
.optional(),
targetAudience: Joi.string()
.valid(
"all",
"students",
"teachers",
"staff",
"parents",
"admin",
"specific"
)
.optional(),
targetClasses: Joi.array()
.items(Joi.string().pattern(/^[0-9a-fA-F]{24}$/))
.optional(),
targetUsers: Joi.array()
.items(Joi.string().pattern(/^[0-9a-fA-F]{24}$/))
.optional(),
validFrom: Joi.date().optional(),
validUntil: Joi.date().optional(),
link: Joi.object({
url: Joi.string().uri().optional(),
text: Joi.object({
en: Joi.string().allow("").optional(),
ar: Joi.string().allow("").optional(),
}).optional(),
}).optional(),
relatedResource: Joi.object({
resourceId: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).optional(),
resourceType: Joi.string()
.valid("assignment", "quiz", "event", "fee", "class", "other")
.optional(),
}).optional(),
// Added status field here too
status: Joi.string()
.valid("draft", "published", "archived")
.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 |
|