155 lines
5.2 KiB
TypeScript
155 lines
5.2 KiB
TypeScript
import type { IUserInfo } from "@/shared/store/user-store";
|
|
import {
|
|
type InstlSncnApplySaveRequestDto,
|
|
instlSncnApplySaveSchema,
|
|
type InstlSncnMngDetResponse,
|
|
} from "@/entities/instl-sncn";
|
|
import { toEsntlAtchFileSaveList } from "@/widgets/pbadms-sprt";
|
|
|
|
import type { InstlSncnRegistFormData } from "./instl-sncn-regist-schema";
|
|
import { formatTaskSeComCdForApi, parseTaskSeComCdFromApi } from "./instl-sncn-regist-schema";
|
|
|
|
function mapSelectedValue(value?: string | null): "Y" | "N" | null {
|
|
if (value === "Y" || value === "N") return value;
|
|
return null;
|
|
}
|
|
|
|
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 ?? "",
|
|
sido: detDto.sido,
|
|
gugun: detDto.gugun,
|
|
},
|
|
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: toEsntlAtchFileSaveList(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 ?? "",
|
|
cmptnYn: item.cmptnYn,
|
|
})) ?? [],
|
|
privacyConsent: "Y",
|
|
};
|
|
}
|
|
|
|
export function getCreateDefaultValues(
|
|
userInfo: IUserInfo | null,
|
|
options?: {
|
|
taskSeComCd?: string[];
|
|
admdstCd?: string;
|
|
sido?: string;
|
|
gugun?: string;
|
|
},
|
|
): InstlSncnRegistFormData {
|
|
return {
|
|
instlSncnMng: {
|
|
bizNm: "",
|
|
bizBgngYr: "",
|
|
bizEndYr: "",
|
|
bizCn: "",
|
|
taskSeComCd: options?.taskSeComCd ?? [],
|
|
sncnSeComCd: "",
|
|
dsgnrNm: "",
|
|
dsgnrTelno: "",
|
|
dsgnrOgdpNm: "",
|
|
dsgnrEmlAddr: "",
|
|
aplcntNm: userInfo?.userName ?? "",
|
|
aplcntMblTelno: userInfo?.mphn ?? "",
|
|
aplcntOgdpNm: userInfo?.ogdpSeNm ?? "",
|
|
aplcntEmlAddr: userInfo?.email ?? "",
|
|
admdstCd: options?.admdstCd ?? "",
|
|
sido: options?.sido ?? "",
|
|
gugun: options?.gugun ?? "",
|
|
prgrsSttsComCd: "SV",
|
|
atchFileGroupId: "",
|
|
},
|
|
bzScaleList: [],
|
|
bizCstList: [],
|
|
cklstResultList: [],
|
|
esntlAtchFileList: [],
|
|
splmntDmndList: [],
|
|
privacyConsent: "N",
|
|
};
|
|
}
|
|
|
|
export function buildFormPayload(
|
|
data: InstlSncnRegistFormData,
|
|
prgrsSttsComCd: "SV" | "ST" | "TE",
|
|
options: { isEditMode: boolean; docNo?: string },
|
|
): InstlSncnApplySaveRequestDto {
|
|
return instlSncnApplySaveSchema.parse({
|
|
instlSncnMng: {
|
|
...data.instlSncnMng,
|
|
instlSncnDocNo: options.isEditMode ? options.docNo : undefined,
|
|
taskSeComCd: formatTaskSeComCdForApi(data.instlSncnMng.taskSeComCd),
|
|
prgrsSttsComCd,
|
|
},
|
|
bzScaleList: data.bzScaleList,
|
|
bizCstList: data.bizCstList,
|
|
cklstResultList: data.cklstResultList.map((item) => ({
|
|
...item,
|
|
selected: item.selected ?? undefined,
|
|
})),
|
|
esntlAtchFileList: data.esntlAtchFileList,
|
|
splmntDmndList: data.splmntDmndList.map((item) => ({
|
|
...item,
|
|
...(prgrsSttsComCd === "TE" ? { cmptnYn: "Y" } : null),
|
|
})),
|
|
});
|
|
}
|