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
+7 -6
View File
@@ -196,16 +196,17 @@ export async function loader({ request }: LoaderFunctionArgs) {
try {
const pointIds = points.map((p: any) => p.pointId).filter(Boolean);
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',
filter: { id: `in.(${[...new Set(pointIds)].join(',')})` },
token: jwt,
});
if (resp.data && Array.isArray(resp.data)) {
const codeMap: Record<string, string> = {};
resp.data.forEach((ep: any) => { if (ep.code) codeMap[String(ep.id)] = ep.code; });
points.forEach((p: any) => { p.pointCode = codeMap[String(p.pointId)] || ''; });
}
// 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> = {};
epList.forEach((ep: any) => { if (ep.code) codeMap[String(ep.id)] = ep.code; });
points.forEach((p: any) => { p.pointCode = codeMap[String(p.pointId)] || ''; });
} catch (e) {
console.error('[Reviews Loader] patchPointCodes error:', e);
}