added todos | payday time settings | refactor payment scheduling

This commit is contained in:
JCEEE
2026-08-04 08:34:14 +01:00
parent ccbbd302d4
commit 85ea97ae96
16 changed files with 2877 additions and 659 deletions
+34 -12
View File
@@ -2,26 +2,48 @@ import { SERVER_IP, PROXY_PORT } from '../../../../config.ts';
const HONO_URL = `http://${SERVER_IP}:${PROXY_PORT}`;
async function paydayCheck(famId: string, headers: Record<string, string>) {
try {
const res = await fetch(`${HONO_URL}/api/fam/${famId}/payday`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...headers
}
});
// Best-effort: never block render on the payday heartbeat.
await res.json().catch(() => null);
} catch {}
}
export async function load(event) {
const session = event.locals.session || null;
const isParent = session !== null;
const deviceToken = event.cookies.get('device_token') || '';
let famId = '';
if (isParent) {
famId = session.famId;
} else {
const deviceToken = event.cookies.get('device_token') || '';
if (deviceToken) {
try {
const res = await fetch(`${HONO_URL}/api/members/seasons`, {
headers: { 'x-device-token': deviceToken },
});
if (res.ok) {
const body = await res.json();
famId = body.famId || '';
}
} catch {}
await paydayCheck(famId, {
'x-session-famid': session.famId,
'x-session-userid': session.userId
});
} else if (deviceToken) {
try {
const res = await fetch(`${HONO_URL}/api/members/seasons`, {
headers: { 'x-device-token': deviceToken }
});
if (res.ok) {
const body = await res.json();
famId = body.famId || '';
}
} catch {}
if (famId) {
await paydayCheck(famId, {
'x-device-token': deviceToken,
'x-device-famid': famId
});
}
}