feat(mentor): show co-mentors on workspace page (PR8 Task 9)

- Adds mentor.getProjectMentors({ projectId }) — returns all active
  MentorAssignment rows for a project, authorized to any mentor on it
- Workspace page header surfaces "You + N co-mentor(s): names…" so each
  mentor knows the team composition without having to ask the admin

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt
2026-05-22 17:07:11 +02:00
parent ee47c0305f
commit d440b5f274
2 changed files with 100 additions and 1 deletions

View File

@@ -1326,6 +1326,50 @@ export const mentorRouter = router({
return assignments
}),
/**
* List all active mentors assigned to a project (PR8 multi-mentor).
*
* Returns one row per active MentorAssignment (droppedAt = null) with the
* mentor's id + name. Used by the mentor workspace page to display the
* co-mentor team so each mentor knows who else they're working with.
*
* Authorization: caller must be an active mentor on the project (or an
* admin via mentorProcedure). Non-assigned mentors get FORBIDDEN.
*/
getProjectMentors: mentorProcedure
.input(z.object({ projectId: z.string() }))
.query(async ({ ctx, input }) => {
const isAdmin = ['SUPER_ADMIN', 'PROGRAM_ADMIN'].includes(ctx.user.role)
if (!isAdmin) {
const ownAssignment = await ctx.prisma.mentorAssignment.findFirst({
where: {
projectId: input.projectId,
mentorId: ctx.user.id,
droppedAt: null,
},
select: { id: true },
})
if (!ownAssignment) {
throw new TRPCError({
code: 'FORBIDDEN',
message: 'You are not assigned to mentor this project',
})
}
}
const assignments = await ctx.prisma.mentorAssignment.findMany({
where: { projectId: input.projectId, droppedAt: null },
select: {
id: true,
mentor: { select: { id: true, name: true } },
},
orderBy: { assignedAt: 'asc' },
})
return assignments
}),
/**
* Get detailed project info for a mentor's assigned project
*/