Files
frontend/apps/wr/app/map/util.ts
T
2025-07-31 14:38:14 +09:00

58 lines
2.2 KiB
TypeScript

import { getFetch, postFectch, fetchType } from "@/components/lib/api";
const fetchpbnstDetail = async (featureCd: string, setTabData: any) => {
try {
const response = await getFetch("wr", `/reuseFc/pubFc/${featureCd}`);
// 중복 데이터 추가 방지
setTabDataFunc(response, featureCd, setTabData);
} catch (error) {
console.error("Error fetching data:", error);
}
};
const fetchHasuDetail = async (featureCd: string, data: string) => {
try {
const rainRes = await postFectch(`/prcsFclt/ruseInfo/1/20/A/0/0/1/SW/${featureCd}`, [data], fetchType.COMMON)
// setHasuList
const filteredData = rainRes.data.map((item: any) => {
return {
...item,
fctCpc: Number(item.fctCpc) || 0,
ruse: item.ruse === false ? "N" : "Y",
};
})
return filteredData
} catch (error) {
console.error("Error fetching data:", error);
}
};
// 재이용시설 상세정보
const setTabDataFunc = (res: any, pk: string, setTabData: any) => {
setTabData((prev) => {
if (prev.some((tab) => tab.id === pk)) {
return prev; // 이미 존재하는 탭이면 추가하지 않음
}
return [...prev, { id: pk, name: `재이용시설 ${prev.length + 1}`, data: res }];
});
}
const detainSttn = async (featureCd: string, layerNm: string) => {
if (layerNm == '빗물이용시설') { //빗물이용시설
const res = await getFetch(fetchType.WR, `/reuseFc/rainyInfoList/1/20/0/${featureCd}`)
return res
}
else if (layerNm == '중수도시설') { //중수도 시설
const res = await getFetch(fetchType.WR, `/reuseFc/waterreuseFc/1/20/0/${featureCd}`)
return res
}
else if (layerNm == '수요처') { //수요처
const res = await getFetch(fetchType.WR, `/reuseFc/request/1/20/0/${featureCd}`)
return res
}
else {
const res = await getFetch(fetchType.WR, `/drain/facilityList/1/20/0/${featureCd}`)
return res
// setHtdflDetailModal({ isOpen: true, data: htdflSttnRes[0] });
}
}
export { fetchHasuDetail, fetchpbnstDetail, detainSttn };