add debugging
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import type { RequestEvent } from '@sveltejs/kit';
|
||||
import { createPbClient, pbAdmin } from '$lib/server/pocketbase';
|
||||
|
||||
// TEMP diagnostic for the recurring prod CHORE_GONE. Compares what the client
|
||||
// claims against server truth from both angles (superuser getOne — the toggle
|
||||
// path — and the user's own list read — the kanban path). Authenticated,
|
||||
// own-fam only, no tokens ever logged or returned.
|
||||
export async function GET(event: RequestEvent) {
|
||||
const u = event.locals.user;
|
||||
if (!u || !event.locals.pbToken) throw error(401, 'Unauthorized');
|
||||
const assignedChoreId = event.url.searchParams.get('assignedChoreId') || '';
|
||||
|
||||
let suChore: any = null;
|
||||
let suError = '';
|
||||
if (assignedChoreId) {
|
||||
try {
|
||||
suChore = await pbAdmin.getOne('assigned_chores', assignedChoreId);
|
||||
} catch (e) {
|
||||
suError = e instanceof Error ? e.message : String(e);
|
||||
}
|
||||
}
|
||||
|
||||
let userSeesIt: boolean | null = null;
|
||||
let userListError = '';
|
||||
try {
|
||||
const pb = createPbClient(event.locals.pbToken);
|
||||
const list = await pb
|
||||
.collection('assigned_chores')
|
||||
.getFullList({ filter: `famId = '${u.famId}'` });
|
||||
if (assignedChoreId) userSeesIt = list.some((a: any) => a.id === assignedChoreId);
|
||||
} catch (e) {
|
||||
userListError = e instanceof Error ? e.message : String(e);
|
||||
}
|
||||
|
||||
const out = {
|
||||
session: { id: u.id, role: u.role, famId: u.famId },
|
||||
asked: assignedChoreId,
|
||||
superuser: suChore
|
||||
? {
|
||||
found: true,
|
||||
famId: suChore.famId,
|
||||
memberId: suChore.memberId,
|
||||
isTodo: !!suChore.isTodo,
|
||||
famMatch: suChore.famId === u.famId
|
||||
}
|
||||
: { found: false, error: suError },
|
||||
userList: { seesIt: userSeesIt, error: userListError }
|
||||
};
|
||||
console.log(`[diag] debug-chore ${JSON.stringify(out)}`);
|
||||
return json(out);
|
||||
}
|
||||
Reference in New Issue
Block a user