261026_01_ENH: 사내 연동 API 추가 및 SurveyProgress 전환·문자열 필터 지원
This commit is contained in:
59
src/lib/kric-internal-policy.ts
Normal file
59
src/lib/kric-internal-policy.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
exportTarget,
|
||||
isQuotaListPath,
|
||||
isQuotaResultPath,
|
||||
isReportStreamPath,
|
||||
} from "@/lib/project-proxy-policy";
|
||||
import { isRecord, validDateRange } from "@/types/kart";
|
||||
import { readReportBatch } from "@/lib/report-contract";
|
||||
import { parseFilterExpression } from "@/lib/filter-expression";
|
||||
|
||||
type Target = { path: string; kind: "list" | "quota" | "report" | "excel" };
|
||||
|
||||
/** Adapt integration input to the existing report contract without coupling the parser to HTTP. */
|
||||
export function readInternalReportBatch(value: unknown) {
|
||||
return readReportBatch(
|
||||
isRecord(value) && typeof value.filter === "string"
|
||||
? { ...value, filter: parseFilterExpression(value.filter) }
|
||||
: value,
|
||||
);
|
||||
}
|
||||
|
||||
/** Only the five approved integration operations; no arbitrary upstream forwarding. */
|
||||
export function internalTarget(method: string, slug: string[]): Target | null {
|
||||
const [area, ...parts] = slug;
|
||||
const path = "/" + slug.map(encodeURIComponent).join("/");
|
||||
if (method === "GET" && area === "quota" && isQuotaListPath(parts))
|
||||
return { path, kind: "list" };
|
||||
if (method !== "POST") return null;
|
||||
if (area === "project" && isReportStreamPath(parts))
|
||||
return { path, kind: "report" };
|
||||
if (area === "quota" && isQuotaResultPath(parts))
|
||||
return { path, kind: "quota" };
|
||||
if (
|
||||
area === "export" &&
|
||||
parts.length === 3 &&
|
||||
["table", "quota"].includes(parts[2])
|
||||
) {
|
||||
const target = exportTarget("POST", parts);
|
||||
if (target) return { path: target.path, kind: "excel" };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Broader backend quota contract, without changing the ordinary screen's request policy. */
|
||||
export function readInternalQuotaRequest(value: unknown) {
|
||||
if (!isRecord(value)) throw new Error("쿼터 조회 조건을 확인해 주세요.");
|
||||
const dataScope = value.dataScope ?? "ACTUAL";
|
||||
const startDate = value.startDate ?? "";
|
||||
const endDate = value.endDate ?? "";
|
||||
if (
|
||||
!["ACTUAL", "TEST", "ALL"].includes(String(dataScope)) ||
|
||||
typeof dataScope !== "string" ||
|
||||
typeof startDate !== "string" ||
|
||||
typeof endDate !== "string" ||
|
||||
!validDateRange({ startDate, endDate })
|
||||
)
|
||||
throw new Error("쿼터 데이터 범위와 조회 날짜를 확인해 주세요.");
|
||||
return { dataScope, ...(startDate ? { startDate, endDate } : {}) };
|
||||
}
|
||||
Reference in New Issue
Block a user