Mega push vol 4
This commit is contained in:
@@ -8,6 +8,7 @@ export const load: LayoutServerLoad = async ({ params, locals }) => {
|
||||
error(401, 'Unauthorized');
|
||||
}
|
||||
|
||||
// Fetch org first (need org.id for subsequent queries)
|
||||
const { data: org, error: orgError } = await locals.supabase
|
||||
.from('organizations')
|
||||
.select('*')
|
||||
@@ -18,58 +19,62 @@ export const load: LayoutServerLoad = async ({ params, locals }) => {
|
||||
error(404, 'Organization not found');
|
||||
}
|
||||
|
||||
const { data: membership } = await locals.supabase
|
||||
.from('org_members')
|
||||
.select('role')
|
||||
.eq('org_id', org.id)
|
||||
.eq('user_id', user.id)
|
||||
.single();
|
||||
// Now fetch membership, members, and activity in parallel (all depend on org.id)
|
||||
const [membershipResult, membersResult, activityResult] = await Promise.all([
|
||||
locals.supabase
|
||||
.from('org_members')
|
||||
.select('role')
|
||||
.eq('org_id', org.id)
|
||||
.eq('user_id', user.id)
|
||||
.single(),
|
||||
locals.supabase
|
||||
.from('org_members')
|
||||
.select(`
|
||||
id,
|
||||
user_id,
|
||||
role,
|
||||
profiles:user_id (
|
||||
id,
|
||||
email,
|
||||
full_name,
|
||||
avatar_url
|
||||
)
|
||||
`)
|
||||
.eq('org_id', org.id)
|
||||
.limit(10),
|
||||
locals.supabase
|
||||
.from('activity_log')
|
||||
.select(`
|
||||
id,
|
||||
action,
|
||||
entity_type,
|
||||
entity_id,
|
||||
entity_name,
|
||||
created_at,
|
||||
profiles:user_id (
|
||||
full_name,
|
||||
email
|
||||
)
|
||||
`)
|
||||
.eq('org_id', org.id)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(10)
|
||||
]);
|
||||
|
||||
const { data: membership } = membershipResult;
|
||||
const { data: members } = membersResult;
|
||||
const { data: recentActivity } = activityResult;
|
||||
|
||||
if (!membership) {
|
||||
error(403, 'You are not a member of this organization');
|
||||
}
|
||||
|
||||
// Fetch team members for sidebar
|
||||
const { data: members } = await locals.supabase
|
||||
.from('org_members')
|
||||
.select(`
|
||||
id,
|
||||
user_id,
|
||||
role,
|
||||
profiles:user_id (
|
||||
id,
|
||||
email,
|
||||
full_name,
|
||||
avatar_url
|
||||
)
|
||||
`)
|
||||
.eq('org_id', org.id)
|
||||
.limit(10);
|
||||
|
||||
// Fetch recent activity
|
||||
const { data: recentActivity } = await locals.supabase
|
||||
.from('activity_log')
|
||||
.select(`
|
||||
id,
|
||||
action,
|
||||
entity_type,
|
||||
entity_id,
|
||||
entity_name,
|
||||
created_at,
|
||||
profiles:user_id (
|
||||
full_name,
|
||||
email
|
||||
)
|
||||
`)
|
||||
.eq('org_id', org.id)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(10);
|
||||
|
||||
return {
|
||||
org,
|
||||
role: membership.role,
|
||||
userRole: membership.role,
|
||||
userRole: membership.role, // kept for backwards compat — same as role
|
||||
members: members ?? [],
|
||||
recentActivity: recentActivity ?? []
|
||||
recentActivity: recentActivity ?? [],
|
||||
user
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user