62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
/** 침수흔적 강우분석과 연결된 심선·위선 목록 조회를 담당한다. */
|
|
|
|
import { getData } from "@/components/lib/api";
|
|
|
|
import type { FldngHstryDetailCacheValue } from "./fldngHstryTypes";
|
|
|
|
const normalizeFldngHstryRainAnalysisPayload = (data: any) => {
|
|
if (!data || typeof data !== "object") return {};
|
|
return {
|
|
rain_bgng_tm: data.rainBgngTm ?? data.rain_bgng_tm ?? null,
|
|
rainBgngTm: data.rainBgngTm ?? data.rain_bgng_tm ?? null,
|
|
rain_end_tm: data.rainEndTm ?? data.rain_end_tm ?? null,
|
|
rainEndTm: data.rainEndTm ?? data.rain_end_tm ?? null,
|
|
rain_tot: data.rainTot ?? data.rain_tot ?? null,
|
|
rainTot: data.rainTot ?? data.rain_tot ?? null,
|
|
rain_str: data.rainStr ?? data.rain_str ?? null,
|
|
rainStr: data.rainStr ?? data.rain_str ?? null,
|
|
};
|
|
};
|
|
|
|
export const loadFldngHstryDetail = async (
|
|
fldngHstryFid: string,
|
|
): Promise<FldngHstryDetailCacheValue> => {
|
|
const [rainResult, depthResult] = await Promise.allSettled([
|
|
getData(`v1/fldng/hstry/rainAnls/${encodeURIComponent(fldngHstryFid)}`),
|
|
getData(`v1/fldng/hstry/depthMap/${encodeURIComponent(fldngHstryFid)}`),
|
|
]);
|
|
|
|
if (rainResult.status === "rejected") {
|
|
console.warn("침수강우분석 조회 실패:", rainResult.reason);
|
|
}
|
|
if (depthResult.status === "rejected") {
|
|
console.warn("침수깊이지도 조회 실패:", depthResult.reason);
|
|
}
|
|
|
|
const depthPayload =
|
|
depthResult.status === "fulfilled"
|
|
? (depthResult.value?.data ?? depthResult.value)
|
|
: null;
|
|
const depthItems = Array.isArray(depthPayload)
|
|
? depthPayload
|
|
: depthPayload?.depthMaps;
|
|
const waterLevelItems = Array.isArray(depthPayload?.waterLevelMaps)
|
|
? depthPayload.waterLevelMaps
|
|
: [];
|
|
|
|
return {
|
|
rainAnalysis:
|
|
rainResult.status === "fulfilled"
|
|
? normalizeFldngHstryRainAnalysisPayload(rainResult.value)
|
|
: {},
|
|
fldngHstryDepthRows: Array.isArray(depthItems)
|
|
? depthItems.filter((row) => row && typeof row === "object")
|
|
: [],
|
|
fldngHstryWtlvRows: waterLevelItems.filter(
|
|
(row: unknown) => row && typeof row === "object",
|
|
),
|
|
complete:
|
|
rainResult.status === "fulfilled" && depthResult.status === "fulfilled",
|
|
};
|
|
};
|