fix: fetch pointCode directly via PostgREST in route loader
Vite tree-shakes pointCode from intermediate data objects. Fix by querying evaluation_points.code directly in the route loader with postgrestGet, then patching pointCode onto reviewPoints before returning to the client. Works for both legacy and GraphRAG paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+23
-19
@@ -31,6 +31,7 @@ import { useNavigate, useLoaderData, useFetcher } from "@remix-run/react";
|
||||
import type { FilePreviewHandle } from "~/components/reviews/FilePreview";
|
||||
import reviewsStyles from "~/styles/reviews.css?url";
|
||||
import { getReviewPoints, getReviewPoints_fromApi, getUnifiedEvaluationResults, updateReviewResult, confirmReviewResults } from "~/api/evaluation_points/reviews";
|
||||
import { postgrestGet } from "~/api/postgrest-client";
|
||||
import { toastService } from "~/components/ui/Toast";
|
||||
|
||||
// 导入评查详情页面组件
|
||||
@@ -190,6 +191,26 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
return Response.json({ result: false, message: '文件ID不能为空' });
|
||||
}
|
||||
|
||||
// 补充 pointCode 到 reviewPoints(直接查 DB,不受 Vite tree-shake 影响)
|
||||
async function patchPointCodes(points: any[], jwt: string) {
|
||||
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', {
|
||||
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)] || ''; });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('[Reviews Loader] patchPointCodes error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户会话信息
|
||||
const { getUserSession } = await import("~/api/login/auth.server");
|
||||
const { userInfo, frontendJWT } = await getUserSession(request);
|
||||
@@ -209,14 +230,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
}
|
||||
|
||||
if ('document' in reviewData && 'data' in reviewData && 'reviewInfo' in reviewData && 'stats' in reviewData) {
|
||||
// 补充 pointCode(Vite tree-shake 会移除 reviews.ts 中的 pointCode)
|
||||
if (reviewData.pointCodeMap) {
|
||||
(reviewData.data as any[]).forEach((p: any) => {
|
||||
if (!p.pointCode && p.pointId && reviewData.pointCodeMap[p.pointId]) {
|
||||
p.pointCode = reviewData.pointCodeMap[p.pointId];
|
||||
}
|
||||
});
|
||||
}
|
||||
await patchPointCodes(reviewData.data as any[], frontendJWT);
|
||||
return Response.json({
|
||||
previousRoute: previousRoute,
|
||||
document: reviewData.document,
|
||||
@@ -264,17 +278,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
||||
postAction: '',
|
||||
}));
|
||||
const allReviewPoints = [...existingPoints, ...notApplicablePoints];
|
||||
|
||||
// 补充 pointCode(从统一接口的 scored results 获取 code)
|
||||
const codeMap = new Map<number, string>();
|
||||
(unifiedData.results || []).forEach((r: any) => {
|
||||
if (r.evaluation_point_id && r.code) codeMap.set(r.evaluation_point_id, r.code);
|
||||
});
|
||||
allReviewPoints.forEach((p: any) => {
|
||||
if (!p.pointCode && p.pointId && codeMap.has(Number(p.pointId))) {
|
||||
p.pointCode = codeMap.get(Number(p.pointId));
|
||||
}
|
||||
});
|
||||
await patchPointCodes(allReviewPoints, frontendJWT);
|
||||
|
||||
return Response.json({
|
||||
previousRoute: previousRoute,
|
||||
|
||||
Reference in New Issue
Block a user