140 lines
4.8 KiB
TypeScript
140 lines
4.8 KiB
TypeScript
import type { IUserInfo } from "@/shared/store/user-store";
|
|
import type { InstlSncnMngDetResponse } from "@/entities/instl-sncn";
|
|
|
|
import type { InstlSncnRegistFormData } from "./instl-sncn-regist-schema";
|
|
import { parseTaskSeComCdFromApi } from "./instl-sncn-regist-schema";
|
|
|
|
function mapSelectedValue(value?: string | null): "Y" | "N" | null {
|
|
if (value === "Y" || value === "N") return value;
|
|
return null;
|
|
}
|
|
|
|
function mapEsntlAtchFileList(esntlFileList: InstlSncnMngDetResponse["esntlFileList"]) {
|
|
const esntlMap = new Map<string, string>();
|
|
|
|
for (const item of esntlFileList) {
|
|
if (!item.esntlAtchFileId || !item.atflCd) continue;
|
|
esntlMap.set(item.esntlAtchFileId, item.atflCd);
|
|
}
|
|
|
|
return Array.from(esntlMap.entries()).map(([esntlAtchFileId, atchFileGroupId]) => ({
|
|
esntlAtchFileId,
|
|
atchFileGroupId,
|
|
}));
|
|
}
|
|
|
|
export function mapDetailToFormData(data: InstlSncnMngDetResponse): InstlSncnRegistFormData {
|
|
const { detDto, bizSclList, bizCstList, cklstResultList, esntlFileList, splmntDmndList } = data;
|
|
|
|
return {
|
|
instlSncnMng: {
|
|
instlSncnDocNo: detDto.instlSncnDocNo,
|
|
bizNm: detDto.bizNm,
|
|
bizBgngYr: detDto.bizBgngYr,
|
|
bizEndYr: detDto.bizEndYr,
|
|
bizCn: detDto.bizCn,
|
|
taskSeComCd: parseTaskSeComCdFromApi(detDto.taskSeComCd),
|
|
sncnSeComCd: detDto.sncnSeComCd,
|
|
dsgnrNm: detDto.dsgnrNm,
|
|
dsgnrTelno: detDto.dsgnrTelno,
|
|
dsgnrOgdpNm: detDto.dsgnrOgdpNm,
|
|
dsgnrEmlAddr: detDto.dsgnrEmlAddr,
|
|
aplcntNm: detDto.aplcntNm ?? "",
|
|
aplcntMblTelno: detDto.aplcntMblTelno ?? "",
|
|
aplcntOgdpNm: detDto.aplcntOgdpNm ?? "",
|
|
aplcntEmlAddr: detDto.aplcntEmlAddr ?? "",
|
|
bgtBizCd: detDto.bgtBizCd,
|
|
bgtAplyYr: detDto.bgtAplyYr,
|
|
admdstCd: detDto.admdstCd,
|
|
envoSeComCd: detDto.envoSeComCd,
|
|
prgrsSttsComCd: detDto.prgrsSttsComCd,
|
|
atchFileGroupId: detDto.atchFileGroupId ?? "",
|
|
rtlztnFcltSeComCd: detDto.rtlztnFcltSeComCd ?? "",
|
|
rtlztnUsgSeComCd: detDto.rtlztnUsgSeComCd ?? "",
|
|
envoSeCdNm: detDto.envoSeCdNm,
|
|
sncnSeCdNm: detDto.sncnSeCdNm,
|
|
taskSeCdNm: detDto.taskSeCdNm,
|
|
prgrsSttsCdNm: detDto.prgrsSttsCdNm,
|
|
sido: detDto.sido,
|
|
gugun: detDto.gugun,
|
|
regDt: detDto.regDt,
|
|
rgtr: detDto.rgtr,
|
|
rgtrNm: detDto.rgtrNm,
|
|
mdfcnDt: detDto.mdfcnDt,
|
|
},
|
|
bzScaleList: bizSclList.map((item) => ({
|
|
cnstpSeCd: item.cnstpSeCd,
|
|
bscPl: item.bscPlanQty,
|
|
budgetReflct: item.bgtRfltQty,
|
|
thtiDsgn: item.tstmDesignQty,
|
|
diff: item.tstmDesignQty - item.bgtRfltQty,
|
|
})),
|
|
bizCstList: bizCstList.map((item) => ({
|
|
acntgSeCd: item.acntgSeCd,
|
|
bscPlanAmt: item.bscPlanAmt,
|
|
bgtRfltAmt: item.bgtRfltAmt,
|
|
tstmDesignAmt: item.tstmDesignAmt,
|
|
})),
|
|
cklstResultList:
|
|
cklstResultList?.map((item) => ({
|
|
cklstSn: item.cklstSn,
|
|
cklstArtclSn: item.cklstArtclSn,
|
|
cklstRvwSn: item.cklstRvwSn,
|
|
rvwStpComCd: item.rvwStpComCd,
|
|
selected: mapSelectedValue(item.rvwRsltAnmlyYn),
|
|
picRvwCn: item.picRvwCn,
|
|
})) ?? [],
|
|
esntlAtchFileList: mapEsntlAtchFileList(esntlFileList),
|
|
splmntDmndList:
|
|
splmntDmndList?.map((item) => ({
|
|
splmntDmndSn: item.splmntDmndSn,
|
|
splmntArtclComCd: item.splmntArtclComCd,
|
|
splmntArtclCdNm: item.splmntArtclCdNm,
|
|
splmntDmndCn: item.splmntDmndCn,
|
|
splmntDmndDt: item.splmntDmndDt,
|
|
splmntDmndAtchFileGroupId: item.splmntDmndAtchFileGroupId ?? "",
|
|
splmntDmndAtchFileNm: item.splmntDmndAtchFileInfo?.orgnlFileNm ?? "",
|
|
splmntCn: item.splmntCn ?? "",
|
|
splmntPicNm: item.splmntPicNm ?? "",
|
|
splmntCmptnDt: item.splmntCmptnDt ?? "",
|
|
splmntAtchFileGroupId: item.splmntAtchFileGroupId ?? "",
|
|
splmntAtchFileNm: item.splmntAtchFileInfo?.orgnlFileNm ?? "",
|
|
splmntAtchFileAtflId: item.splmntAtchFileInfo?.atflId ?? "",
|
|
cmptnYn: item.cmptnYn,
|
|
})) ?? [],
|
|
privacyConsent: "Y",
|
|
};
|
|
}
|
|
|
|
export function getCreateDefaultValues(
|
|
userInfo: IUserInfo | null,
|
|
taskSeComCd?: string[],
|
|
): InstlSncnRegistFormData {
|
|
return {
|
|
instlSncnMng: {
|
|
bizNm: "",
|
|
bizBgngYr: "",
|
|
bizEndYr: "",
|
|
bizCn: "",
|
|
taskSeComCd: taskSeComCd ?? [],
|
|
sncnSeComCd: "",
|
|
dsgnrNm: "",
|
|
dsgnrTelno: "",
|
|
dsgnrOgdpNm: "",
|
|
dsgnrEmlAddr: "",
|
|
aplcntNm: userInfo?.userName ?? "",
|
|
aplcntMblTelno: userInfo?.mphn ?? "",
|
|
aplcntOgdpNm: userInfo?.ogdpSeNm ?? "",
|
|
aplcntEmlAddr: userInfo?.email ?? "",
|
|
prgrsSttsComCd: "SV",
|
|
atchFileGroupId: "",
|
|
},
|
|
bzScaleList: [],
|
|
bizCstList: [],
|
|
cklstResultList: [],
|
|
esntlAtchFileList: [],
|
|
splmntDmndList: [],
|
|
privacyConsent: "N",
|
|
};
|
|
}
|