fix: unwrap PostgREST proxy response format for pointCode
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user