fix: unwrap PostgREST proxy response format for pointCode

This commit is contained in:
2026-03-23 20:56:27 +08:00
parent 138cb5c606
commit 5d3cb2ba34
+5 -4
View File
@@ -196,16 +196,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
try { try {
const pointIds = points.map((p: any) => p.pointId).filter(Boolean); const pointIds = points.map((p: any) => p.pointId).filter(Boolean);
if (pointIds.length === 0) return; if (pointIds.length === 0) return;
const resp = await postgrestGet<any[]>('/api/postgrest/proxy/evaluation_points', { const resp = await postgrestGet<any>('/api/postgrest/proxy/evaluation_points', {
select: 'id,code', select: 'id,code',
filter: { id: `in.(${[...new Set(pointIds)].join(',')})` }, filter: { id: `in.(${[...new Set(pointIds)].join(',')})` },
token: jwt, token: jwt,
}); });
if (resp.data && Array.isArray(resp.data)) { // resp.data 可能是 {code:200, data:[...]} 或直接 [...]
const raw = resp.data;
const epList = Array.isArray(raw) ? raw : (raw?.data && Array.isArray(raw.data) ? raw.data : []);
const codeMap: Record<string, string> = {}; const codeMap: Record<string, string> = {};
resp.data.forEach((ep: any) => { if (ep.code) codeMap[String(ep.id)] = ep.code; }); epList.forEach((ep: any) => { if (ep.code) codeMap[String(ep.id)] = ep.code; });
points.forEach((p: any) => { p.pointCode = codeMap[String(p.pointId)] || ''; }); points.forEach((p: any) => { p.pointCode = codeMap[String(p.pointId)] || ''; });
}
} catch (e) { } catch (e) {
console.error('[Reviews Loader] patchPointCodes error:', e); console.error('[Reviews Loader] patchPointCodes error:', e);
} }