fix(property): improve property save payload and error handling
deploy-chabokan / deploy (push) Canceled after 0s

This commit is contained in:
2026-08-19 07:46:20 +03:30
parent 30c8149008
commit a155cdd481
2 changed files with 27 additions and 18 deletions
+4 -4
View File
@@ -103,8 +103,8 @@ export const PropertyService = {
const response = await axios(config); const response = await axios(config);
return 'success'; return 'success';
} catch (err) { } catch (err) {
console.log(err); console.error('createProperty error:', err);
return err.response.data.message; return err?.response?.data?.message || err?.message || 'خطا در ثبت ملک';
} }
}, },
@@ -120,8 +120,8 @@ export const PropertyService = {
const response = await axios(config); const response = await axios(config);
return 'success'; return 'success';
} catch (err) { } catch (err) {
console.log(err); console.error('updateProperty error:', err);
return err.response.data.message; return err?.response?.data?.message || err?.message || 'خطا در بروزرسانی ملک';
} }
}, },
+23 -14
View File
@@ -466,10 +466,16 @@ const performAutoSave = async () => {
payload.registrationDate = dObj ? dObj.toISOString() : null; payload.registrationDate = dObj ? dObj.toISOString() : null;
} }
payload.mainImageUrls = (mainImageUrlsWithData.value || []) 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); .filter(Boolean);
payload.documentUrls = (documentUrlsWithData.value || []) 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); .filter(Boolean);
payload.features = serializeFeaturesPayload(featuresValues.value); payload.features = serializeFeaturesPayload(featuresValues.value);
@@ -626,13 +632,6 @@ const saveProperty = async () => {
return; 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; isSaving.value = true;
toast.add({ toast.add({
severity: 'info', severity: 'info',
@@ -642,25 +641,35 @@ const saveProperty = async () => {
}); });
try { 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) => { .map((x) => {
const raw = typeof x === 'string' ? x : (x.url || x.source || ''); const raw = typeof x === 'string' ? x : (x.url || x.source || '');
return raw.split('?')[0]; return raw.split('?')[0];
}) })
.filter(Boolean); .filter(Boolean);
property.value.documentUrls = (documentUrlsWithData.value || []) payload.documentUrls = (documentUrlsWithData.value || [])
.map((x) => { .map((x) => {
const raw = typeof x === 'string' ? x : (x.url || x.source || ''); const raw = typeof x === 'string' ? x : (x.url || x.source || '');
return raw.split('?')[0]; return raw.split('?')[0];
}) })
.filter(Boolean); .filter(Boolean);
property.value.features = serializeFeaturesPayload(featuresValues.value); payload.features = serializeFeaturesPayload(featuresValues.value);
let status = 'failed'; let status = 'failed';
if (property.value._id?.trim()) { if (property.value._id?.trim()) {
status = await PropertyService.updateProperty(property.value._id, property.value); status = await PropertyService.updateProperty(property.value._id, payload);
} else { } else {
status = await PropertyService.createProperty(property.value); status = await PropertyService.createProperty(payload);
} }
if (status === 'success') { if (status === 'success') {