Mega push vol 5, working on messaging now

This commit is contained in:
AlacrisDevs
2026-02-07 01:31:55 +02:00
parent d8bbfd9dc3
commit e55881b38b
77 changed files with 8478 additions and 1554 deletions

View File

@@ -1,11 +1,14 @@
import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import type { OrgLayoutData } from '$lib/types/layout';
import { createLogger } from '$lib/utils/logger';
import { getServiceAccountEmail } from '$lib/api/google-calendar-push';
import { env } from '$env/dynamic/private';
const log = createLogger('page.settings');
export const load: PageServerLoad = async ({ parent, locals }) => {
const { org, userRole } = await parent() as { org: { id: string; slug: string }; userRole: string };
const { org, userRole } = await parent() as OrgLayoutData;
// Only admins and owners can access settings
if (userRole !== 'owner' && userRole !== 'admin') {
@@ -16,22 +19,10 @@ export const load: PageServerLoad = async ({ parent, locals }) => {
// Fetch all settings data in parallel
const [membersResult, rolesResult, invitesResult, calendarResult] = await Promise.all([
// Get org members with profiles
// Get org members (without embedded profile join — FK points to auth.users, not profiles)
locals.supabase
.from('org_members')
.select(`
id,
user_id,
role,
role_id,
created_at,
profiles:user_id (
id,
email,
full_name,
avatar_url
)
`)
.select('id, user_id, role, role_id, invited_at')
.eq('org_id', orgId),
// Get org roles
locals.supabase
@@ -54,11 +45,41 @@ export const load: PageServerLoad = async ({ parent, locals }) => {
.single()
]);
if (membersResult.error) {
log.error('Failed to fetch members', { error: membersResult.error, data: { orgId } });
}
// Fetch profiles separately since org_members.user_id FK points to auth.users, not profiles
const rawMembers = membersResult.data ?? [];
const userIds = rawMembers.map(m => m.user_id).filter((id): id is string => id !== null);
let profilesMap: Record<string, { id: string; email: string; full_name: string | null; avatar_url: string | null }> = {};
if (userIds.length > 0) {
const { data: profiles } = await locals.supabase
.from('profiles')
.select('id, email, full_name, avatar_url')
.in('id', userIds);
if (profiles) {
profilesMap = Object.fromEntries(profiles.map(p => [p.id, p]));
}
}
const members = rawMembers.map(m => ({
...m,
profiles: (m.user_id ? profilesMap[m.user_id] : null) ?? null
}));
const serviceAccountEmail = env.GOOGLE_SERVICE_ACCOUNT_KEY
? getServiceAccountEmail(env.GOOGLE_SERVICE_ACCOUNT_KEY)
: null;
return {
members: membersResult.data ?? [],
members,
roles: rolesResult.data ?? [],
invites: invitesResult.data ?? [],
orgCalendar: calendarResult.data,
serviceAccountEmail,
userRole
};
};