eedfd3ecec
- Add RecurringPayment model with flexible scheduling options - Implement node-cron based scheduler for payment processing - Create API endpoints for CRUD operations on recurring payments - Add recurring payments management UI with create/edit forms - Integrate scheduler initialization in hooks.server.ts - Enhance payments/add form with progressive enhancement - Add recurring payments button to main dashboard - Improve server-side rendering for better performance
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import type { PageServerLoad } from './$types';
|
|
import { redirect, error } from '@sveltejs/kit';
|
|
|
|
export const load: PageServerLoad = async ({ locals, fetch, url }) => {
|
|
const session = await locals.auth();
|
|
|
|
if (!session) {
|
|
throw redirect(302, '/login');
|
|
}
|
|
|
|
try {
|
|
// Get pagination params from URL
|
|
const limit = parseInt(url.searchParams.get('limit') || '20');
|
|
const offset = parseInt(url.searchParams.get('offset') || '0');
|
|
|
|
// Fetch payments data server-side using existing API
|
|
const paymentsResponse = await fetch(`/api/cospend/payments?limit=${limit}&offset=${offset}`);
|
|
if (!paymentsResponse.ok) {
|
|
throw new Error('Failed to fetch payments');
|
|
}
|
|
const paymentsData = await paymentsResponse.json();
|
|
|
|
return {
|
|
session,
|
|
payments: paymentsData.payments,
|
|
hasMore: paymentsData.payments.length === limit,
|
|
currentOffset: offset,
|
|
limit
|
|
};
|
|
} catch (e) {
|
|
console.error('Error loading payments data:', e);
|
|
throw error(500, 'Failed to load payments data');
|
|
}
|
|
}; |