Skip to content

Commit

Permalink
Add mentees counts on mentor application (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Disura-Randunu authored Oct 19, 2024
1 parent 91b32c5 commit 548406e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/services/mentor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 13 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 548406e

Please sign in to comment.