"// This is the entry file for backend server service (for… · The Chat Archive
Explore "// This is the entry file for backend server service (for server-side validation and… Save Share Download ▾ Report"// This is the entry file for backend server service (for server-side validation and data conversion)
import {
pdf,
xml,
flattenToStringMap,
validateForm,
getSignatureSummary,
i18nByLocale,
isEmpty,
getI18nAddressLabel,
getI18nDistrictLabel,
getI18nRegionLabel,
} from "govhk-form-core";
import moment from "moment";
import get from "lodash/get";
import "../l10n";
import steps from "../steps";
const checkNull = (val) => {
if (isEmpty(val) || val == "false") {return "No submission found"}
else{ return val}
};
export default {
convert: ({ form, submit, data }, dataTypes) => {
const applicant = data.applicant;
const sign = getSignatureSummary(form.locale, data, "applicant");
const list = get(data["applicant"], "b", []);
const mapping = {
...flattenToStringMap(data),
sign,
//a attachments
newBuCertCopy:
get(data["applicant"], "newBuCertCopy.fileName", "")
,
newBuAppFormCopy:
get(data["applicant"], "newBuAppFormCopy.fileName", "")
,
incorCertCopy:
get(data["applicant"], "incorCertCopy.fileName", "")
,
MACopy: get(data["applicant"], "MACopy.fileName", ""),
a_Other: get(data["applicant"], "a_Other.fileName", ""),
//b hkid
"applicant.b.0.b_hkid": isEmpty(list[0])
? ""
: ${list[0].b_hkid.id}(${list[0].b_hkid.checkDigit}),
"applicant.b.1.b_hkid": isEmpty(list[1])
? ""
: ${list[1].b_hkid.id}(${list[1].b_hkid.checkDigit}),
"applicant.b.2.b_hkid": isEmpty(list[2])
? ""
: ${list[2].b_hkid.id}(${list[2].b_hkid.checkDigit}),
// 'applicant.b.0.b_quaType.ee': isEmpty(list[0]) ? '' : ${list[0].b_quaType.ee}(${list[0].b_quaType.indexOf("ee")> -1 ? "Yes": ""}), //b attachments quahkidCopy: get(data["applicant"], "quahkidCopy.fileName", "") , quaSign: get(data["applicant"], "quaSign.fileName", ""), quaOther: get(data["applicant"], "quaOther.fileName", ""), //c hkid "applicant.c_hkid": a p p l i c a n t . c h k i d . i d ( {applicant.c_hkid.id}( a ppl i c {applicant.c_hkid.checkDigit}) {applicant.d_hkid.checkDigit}) quaDegreeCertCopy_ {i} quaPlumCertCopy_ {i} quaEmpConCopy_ {i}`] =
!isEmpty(list[i].quaMpfCopy) && list[i].quaMpfCopy.fileName
;
}
}
Assistant2023-08-22 04:05 UTC Copy response
Sure! You can update the code as follows:
const checkNull = (val) => {
if (isEmpty(val) || val === "false") {
return "No submission found";
} else {
return val;
}
};
const checkEmpty = (val) => {
if (isEmpty(val)) {
return "";
} else {
return val;
}
};
export default {
convert: ({ form, submit, data }, dataTypes) => {
// ...
const mapping = {
// ...
a_Other: checkEmpty(get(data["applicant"], "a_Other.fileName", "")),
// ...
};
// ...
},
// ...
};
This will check if a_Other is empty and return "" if it is empty.
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 1 (2 messages)
Language en
Conversation date Aug 22, 2023
Added to archive Nov 16, 2026
ID 01m7h41eaqs4dsnz977qaszx0jSource & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: f511ddd59dedc55c1c841a52a6d63e90
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
an
t
.
c h
k
i
d
.
i
d
(
, //c attachments authHkid: get(data["applicant"], "authHkid.fileName", ""), authSign: get(data["applicant"], "authSign.fileName", ""), authBuRegRecord: get(data["applicant"], "authBuRegRecord.fileName", "") , authEmpConCopy: get(data["applicant"], "authEmpConCopy.fileName", "") , authMpfCopy: get(data["applicant"], "authMpfCopy.fileName", "") , authOther: get(data["applicant"], "authOther.fileName", "") , //d hkid "applicant.d_hkid":
a p p l i c a n t . d h k i d . i d ( {applicant.d_hkid.id}( a ppl i c an t . d h k i d . i d ( , //d attachments resHkid: get(data["applicant"], "resHkid.fileName", ""), resSign: get(data["applicant"], "resSign.fileName", ""), resBuRegRecord: get(data["applicant"], "resBuRegRecord.fileName", "") , resEmConCopy: get(data["applicant"], "resEmConCopy.fileName", "") , resMpfCopy: get(data["applicant"], "resMpfCopy.fileName", ""), resOther: get(data["applicant"], "resOther.fileName", ""), //e attachments manuAccLetterCopy: get(data["applicant"], "manuAccLetterCopy.fileName", "") , manuAppLetter: get(data["applicant"], "manuAppLetter.fileName", "") , //f attachments workPurCopy: get(data["applicant"], "workPurCopy.fileName", "") , workRecCopy: get(data["applicant"], "workRecCopy.fileName", "") , workAuthUse: get(data["applicant"], "workAuthUse.fileName", "") , workLayPlan: get(data["applicant"], "workLayPlan.fileName", "") , workUnderForm: get(data["applicant"], "workUnderForm.fileName", "") , workOther: get(data["applicant"], "workOther.fileName", ""), // date: moment(new Date()).format('YYYY-MM-DD'), }; //b attachments if (list.length > 0) { for (let i = 0; i < list.length; i++) { mapping[
{i}`] =
!isEmpty(list[i].quaDegreeCertCopy) &&
list[i].quaDegreeCertCopy.fileName
;
mapping[`quaHdCertCopy_
] = !isEmpty(list[i].quaHdCertCopy) && list[i].quaHdCertCopy.fileName ; mapping[
{i}`] =
!isEmpty(list[i].quaPlumCertCopy) && list[i].quaPlumCertCopy.fileName
;
mapping[`quaBuRegRecord_
] = !isEmpty(list[i].quaBuRegRecord) && list[i].quaBuRegRecord.fileName ; mapping[
{i}`] =
!isEmpty(list[i].quaEmpConCopy) && list[i].quaEmpConCopy.fileName
;
mapping[`quaMpfCopy_
return [
pdf.concat(
[
pdf.defaultAck(form, submit),
pdf.merge({
file: `${form.formId}-${form.locale}.pdf`,
mapping,
}),
],
`${submit.trnId}_${submit.submitTime.replace(/[ :]/g, "-")}.pdf`
),
xml.convert({ form, submit, data }, dataTypes, `${form.formId}.xml`),
];
},
validate: (submission, setResult) => {
// console.log(JSON.stringify(submission.data));
validateForm(submission, steps).then((result) => {
setResult(result);
});
},
};
" can you help update it that if a_Other is empty then return ""
Copy first response
Not yet included in a published release.