feat: add team collaboration sessions for admins, enhancing session management and visibility in the application
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user