feat: add team collaboration sessions for admins, enhancing session management and visibility in the application
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { prisma } from '@/services/database';
|
||||
import { resolveCollaborator } from '@/services/auth';
|
||||
import { getTeamMemberIdsForAdminTeams } from '@/services/teams';
|
||||
import type { ShareRole, WeeklyCheckInCategory, Emotion } from '@prisma/client';
|
||||
|
||||
// ============================================
|
||||
@@ -76,6 +77,43 @@ export async function getWeeklyCheckInSessionsByUserId(userId: string) {
|
||||
return sessionsWithResolved;
|
||||
}
|
||||
|
||||
/** Sessions owned by team members (where user is team admin) that are NOT shared with the user. */
|
||||
export async function getTeamCollaboratorSessionsForAdmin(userId: string) {
|
||||
const teamMemberIds = await getTeamMemberIdsForAdminTeams(userId);
|
||||
if (teamMemberIds.length === 0) return [];
|
||||
|
||||
const sessions = await prisma.weeklyCheckInSession.findMany({
|
||||
where: {
|
||||
userId: { in: teamMemberIds },
|
||||
shares: { none: { userId } },
|
||||
},
|
||||
include: {
|
||||
user: { select: { id: true, name: true, email: true } },
|
||||
shares: {
|
||||
include: {
|
||||
user: { select: { id: true, name: true, email: true } },
|
||||
},
|
||||
},
|
||||
_count: { select: { items: true } },
|
||||
},
|
||||
orderBy: { updatedAt: 'desc' },
|
||||
});
|
||||
|
||||
const withRole = sessions.map((s) => ({
|
||||
...s,
|
||||
isOwner: false as const,
|
||||
role: 'VIEWER' as const,
|
||||
isTeamCollab: true as const,
|
||||
}));
|
||||
|
||||
return Promise.all(
|
||||
withRole.map(async (s) => ({
|
||||
...s,
|
||||
resolvedParticipant: await resolveCollaborator(s.participant),
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
export async function getWeeklyCheckInSessionById(sessionId: string, userId: string) {
|
||||
// Check if user owns the session OR has it shared
|
||||
const session = await prisma.weeklyCheckInSession.findFirst({
|
||||
|
||||
Reference in New Issue
Block a user