Files
frontend/apps/sn/src/features/facility-detail/api/facility-input-api.ts
T

53 lines
2.1 KiB
TypeScript

import { getData, postData } from "@/shared/api/sewerage-api";
const INPUT_RESOURCES = new Map<string, string>([
["하수관로", "v1/fcltPpl"],
["우수토실", "v1/fcltStofcbr"],
["하수펌프장", "v1/fcltPump"],
["하수맨홀", "v1/fcltMhl"],
]);
/** 시설 종류와 자체입력 API의 기존 매핑. 미지원 종류의 조회는 수행하지 않는다. */
export const supportsFacilityInput = (layerName: string) =>
INPUT_RESOURCES.has(layerName);
/** 미지원 시설을 잘못된 URL로 전송하지 않도록 API 경계에서 차단한다. */
function requireInputResource(layerName: string): string {
const resource = INPUT_RESOURCES.get(layerName);
if (!resource)
throw new Error(`자체입력을 지원하지 않는 시설입니다: ${layerName}`);
return resource;
}
/** 자체입력에 사용하는 관리기관 목록을 조회한다. */
export const fetchManagingInstitutions = () => getData("v1/fcltPpl/mngInsts");
/** 선택 시설의 자체입력 정보만 조회한다. */
export const fetchFacilityInput = (
layerName: string,
facilityNo: string,
institutionCode: string,
) =>
getData(
`${requireInputResource(layerName)}/${facilityNo}/${institutionCode}`,
);
/** 기존 시설별 등록 API와 요청 본문을 유지한다. */
export const saveFacilityInput = (
layerName: string,
body: Record<string, unknown>,
) => postData(requireInputResource(layerName), body);
/** 단건 관로의 기존 유하방향 보정 근거 조회 계약. cqlFiter는 기존 서버 파라미터명이다. */
export async function fetchPipeFlowBasis(
facilityNo: string,
institutionCode: string,
) {
const escapeCqlLiteral = (value: string) => value.replace(/'/g, "''");
const params = new URLSearchParams({
lyrTypeNm: "tb_ms_swage_ppl",
includeFlowDirectionBasis: "true",
cqlFiter: `fclt_mng_no='${escapeCqlLiteral(facilityNo)}' and mng_inst_cd='${escapeCqlLiteral(institutionCode)}'`,
page: "0",
size: "1",
});
const response = await getData(`v1/fclts?${params.toString()}`);
return Array.isArray(response?.data) ? response.data[0] : null;
}