diff --git a/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue b/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue index f025c2b..bd234f3 100644 --- a/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue +++ b/src/pages/newMedicalCard/components/BasicDataForms/DocumentsForm.vue @@ -139,7 +139,7 @@ export default { checkPassportFields(val, defaultRule) { if ( this.passportFields.every((elem) => !this.docData.passport[elem]) && - !this.initialDocData.passport.series + !this.initialDocData.passport?.id ) { this.$refs.documentForm .getValidationComponents() @@ -200,12 +200,10 @@ export default { let documentsFormData = new FormData(); form.getValidationComponents().forEach((elem) => { if (!this.personDataField.includes(elem.name)) { - if (!this.approvedPassportData) - passportFormData.append(elem.name, elem.modelValue ?? ""); + passportFormData.append(elem.name, elem.modelValue ?? ""); } else documentsFormData.append(elem.name, elem.modelValue ?? ""); }); - if (!this.approvedPassportData) - this.checkChengePhoto("passport", "photo", passportFormData); + this.checkChengePhoto("passport", "photo", passportFormData); this.checkChengePhoto( "insurance_number", "photo_insurance_number", @@ -230,14 +228,43 @@ export default { passportFormData ) ); - } else + } else { + if (this.checkPhotoDeletion("passport", "photo")) + request.push( + this.deletePhoto( + `general/identity_document/${this.initialDocData.passport?.id}/delete_photo/` + ) + ); request.push( this.sendData( `general/identity_document/${this.initialDocData.passport?.id}/update/`, passportFormData ) ); + } } + if ( + this.checkPhotoDeletion( + "insurance_number", + "photo_insurance_number" + ) + ) + request.push( + this.deletePhoto( + `general/person/${this.$store.state.medical?.basicData?.personalData?.id}/delete_photo_insurance_number/` + ) + ); + if ( + this.checkPhotoDeletion( + "tax_identification_number", + "photo_tax_identification_number" + ) + ) + request.push( + this.deletePhoto( + `general/person/${this.$store.state.medical?.basicData?.personalData?.id}/delete_photo_tax_identification_number/` + ) + ); request.push( this.sendData( `general/person/${this.$store.state.medical?.basicData?.personalData?.id}/update/`, @@ -257,9 +284,18 @@ export default { if (this.docData[updatedObjId][field]?.file) formData.append(field, this.docData[updatedObjId][field]?.file[0]); }, + checkPhotoDeletion(updatedObjId, field) { + return ( + !Object.keys(this.docData[updatedObjId][field]).length && + this.initialDocData[updatedObjId][field]?.photo + ); + }, async sendData(url, body) { return await fetchWrapper.post(url, body, "formData"); }, + async deletePhoto(url) { + return await fetchWrapper.del(url); + }, addErrorNotification(title, message) { addNotification(title + message, title, message, "error", 5000); },