From 851d2799857ca0268bf6f55654f9b51f828d6dff Mon Sep 17 00:00:00 2001 From: Dasha Date: Wed, 4 Mar 2026 07:47:26 +0100 Subject: [PATCH 1/3] feat: increase characters for description --- .../appointmentDescription.validation.ts | 20 +++++--------- server/src/constants/validation.constants.ts | 1 + .../validation/requestValidation.util.ts | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 server/src/constants/validation.constants.ts create mode 100644 server/src/utils/validation/requestValidation.util.ts diff --git a/client/src/utils/appointmentDescription.validation.ts b/client/src/utils/appointmentDescription.validation.ts index 5e2266c1..d57406cb 100644 --- a/client/src/utils/appointmentDescription.validation.ts +++ b/client/src/utils/appointmentDescription.validation.ts @@ -1,24 +1,16 @@ -export const MAX_DESCRIPTION_WORDS = 50; - -export const countWords = (text: string): number => { - return text - .trim() - .split(/\s+/) - .filter((word) => word.length > 0).length; -}; +export const MAX_DESCRIPTION_CHARACTERS = 500; export const isDescriptionValid = (description: string): boolean => { - const wordCount = countWords(description); - return wordCount <= MAX_DESCRIPTION_WORDS; + return description.trim().length <= MAX_DESCRIPTION_CHARACTERS; }; export const getDescriptionValidation = (description: string) => { - const wordCount = countWords(description); - const isValid = wordCount <= MAX_DESCRIPTION_WORDS; + const characterCount = description.trim().length; + const isValid = characterCount <= MAX_DESCRIPTION_CHARACTERS; return { - wordCount, + characterCount, isValid, - maxWords: MAX_DESCRIPTION_WORDS, + maxCharacters: MAX_DESCRIPTION_CHARACTERS, }; }; diff --git a/server/src/constants/validation.constants.ts b/server/src/constants/validation.constants.ts new file mode 100644 index 00000000..f9567a86 --- /dev/null +++ b/server/src/constants/validation.constants.ts @@ -0,0 +1 @@ +export const MAX_DESCRIPTION_CHARACTERS = 500; \ No newline at end of file diff --git a/server/src/utils/validation/requestValidation.util.ts b/server/src/utils/validation/requestValidation.util.ts new file mode 100644 index 00000000..c90562ef --- /dev/null +++ b/server/src/utils/validation/requestValidation.util.ts @@ -0,0 +1,27 @@ +export const validatePaginationParams = (page?: string, limit?: string) => { + let validatedPage: number | undefined; + let validatedLimit: number | undefined; + + if (page) { + validatedPage = parseInt(page, 10); + if (isNaN(validatedPage)) { + throw new Error("Invalid page parameter"); + } + } + + if (limit) { + validatedLimit = parseInt(limit, 10); + if (isNaN(validatedLimit)) { + throw new Error("Invalid limit parameter"); + } + } + + return { page: validatedPage, limit: validatedLimit }; +}; + +export const validateAuthorization = (userId?: string) => { + if (!userId) { + throw new Error("Unauthorized"); + } + return userId; +}; From 46a8820fb1f7379b6231b9a2c5626bfdf5b558b0 Mon Sep 17 00:00:00 2001 From: Dasha Date: Wed, 4 Mar 2026 07:47:58 +0100 Subject: [PATCH 2/3] feat: improve validation --- .../teacherSchedule/TeacherSchedule.tsx | 17 ++- server/src/constants/validation.constants.ts | 2 +- .../src/controllers/appointment.controller.ts | 126 ++++-------------- server/src/controllers/review.controller.ts | 34 ++--- server/src/controllers/student.controller.ts | 13 +- server/src/controllers/teacher.controller.ts | 23 +--- server/src/controllers/upload.controller.ts | 13 +- .../src/controllers/videoCall.controller.ts | 37 ++--- .../appointmentValidationMiddleware.ts | 14 ++ 9 files changed, 94 insertions(+), 185 deletions(-) diff --git a/client/src/components/teacherSection/teacherSchedule/TeacherSchedule.tsx b/client/src/components/teacherSection/teacherSchedule/TeacherSchedule.tsx index 766fe76f..edc5b854 100644 --- a/client/src/components/teacherSection/teacherSchedule/TeacherSchedule.tsx +++ b/client/src/components/teacherSection/teacherSchedule/TeacherSchedule.tsx @@ -93,7 +93,7 @@ export default function TeacherSchedule({ teacher }: TeacherScheduleProps) { return getDescriptionValidation(description); }, [description]); - const { wordCount, isValid: isDescriptionValid } = descriptionValidation; + const { characterCount, isValid: isDescriptionValid } = descriptionValidation; const handleDateSelection = (date: Date): void => { setSelectedDate(date); @@ -325,10 +325,14 @@ export default function TeacherSchedule({ teacher }: TeacherScheduleProps) { {selectedSubject && selectedLevel && (
-