fix: unwrap PostgREST proxy response format for pointCode
This commit is contained in:
@@ -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 codeMap: Record<string, string> = {};
|
const raw = resp.data;
|
||||||
resp.data.forEach((ep: any) => { if (ep.code) codeMap[String(ep.id)] = ep.code; });
|
const epList = Array.isArray(raw) ? raw : (raw?.data && Array.isArray(raw.data) ? raw.data : []);
|
||||||
points.forEach((p: any) => { p.pointCode = codeMap[String(p.pointId)] || ''; });
|
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) {
|
} catch (e) {
|
||||||
console.error('[Reviews Loader] patchPointCodes error:', e);
|
console.error('[Reviews Loader] patchPointCodes error:', e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user