From a155cdd48112ccaa514abaa3cd34faad1cb02fac Mon Sep 17 00:00:00 2001 From: Kavehhn174 Date: Wed, 19 Aug 2026 07:46:20 +0330 Subject: [PATCH] fix(property): improve property save payload and error handling --- src/service/PropertyService.js | 8 ++--- src/views/pages/Property/CreateProperty.vue | 37 +++++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/service/PropertyService.js b/src/service/PropertyService.js index f29bcd5..dbec953 100644 --- a/src/service/PropertyService.js +++ b/src/service/PropertyService.js @@ -103,8 +103,8 @@ export const PropertyService = { const response = await axios(config); return 'success'; } catch (err) { - console.log(err); - return err.response.data.message; + console.error('createProperty error:', err); + return err?.response?.data?.message || err?.message || 'خطا در ثبت ملک'; } }, @@ -120,8 +120,8 @@ export const PropertyService = { const response = await axios(config); return 'success'; } catch (err) { - console.log(err); - return err.response.data.message; + console.error('updateProperty error:', err); + return err?.response?.data?.message || err?.message || 'خطا در بروزرسانی ملک'; } }, diff --git a/src/views/pages/Property/CreateProperty.vue b/src/views/pages/Property/CreateProperty.vue index e2cf6e5..ca4ac4e 100644 --- a/src/views/pages/Property/CreateProperty.vue +++ b/src/views/pages/Property/CreateProperty.vue @@ -466,10 +466,16 @@ const performAutoSave = async () => { payload.registrationDate = dObj ? dObj.toISOString() : null; } payload.mainImageUrls = (mainImageUrlsWithData.value || []) - .map((x) => typeof x === 'string' ? x : (x.url || x.source || '')) + .map((x) => { + const raw = typeof x === 'string' ? x : (x.url || x.source || ''); + return raw.split('?')[0]; + }) .filter(Boolean); payload.documentUrls = (documentUrlsWithData.value || []) - .map((x) => typeof x === 'string' ? x : (x.url || x.source || '')) + .map((x) => { + const raw = typeof x === 'string' ? x : (x.url || x.source || ''); + return raw.split('?')[0]; + }) .filter(Boolean); payload.features = serializeFeaturesPayload(featuresValues.value); @@ -626,13 +632,6 @@ const saveProperty = async () => { return; } - if (regYear.value && regMonth.value && regDay.value) { - const dObj = jalaliToDate(regYear.value, regMonth.value, regDay.value); - property.value.registrationDate = dObj ? dObj.toISOString() : null; - } else { - property.value.registrationDate = null; - } - isSaving.value = true; toast.add({ severity: 'info', @@ -642,25 +641,35 @@ const saveProperty = async () => { }); try { - property.value.mainImageUrls = (mainImageUrlsWithData.value || []) + const payload = { ...property.value }; + payload.name = computedPropertyName.value || payload.name || 'ملک جدید'; + + if (regYear.value && regMonth.value && regDay.value) { + const dObj = jalaliToDate(regYear.value, regMonth.value, regDay.value); + payload.registrationDate = dObj ? dObj.toISOString() : null; + } else { + payload.registrationDate = null; + } + + payload.mainImageUrls = (mainImageUrlsWithData.value || []) .map((x) => { const raw = typeof x === 'string' ? x : (x.url || x.source || ''); return raw.split('?')[0]; }) .filter(Boolean); - property.value.documentUrls = (documentUrlsWithData.value || []) + payload.documentUrls = (documentUrlsWithData.value || []) .map((x) => { const raw = typeof x === 'string' ? x : (x.url || x.source || ''); return raw.split('?')[0]; }) .filter(Boolean); - property.value.features = serializeFeaturesPayload(featuresValues.value); + payload.features = serializeFeaturesPayload(featuresValues.value); let status = 'failed'; if (property.value._id?.trim()) { - status = await PropertyService.updateProperty(property.value._id, property.value); + status = await PropertyService.updateProperty(property.value._id, payload); } else { - status = await PropertyService.createProperty(property.value); + status = await PropertyService.createProperty(payload); } if (status === 'success') {