Files
homepage/src/routes/api/cospend/recurring-payments/scheduler/+server.ts
Alexander Bocken 40a795a30b refactor: remove verbose debug logging from cospend API endpoints
Removed excessive console.log statements from recurring payments processing and monthly expenses aggregation. Error logging (console.error) is retained for troubleshooting.
2025-12-16 16:40:39 +01:00

56 lines
1.5 KiB
TypeScript

import type { RequestHandler } from '@sveltejs/kit';
import { error, json } from '@sveltejs/kit';
import { recurringPaymentScheduler } from '../../../../../lib/server/scheduler';
export const GET: RequestHandler = async ({ locals }) => {
const auth = await locals.auth();
if (!auth || !auth.user?.nickname) {
throw error(401, 'Not logged in');
}
try {
const status = recurringPaymentScheduler.getStatus();
return json({
success: true,
scheduler: status,
message: status.isScheduled ? 'Scheduler is running' : 'Scheduler is stopped'
});
} catch (e) {
console.error('Error getting scheduler status:', e);
throw error(500, 'Failed to get scheduler status');
}
};
export const POST: RequestHandler = async ({ request, locals }) => {
const auth = await locals.auth();
if (!auth || !auth.user?.nickname) {
throw error(401, 'Not logged in');
}
try {
const body = await request.json();
const { action } = body;
switch (action) {
case 'execute':
await recurringPaymentScheduler.executeNow();
return json({
success: true,
message: 'Manual execution completed'
});
case 'status':
const status = recurringPaymentScheduler.getStatus();
return json({
success: true,
scheduler: status
});
default:
throw error(400, 'Invalid action. Use "execute" or "status"');
}
} catch (e) {
console.error('Error in scheduler API:', e);
throw error(500, 'Scheduler operation failed');
}
};