You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
877 B
31 lines
877 B
import type { PageServerLoad } from './$types'; |
|
import { createLogger } from '$lib/utils/logger'; |
|
|
|
const log = createLogger('page.calendar'); |
|
|
|
export const load: PageServerLoad = async ({ parent, locals }) => { |
|
const { org, userRole } = await parent(); |
|
const { supabase } = locals; |
|
|
|
// Fetch events for current month ± 1 month |
|
const now = new Date(); |
|
const startDate = new Date(now.getFullYear(), now.getMonth() - 1, 1); |
|
const endDate = new Date(now.getFullYear(), now.getMonth() + 2, 0); |
|
|
|
const { data: events, error } = await supabase |
|
.from('calendar_events') |
|
.select('*') |
|
.eq('org_id', org.id) |
|
.gte('start_time', startDate.toISOString()) |
|
.lte('end_time', endDate.toISOString()) |
|
.order('start_time'); |
|
|
|
if (error) { |
|
log.error('Failed to load calendar events', { error, data: { orgId: org.id } }); |
|
} |
|
|
|
return { |
|
events: events ?? [], |
|
userRole |
|
}; |
|
};
|
|
|