Files
frontend/apps/wr/app/store/common/searchCode/index.ts
T

55 lines
1.6 KiB
TypeScript

import { fetchType, getFetch, postFectch } from "@/components/lib/api";
import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type";
import type { DemandCompType } from "@common/business_components/ui";
export type comFcltState = {
searchFclts: pubHasuType;
demandCompList: DemandCompType[];
};
export type comFcltActions = {
getSwtrmtFcltNm: (searchNm: string) => void;
getDemandCompList :(searchNm: string,cnt:number) => void
regDemandCompany:(data:DemandCompType ) => void
};
export const searchActions: (set: any) => comFcltActions = (set: any) => {
return {
getSwtrmtFcltNm: async (searchNm: string) => {
const fcltNm = await getFetch(
"common",
`/prcsFclt/info/1/20/${searchNm}`
);
const fcltNmCd: pubHasuType[] = fcltNm.map((item: any) => ({
bscFctCd: item.bscFctCd,
sido: item.sido,
gugun: item.gugun,
bscFctNm: item.bscFctNm,
addr: item.addr,
fctCpc: item.fctCpc,
}));
return set((state: comFcltState) => ({
...state,
searchFclts: fcltNmCd,
}));
},
getDemandCompList: async (searchNm: string ,cnt:number) => {
const coList = await getFetch(
fetchType.WR,
`/reuseFc/request/${searchNm}/${cnt}`
);
return set((state: comFcltState) => {
state.demandCompList= coList
return state
});
},regDemandCompany: async (data:DemandCompType)=>{
try{
const response = await postFectch('/reuseFc/request',data,fetchType.WR )
}catch(err){
console.log(err)
}
}
};
};