From 7360aff0edb2fb5a5baff5daa875c1af33bd4dbb Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Thu, 1 Aug 2024 11:48:20 +0530 Subject: [PATCH 01/18] initialize zod --- package-lock.json | 11 ++++++++++- package.json | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3f5305d3..32cadd7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,8 @@ "pg": "^8.10.0", "reflect-metadata": "^0.1.13", "ts-node": "^10.9.1", - "typeorm": "^0.3.16" + "typeorm": "^0.3.16", + "zod": "^3.23.8" }, "devDependencies": { "@types/bcrypt": "^5.0.0", @@ -10980,6 +10981,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index 35714a15..0713614e 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "pg": "^8.10.0", "reflect-metadata": "^0.1.13", "ts-node": "^10.9.1", - "typeorm": "^0.3.16" + "typeorm": "^0.3.16", + "zod": "^3.23.8" }, "devDependencies": { "@types/bcrypt": "^5.0.0", From 8f57db256f4ed778733d4d7bf0da9e6c6bb1d090 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Thu, 1 Aug 2024 11:48:34 +0530 Subject: [PATCH 02/18] implement request validator --- src/middlewares/requestValidator.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/middlewares/requestValidator.ts diff --git a/src/middlewares/requestValidator.ts b/src/middlewares/requestValidator.ts new file mode 100644 index 00000000..aa51e1c1 --- /dev/null +++ b/src/middlewares/requestValidator.ts @@ -0,0 +1,21 @@ +import { ZodError, ZodSchema } from 'zod' + +export const requestValidator = (schema: ZodSchema) => { + return (req: any, res: any, next: any) => { + try { + schema.parse(req.body) + next() + } catch (err) { + console.log(err) + if (err instanceof ZodError) { + const errorMessages = err.errors.map((issue) => ({ + message: `${issue.path.join('.')} is ${issue.message}` + })) + return res + .status(400) + .json({ error: 'Invalid data', details: errorMessages }) + } + return res.status(500).json({ error: 'Internal server error' }) + } + } +} From 7434ccba4ee1d815994d88c404cf5418e3183a80 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Thu, 1 Aug 2024 11:48:55 +0530 Subject: [PATCH 03/18] add middleware function --- src/schemas/auth-routes.schems.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/schemas/auth-routes.schems.ts diff --git a/src/schemas/auth-routes.schems.ts b/src/schemas/auth-routes.schems.ts new file mode 100644 index 00000000..f0954f75 --- /dev/null +++ b/src/schemas/auth-routes.schems.ts @@ -0,0 +1,8 @@ +import { z } from 'zod' + +export const registerSchema = z.object({ + email: z.string().email(), + password: z.string().min(6), + first_name: z.string(), + last_name: z.string() +}) From 7331d683da242ae71a64600a7b255b253f6a3d8e Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Thu, 1 Aug 2024 11:49:12 +0530 Subject: [PATCH 04/18] attach middle ware to routes --- src/routes/auth/auth.route.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/routes/auth/auth.route.ts b/src/routes/auth/auth.route.ts index e3c6c712..ed4fd7ef 100644 --- a/src/routes/auth/auth.route.ts +++ b/src/routes/auth/auth.route.ts @@ -9,10 +9,12 @@ import { passwordResetRequest, register } from '../../controllers/auth.controller' +import { requestValidator } from '../../middlewares/requestValidator' +import { registerSchema } from '../../schemas/auth-routes.schems' const authRouter = express.Router() -authRouter.post('/register', register) +authRouter.post('/register', requestValidator(registerSchema), register) authRouter.post('/login', login) authRouter.get('/logout', logout) From 229862c44b1df564aec3e1c159f8630ae7456596 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Thu, 1 Aug 2024 13:57:10 +0530 Subject: [PATCH 05/18] complete auth and profile route validations --- src/middlewares/requestValidator.ts | 21 ++++++++++++++++++++- src/routes/auth/auth.route.ts | 8 ++++---- src/routes/profile/profile.route.ts | 22 +++++++++++++++++++--- src/schemas/auth-routes.schems.ts | 7 ++++++- src/schemas/profile-routes.schema.ts | 12 ++++++++++++ 5 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 src/schemas/profile-routes.schema.ts diff --git a/src/middlewares/requestValidator.ts b/src/middlewares/requestValidator.ts index aa51e1c1..9887d729 100644 --- a/src/middlewares/requestValidator.ts +++ b/src/middlewares/requestValidator.ts @@ -1,6 +1,6 @@ import { ZodError, ZodSchema } from 'zod' -export const requestValidator = (schema: ZodSchema) => { +export const requestBodyValidator = (schema: ZodSchema) => { return (req: any, res: any, next: any) => { try { schema.parse(req.body) @@ -19,3 +19,22 @@ export const requestValidator = (schema: ZodSchema) => { } } } + +export const requestQueryValidator = (schema: ZodSchema) => { + return (req: any, res: any, next: any) => { + try { + schema.parse(req.query) + next() + } catch (err) { + if (err instanceof ZodError) { + const errorMessages = err.errors.map((issue) => ({ + message: `${issue.path.join('.')} is ${issue.message}` + })) + return res + .status(400) + .json({ error: 'Invalid data', details: errorMessages }) + } + return res.status(500).json({ error: 'Internal server error' }) + } + } +} diff --git a/src/routes/auth/auth.route.ts b/src/routes/auth/auth.route.ts index ed4fd7ef..a50bb233 100644 --- a/src/routes/auth/auth.route.ts +++ b/src/routes/auth/auth.route.ts @@ -9,13 +9,13 @@ import { passwordResetRequest, register } from '../../controllers/auth.controller' -import { requestValidator } from '../../middlewares/requestValidator' -import { registerSchema } from '../../schemas/auth-routes.schems' +import { requestBodyValidator } from '../../middlewares/requestValidator' +import { loginSchema, registerSchema } from '../../schemas/auth-routes.schems' const authRouter = express.Router() -authRouter.post('/register', requestValidator(registerSchema), register) -authRouter.post('/login', login) +authRouter.post('/register', requestBodyValidator(registerSchema), register) +authRouter.post('/login', requestBodyValidator(loginSchema), login) authRouter.get('/logout', logout) authRouter.get( diff --git a/src/routes/profile/profile.route.ts b/src/routes/profile/profile.route.ts index c073b24a..91e1d51c 100644 --- a/src/routes/profile/profile.route.ts +++ b/src/routes/profile/profile.route.ts @@ -1,17 +1,33 @@ import express from 'express' +import { requireAuth } from '../../controllers/auth.controller' import { deleteProfileHandler, getApplicationsHandler, getProfileHandler, updateProfileHandler } from '../../controllers/profile.controller' -import { requireAuth } from '../../controllers/auth.controller' +import { + requestBodyValidator, + requestQueryValidator +} from '../../middlewares/requestValidator' +import { + getApplicationsSchema, + updateProfileSchema +} from '../../schemas/profile-routes.schema' const profileRouter = express.Router() profileRouter.get('/profile', requireAuth, getProfileHandler) -profileRouter.put('/profile', requireAuth, updateProfileHandler) +profileRouter.put( + '/profile', + [requireAuth, requestBodyValidator(updateProfileSchema)], + updateProfileHandler +) profileRouter.delete('/profile', requireAuth, deleteProfileHandler) -profileRouter.get('/applications', requireAuth, getApplicationsHandler) +profileRouter.get( + '/applications', + [requireAuth, requestQueryValidator(getApplicationsSchema)], + getApplicationsHandler +) export default profileRouter diff --git a/src/schemas/auth-routes.schems.ts b/src/schemas/auth-routes.schems.ts index f0954f75..74031977 100644 --- a/src/schemas/auth-routes.schems.ts +++ b/src/schemas/auth-routes.schems.ts @@ -2,7 +2,12 @@ import { z } from 'zod' export const registerSchema = z.object({ email: z.string().email(), - password: z.string().min(6), + password: z.string(), first_name: z.string(), last_name: z.string() }) + +export const loginSchema = z.object({ + email: z.string().email(), + password: z.string() +}) diff --git a/src/schemas/profile-routes.schema.ts b/src/schemas/profile-routes.schema.ts new file mode 100644 index 00000000..f4706d1d --- /dev/null +++ b/src/schemas/profile-routes.schema.ts @@ -0,0 +1,12 @@ +import { z } from 'zod' + +export const updateProfileSchema = z.object({ + primary_email: z.string().email(), + first_name: z.string(), + last_name: z.string(), + image_url: z.string().url() +}) + +export const getApplicationsSchema = z.object({ + type: z.enum(['mentor', 'mentee']) +}) From 6887ed87e6002703626a1db96025614add0d024b Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Thu, 1 Aug 2024 14:33:10 +0530 Subject: [PATCH 06/18] update mentor schemas --- src/routes/mentor/mentor.route.ts | 26 +++++++++++++++++++++----- src/schemas/mentor-routes.schema.ts | 11 +++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 src/schemas/mentor-routes.schema.ts diff --git a/src/routes/mentor/mentor.route.ts b/src/routes/mentor/mentor.route.ts index 5456d265..2d56f2b3 100644 --- a/src/routes/mentor/mentor.route.ts +++ b/src/routes/mentor/mentor.route.ts @@ -1,17 +1,33 @@ import express from 'express' +import { + requestBodyValidator, + requestQueryValidator +} from '../../middlewares/requestValidator' +import { + getMenteesByMentorSchema, + mentorApplicationSchema +} from '../../schemas/mentor-routes.schema' import { requireAuth } from './../../controllers/auth.controller' import { + getAllMentorsHandler, + getMenteesByMentor, mentorApplicationHandler, mentorAvailabilityHandler, - mentorDetailsHandler, - getAllMentorsHandler, - getMenteesByMentor + mentorDetailsHandler } from './../../controllers/mentor.controller' const mentorRouter = express.Router() -mentorRouter.post('/', requireAuth, mentorApplicationHandler) -mentorRouter.get('/mentees', requireAuth, getMenteesByMentor) +mentorRouter.post( + '/', + [requireAuth, requestBodyValidator(mentorApplicationSchema)], + mentorApplicationHandler +) +mentorRouter.get( + '/mentees', + [requireAuth, requestQueryValidator(getMenteesByMentorSchema)], + getMenteesByMentor +) mentorRouter.put( '/:mentorId/availability', requireAuth, diff --git a/src/schemas/mentor-routes.schema.ts b/src/schemas/mentor-routes.schema.ts new file mode 100644 index 00000000..416f9879 --- /dev/null +++ b/src/schemas/mentor-routes.schema.ts @@ -0,0 +1,11 @@ +import { z } from 'zod' +import { ApplicationStatus } from '../enums' + +export const mentorApplicationSchema = z.object({ + application: z.record(z.unknown()), + categoryId: z.string() +}) + +export const getMenteesByMentorSchema = z.object({ + status: z.nativeEnum(ApplicationStatus).or(z.undefined()) +}) From 8ab877af85c72369f58612b8b7d681ffc27d9157 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Fri, 2 Aug 2024 20:34:34 +0530 Subject: [PATCH 07/18] add mentee routes --- src/routes/mentee/mentee.route.ts | 21 +++++++++++++++++---- src/schemas/mentee-routes.schemas.ts | 11 +++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/schemas/mentee-routes.schemas.ts diff --git a/src/routes/mentee/mentee.route.ts b/src/routes/mentee/mentee.route.ts index bdce9250..376ad813 100644 --- a/src/routes/mentee/mentee.route.ts +++ b/src/routes/mentee/mentee.route.ts @@ -1,15 +1,28 @@ import express from 'express' import { requireAuth } from '../../controllers/auth.controller' import { + getMenteeDetails, menteeApplicationHandler, - updateMenteeStatus, - getMenteeDetails + updateMenteeStatus } from '../../controllers/mentee.controller' +import { requestBodyValidator } from '../../middlewares/requestValidator' +import { + menteeApplicationSchema, + updateMenteeStatusSchema +} from '../../schemas/mentee-routes.schemas' const menteeRouter = express.Router() -menteeRouter.post('/', requireAuth, menteeApplicationHandler) +menteeRouter.post( + '/', + [requireAuth, requestBodyValidator(menteeApplicationSchema)], + menteeApplicationHandler +) menteeRouter.get('/:menteeId', getMenteeDetails) -menteeRouter.put('/:menteeId/status/', requireAuth, updateMenteeStatus) +menteeRouter.put( + '/:menteeId/status/', + [requireAuth, requestBodyValidator(updateMenteeStatusSchema)], + updateMenteeStatus +) export default menteeRouter diff --git a/src/schemas/mentee-routes.schemas.ts b/src/schemas/mentee-routes.schemas.ts new file mode 100644 index 00000000..7e0abee6 --- /dev/null +++ b/src/schemas/mentee-routes.schemas.ts @@ -0,0 +1,11 @@ +import { z } from 'zod' +import { ApplicationStatus } from '../enums' + +export const menteeApplicationSchema = z.object({ + application: z.record(z.unknown()), + mentorId: z.string() +}) + +export const updateMenteeStatusSchema = z.object({ + state: z.nativeEnum(ApplicationStatus) +}) From ad0690b5f5e9534a76761bab7090e0a38eeefc43 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Fri, 2 Aug 2024 20:34:47 +0530 Subject: [PATCH 08/18] add emails routes --- src/routes/emails/emails.route.ts | 8 +++++++- src/schemas/email-routes.schema.ts | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/schemas/email-routes.schema.ts diff --git a/src/routes/emails/emails.route.ts b/src/routes/emails/emails.route.ts index d52fc8ee..fc896827 100644 --- a/src/routes/emails/emails.route.ts +++ b/src/routes/emails/emails.route.ts @@ -1,9 +1,15 @@ import express from 'express' import { sendEmailController } from '../../controllers/admin/email.controller' import { requireAuth } from '../../controllers/auth.controller' +import { requestBodyValidator } from '../../middlewares/requestValidator' +import { sendEmailSchema } from '../../schemas/email-routes.schema' const emailRouter = express.Router() -emailRouter.post('/send', requireAuth, sendEmailController) +emailRouter.post( + '/send', + [requireAuth, requestBodyValidator(sendEmailSchema)], + sendEmailController +) export default emailRouter diff --git a/src/schemas/email-routes.schema.ts b/src/schemas/email-routes.schema.ts new file mode 100644 index 00000000..9ccd4453 --- /dev/null +++ b/src/schemas/email-routes.schema.ts @@ -0,0 +1,7 @@ +import { z } from 'zod' + +export const sendEmailSchema = z.object({ + subject: z.string(), + to: z.string(), + text: z.string() +}) From e0a49ef4d40c82b589fba4588464f27652ef50ec Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Fri, 2 Aug 2024 20:44:45 +0530 Subject: [PATCH 09/18] add admin category schemas --- src/routes/admin/category/category.route.ts | 19 ++++++++++++++++--- .../admin/admin.category-routes.schema.ts | 9 +++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/schemas/admin/admin.category-routes.schema.ts diff --git a/src/routes/admin/category/category.route.ts b/src/routes/admin/category/category.route.ts index 3b7b1d01..d5169893 100644 --- a/src/routes/admin/category/category.route.ts +++ b/src/routes/admin/category/category.route.ts @@ -1,13 +1,26 @@ import express from 'express' -import { requireAuth } from '../../../controllers/auth.controller' import { addCategory, updateCategory } from '../../../controllers/admin/category.controller' +import { requireAuth } from '../../../controllers/auth.controller' +import { requestBodyValidator } from '../../../middlewares/requestValidator' +import { + addCategorySchema, + updateCategorySchema +} from '../../../schemas/admin/admin.category-routes.schema' const categoryRouter = express.Router() -categoryRouter.post('/', requireAuth, addCategory) -categoryRouter.put('/:categoryId', requireAuth, updateCategory) +categoryRouter.post( + '/', + [requireAuth, requestBodyValidator(addCategorySchema)], + addCategory +) +categoryRouter.put( + '/:categoryId', + [requireAuth, requestBodyValidator(updateCategorySchema)], + updateCategory +) export default categoryRouter diff --git a/src/schemas/admin/admin.category-routes.schema.ts b/src/schemas/admin/admin.category-routes.schema.ts new file mode 100644 index 00000000..f357674a --- /dev/null +++ b/src/schemas/admin/admin.category-routes.schema.ts @@ -0,0 +1,9 @@ +import { z } from 'zod' + +export const addCategorySchema = z.object({ + categoryName: z.string() +}) + +export const updateCategorySchema = z.object({ + categoryName: z.string() +}) From 7a8d6638f2ef0833307fcd78dd676e7090c81076 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Fri, 2 Aug 2024 20:45:33 +0530 Subject: [PATCH 10/18] add mentee route validations --- src/routes/admin/mentee/mentee.route.ts | 35 +++++++++++++++---- .../admin/admin.mentee-routes.schema.ts | 14 ++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 src/schemas/admin/admin.mentee-routes.schema.ts diff --git a/src/routes/admin/mentee/mentee.route.ts b/src/routes/admin/mentee/mentee.route.ts index e06e9054..967808bc 100644 --- a/src/routes/admin/mentee/mentee.route.ts +++ b/src/routes/admin/mentee/mentee.route.ts @@ -1,17 +1,38 @@ import express from 'express' -import { requireAuth } from '../../../controllers/auth.controller' import { - getMentees, - updateMenteeStatus, getAllMenteeEmails, - getMenteeDetails + getMenteeDetails, + getMentees, + updateMenteeStatus } from '../../../controllers/admin/mentee.controller' +import { requireAuth } from '../../../controllers/auth.controller' +import { + requestBodyValidator, + requestQueryValidator +} from '../../../middlewares/requestValidator' +import { + getAllMenteeEmailsSchema, + getMenteesSchema, + updateMenteeStatusSchema +} from '../../../schemas/admin/admin.mentee-routes.schema' const menteeRouter = express.Router() -menteeRouter.get('/emails/', requireAuth, getAllMenteeEmails) -menteeRouter.get('/applications', requireAuth, getMentees) +menteeRouter.get( + '/emails/', + [requireAuth, requestQueryValidator(getAllMenteeEmailsSchema)], + getAllMenteeEmails +) +menteeRouter.get( + '/applications', + [requireAuth, requestQueryValidator(getMenteesSchema)], + getMentees +) menteeRouter.get('/:menteeId', requireAuth, getMenteeDetails) -menteeRouter.put('/:menteeId/state', requireAuth, updateMenteeStatus) +menteeRouter.put( + '/:menteeId/state', + [requireAuth, requestBodyValidator(updateMenteeStatusSchema)], + updateMenteeStatus +) export default menteeRouter diff --git a/src/schemas/admin/admin.mentee-routes.schema.ts b/src/schemas/admin/admin.mentee-routes.schema.ts new file mode 100644 index 00000000..73293b99 --- /dev/null +++ b/src/schemas/admin/admin.mentee-routes.schema.ts @@ -0,0 +1,14 @@ +import { z } from 'zod' +import { ApplicationStatus } from '../../enums' + +export const getAllMenteeEmailsSchema = z.object({ + status: z.nativeEnum(ApplicationStatus) +}) + +export const getMenteesSchema = z.object({ + state: z.nativeEnum(ApplicationStatus) +}) + +export const updateMenteeStatusSchema = z.object({ + state: z.nativeEnum(ApplicationStatus) +}) From 5d89d5803d3fdc1b79653290cbd390d4957a1efe Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Fri, 2 Aug 2024 21:17:23 +0530 Subject: [PATCH 11/18] admin mentor routes schema validations --- src/routes/admin/mentor/mentor.route.ts | 39 ++++++++++++++++--- .../admin/admin.mentor-routes.schema.ts | 22 +++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/schemas/admin/admin.mentor-routes.schema.ts diff --git a/src/routes/admin/mentor/mentor.route.ts b/src/routes/admin/mentor/mentor.route.ts index 0f63beb9..bc98b8b2 100644 --- a/src/routes/admin/mentor/mentor.route.ts +++ b/src/routes/admin/mentor/mentor.route.ts @@ -1,5 +1,4 @@ import express from 'express' -import { requireAuth } from '../../../controllers/auth.controller' import { getAllMentorEmails, getAllMentorsByStatus, @@ -8,18 +7,46 @@ import { searchMentors, updateMentorAvailability } from '../../../controllers/admin/mentor.controller' +import { requireAuth } from '../../../controllers/auth.controller' +import { + requestBodyValidator, + requestQueryValidator +} from '../../../middlewares/requestValidator' +import { + getAllMentorEmailsSchema, + getAllMentorsByStatusSchema, + mentorStatusSchema, + searchMentorsSchema, + updateMentorAvailabilitySchema +} from '../../../schemas/admin/admin.mentor-routes.schema' const mentorRouter = express.Router() -mentorRouter.put('/:mentorId/state', requireAuth, mentorStatusHandler) +mentorRouter.put( + '/:mentorId/state', + [requireAuth, requestBodyValidator(mentorStatusSchema)], + mentorStatusHandler +) mentorRouter.get('/:mentorId', requireAuth, mentorDetailsHandler) -mentorRouter.get('/', requireAuth, getAllMentorsByStatus) -mentorRouter.get('/emails', requireAuth, getAllMentorEmails) +mentorRouter.get( + '/', + [requireAuth, requestQueryValidator(getAllMentorsByStatusSchema)], + getAllMentorsByStatus +) +mentorRouter.get( + '/emails', + [requireAuth, requestQueryValidator(getAllMentorEmailsSchema)], + getAllMentorEmails +) mentorRouter.put( '/:mentorId/availability', - requireAuth, + [requireAuth, requestBodyValidator(updateMentorAvailabilitySchema)], updateMentorAvailability ) -mentorRouter.get('/search', requireAuth, searchMentors) +mentorRouter.get( + '/search', + [requireAuth, requestQueryValidator(searchMentorsSchema)], + searchMentors +) export default mentorRouter diff --git a/src/schemas/admin/admin.mentor-routes.schema.ts b/src/schemas/admin/admin.mentor-routes.schema.ts new file mode 100644 index 00000000..9c21fbef --- /dev/null +++ b/src/schemas/admin/admin.mentor-routes.schema.ts @@ -0,0 +1,22 @@ +import { z } from 'zod' +import { ApplicationStatus } from '../../enums' + +export const mentorStatusSchema = z.object({ + state: z.nativeEnum(ApplicationStatus) +}) + +export const getAllMentorsByStatusSchema = z.object({ + status: z.nativeEnum(ApplicationStatus).or(z.undefined()) +}) + +export const getAllMentorEmailsSchema = z.object({ + status: z.nativeEnum(ApplicationStatus).or(z.undefined()) +}) + +export const updateMentorAvailabilitySchema = z.object({ + availability: z.boolean() +}) + +export const searchMentorsSchema = z.object({ + q: z.string().or(z.undefined()) +}) From 46735348c3c7b8b908f1386016495cf420f6ca4a Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Sat, 3 Aug 2024 06:33:10 +0530 Subject: [PATCH 12/18] update zod schema type --- src/middlewares/requestValidator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlewares/requestValidator.ts b/src/middlewares/requestValidator.ts index 9887d729..17d00653 100644 --- a/src/middlewares/requestValidator.ts +++ b/src/middlewares/requestValidator.ts @@ -1,4 +1,4 @@ -import { ZodError, ZodSchema } from 'zod' +import { ZodError, type ZodSchema } from 'zod' export const requestBodyValidator = (schema: ZodSchema) => { return (req: any, res: any, next: any) => { From 0394007c5086a34d84ee4cf1c1b9a70f1c3796fe Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Mon, 5 Aug 2024 09:15:49 +0530 Subject: [PATCH 13/18] update req res next parameters types --- src/middlewares/requestValidator.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/middlewares/requestValidator.ts b/src/middlewares/requestValidator.ts index 17d00653..f3eefc8b 100644 --- a/src/middlewares/requestValidator.ts +++ b/src/middlewares/requestValidator.ts @@ -1,7 +1,8 @@ +import { NextFunction, Request, Response } from 'express' import { ZodError, type ZodSchema } from 'zod' export const requestBodyValidator = (schema: ZodSchema) => { - return (req: any, res: any, next: any) => { + return (req: Request, res: Response, next: NextFunction) => { try { schema.parse(req.body) next() @@ -21,7 +22,7 @@ export const requestBodyValidator = (schema: ZodSchema) => { } export const requestQueryValidator = (schema: ZodSchema) => { - return (req: any, res: any, next: any) => { + return (req: Request, res: Response, next: NextFunction) => { try { schema.parse(req.query) next() From 5c8178d4b4aa713563cd336c350ec5082e508a90 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Mon, 5 Aug 2024 09:20:57 +0530 Subject: [PATCH 14/18] update types --- src/middlewares/requestValidator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middlewares/requestValidator.ts b/src/middlewares/requestValidator.ts index f3eefc8b..4a2cd724 100644 --- a/src/middlewares/requestValidator.ts +++ b/src/middlewares/requestValidator.ts @@ -1,4 +1,4 @@ -import { NextFunction, Request, Response } from 'express' +import { type NextFunction, type Request, type Response } from 'express' import { ZodError, type ZodSchema } from 'zod' export const requestBodyValidator = (schema: ZodSchema) => { From 102cc88834df1ca74345d9e6765df9db647c2ebe Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Mon, 5 Aug 2024 09:24:37 +0530 Subject: [PATCH 15/18] update mentee application status --- src/schemas/admin/admin.mentee-routes.schema.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/schemas/admin/admin.mentee-routes.schema.ts b/src/schemas/admin/admin.mentee-routes.schema.ts index 73293b99..336f3ee4 100644 --- a/src/schemas/admin/admin.mentee-routes.schema.ts +++ b/src/schemas/admin/admin.mentee-routes.schema.ts @@ -1,14 +1,14 @@ import { z } from 'zod' -import { ApplicationStatus } from '../../enums' +import { MenteeApplicationStatus } from '../../enums' export const getAllMenteeEmailsSchema = z.object({ - status: z.nativeEnum(ApplicationStatus) + status: z.nativeEnum(MenteeApplicationStatus) }) export const getMenteesSchema = z.object({ - state: z.nativeEnum(ApplicationStatus) + state: z.nativeEnum(MenteeApplicationStatus) }) export const updateMenteeStatusSchema = z.object({ - state: z.nativeEnum(ApplicationStatus) + state: z.nativeEnum(MenteeApplicationStatus) }) From 0ae93a06265491266ecb2ae3a3c7079a3af8892f Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Mon, 5 Aug 2024 09:24:44 +0530 Subject: [PATCH 16/18] update mentor application status --- src/schemas/admin/admin.mentor-routes.schema.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/schemas/admin/admin.mentor-routes.schema.ts b/src/schemas/admin/admin.mentor-routes.schema.ts index 9c21fbef..64006cf2 100644 --- a/src/schemas/admin/admin.mentor-routes.schema.ts +++ b/src/schemas/admin/admin.mentor-routes.schema.ts @@ -1,16 +1,16 @@ import { z } from 'zod' -import { ApplicationStatus } from '../../enums' +import { MentorApplicationStatus } from '../../enums' export const mentorStatusSchema = z.object({ - state: z.nativeEnum(ApplicationStatus) + state: z.nativeEnum(MentorApplicationStatus) }) export const getAllMentorsByStatusSchema = z.object({ - status: z.nativeEnum(ApplicationStatus).or(z.undefined()) + status: z.nativeEnum(MentorApplicationStatus).or(z.undefined()) }) export const getAllMentorEmailsSchema = z.object({ - status: z.nativeEnum(ApplicationStatus).or(z.undefined()) + status: z.nativeEnum(MentorApplicationStatus).or(z.undefined()) }) export const updateMentorAvailabilitySchema = z.object({ From cb4facd5fc16688a654419db360706c36e5db68a Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Mon, 5 Aug 2024 09:25:51 +0530 Subject: [PATCH 17/18] update public mentor and mentee routes --- src/schemas/mentee-routes.schemas.ts | 4 ++-- src/schemas/mentor-routes.schema.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/schemas/mentee-routes.schemas.ts b/src/schemas/mentee-routes.schemas.ts index 7e0abee6..0f6d2878 100644 --- a/src/schemas/mentee-routes.schemas.ts +++ b/src/schemas/mentee-routes.schemas.ts @@ -1,5 +1,5 @@ import { z } from 'zod' -import { ApplicationStatus } from '../enums' +import { MenteeApplicationStatus } from '../enums' export const menteeApplicationSchema = z.object({ application: z.record(z.unknown()), @@ -7,5 +7,5 @@ export const menteeApplicationSchema = z.object({ }) export const updateMenteeStatusSchema = z.object({ - state: z.nativeEnum(ApplicationStatus) + state: z.nativeEnum(MenteeApplicationStatus) }) diff --git a/src/schemas/mentor-routes.schema.ts b/src/schemas/mentor-routes.schema.ts index 416f9879..751bb065 100644 --- a/src/schemas/mentor-routes.schema.ts +++ b/src/schemas/mentor-routes.schema.ts @@ -1,5 +1,5 @@ import { z } from 'zod' -import { ApplicationStatus } from '../enums' +import { MentorApplicationStatus } from '../enums' export const mentorApplicationSchema = z.object({ application: z.record(z.unknown()), @@ -7,5 +7,5 @@ export const mentorApplicationSchema = z.object({ }) export const getMenteesByMentorSchema = z.object({ - status: z.nativeEnum(ApplicationStatus).or(z.undefined()) + status: z.nativeEnum(MentorApplicationStatus).or(z.undefined()) }) From d5fdf0b5d29e3bdde70bd06da486293a3e06f232 Mon Sep 17 00:00:00 2001 From: Dileepa Mabulage Date: Mon, 5 Aug 2024 09:35:46 +0530 Subject: [PATCH 18/18] update zod types validation --- src/middlewares/requestValidator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/middlewares/requestValidator.ts b/src/middlewares/requestValidator.ts index 4a2cd724..6545928c 100644 --- a/src/middlewares/requestValidator.ts +++ b/src/middlewares/requestValidator.ts @@ -1,7 +1,7 @@ import { type NextFunction, type Request, type Response } from 'express' import { ZodError, type ZodSchema } from 'zod' -export const requestBodyValidator = (schema: ZodSchema) => { +export const requestBodyValidator = (schema: T) => { return (req: Request, res: Response, next: NextFunction) => { try { schema.parse(req.body) @@ -21,7 +21,7 @@ export const requestBodyValidator = (schema: ZodSchema) => { } } -export const requestQueryValidator = (schema: ZodSchema) => { +export const requestQueryValidator = (schema: T) => { return (req: Request, res: Response, next: NextFunction) => { try { schema.parse(req.query)