From 548406ef22d3af1f990f0638a01263976c6862db Mon Sep 17 00:00:00 2001 From: Disura Randunu <37591051+Disura-Randunu@users.noreply.github.com> Date: Sat, 19 Oct 2024 20:09:27 +0530 Subject: [PATCH] Add mentees counts on mentor application (#175) --- src/services/mentor.service.ts | 2 +- src/utils.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/mentor.service.ts b/src/services/mentor.service.ts index 120d6be..bded9c3 100644 --- a/src/services/mentor.service.ts +++ b/src/services/mentor.service.ts @@ -256,7 +256,7 @@ export const getAllMentors = async ({ state: MentorApplicationStatus.APPROVED } : { state: MentorApplicationStatus.APPROVED }, - relations: ['profile', 'category'], + relations: ['profile', 'category', 'mentees', 'mentees.profile'], select: ['application', 'uuid', 'availability'], order: { availability: 'DESC' diff --git a/src/utils.ts b/src/utils.ts index 51d1a0f..cb90429 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -34,12 +34,24 @@ export const getMentorPublicData = (mentor: Mentor): Mentor => { delete profile.created_at delete profile.updated_at + let appliedMenteesCount = 0 + let availableMenteeSlots = mentor.application.noOfMentees as number + if (mentor.mentees) { + appliedMenteesCount = mentor.mentees.length + let approvedMenteesCount = 0 + mentor.mentees = mentor.mentees.map((mentee) => { + if (mentee.state === MenteeApplicationStatus.APPROVED) { + approvedMenteesCount++ + } return getMenteePublicData(mentee) }) - } + availableMenteeSlots -= approvedMenteesCount + } + mentor.application.appliedMenteesCount = appliedMenteesCount + mentor.application.availableMenteeSlots = availableMenteeSlots return mentor }