feat: add team collaboration sessions for admins, enhancing session management and visibility in the application

This commit is contained in:
Julien Froidefond
2026-02-17 14:03:31 +01:00
parent 7f3eabbdb2
commit 4e14112ffa
9 changed files with 344 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
import { prisma } from '@/services/database';
import { getTeamMemberIdsForAdminTeams } from '@/services/teams';
import type { ShareRole } from '@prisma/client';
// ============================================
@@ -67,6 +68,36 @@ export async function getWeatherSessionsByUserId(userId: string) {
return allSessions;
}
/** 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.weatherSession.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: { entries: true } },
},
orderBy: { updatedAt: 'desc' },
});
return sessions.map((s) => ({
...s,
isOwner: false as const,
role: 'VIEWER' as const,
isTeamCollab: true as const,
}));
}
export async function getWeatherSessionById(sessionId: string, userId: string) {
// Check if user owns the session OR has it shared
const session = await prisma.weatherSession.findFirst({