import { getCmsData } from "@/components/lib/api"; export interface Option { id: number, name: string } export type BIZ_CD_TYPE = { lwpoCd: string, upCd: string, lwpoCdNm: string, unit: string, prntLwpoCd: null }; export const fetchCtpvSggData = async (set: (state: any) => void) => { try { const ctpvData = await getCmsData('/api/v1/code/cache/ADSTDSTRCD/Y'); const ctpvList: Option[] = ctpvData .filter((item: any) => typeof item.lwpoCd === 'string' && item.lwpoCd.length === 2) .map((feature: any) => ({ id: feature.lwpoCd, name: feature.lwpoCdNm })); const sggList: Option[] = ctpvData .filter((item: any) => typeof item.lwpoCd === 'string' && item.lwpoCd.length !== 2) .map((item: any) => ({ id: item.lwpoCd, name: item.lwpoCdNm })); set({ ctpv: ctpvList, sgg: sggList }); } catch (e: any) { // alert("시도, 시군구 데이터 로드 실패: " + e.message); console.error("CTPV 데이터 로드 실패:", e); } }; export const fetchBIZ_SE_CD = async (set: (state: any) => void) => { try { const res = await getCmsData(`/api/v1/code/cache/BIZSECD`); set({ BIZ_SE_CD: res }); } catch (e: any) { // alert("BIZ_SE_CD 데이터 로드 실패: " + e.message); console.error("BIZ_SE_CD 데이터 로드 실패:", e); } }; export const fetchBIZ_TY_CD = async (set: (state: any) => void) => { try { const res = await getCmsData(`/api/v1/code/cache/BIZTYCD`); set({ BIZ_TY_CD: res }); } catch (e: any) { // alert("BIZ_TY_CD 데이터 로드 실패: " + e.message); console.error("BIZ_TY_CD 데이터 로드 실패:", e); } };