fix(property): improve property save payload and error handling
deploy-chabokan / deploy (push) Canceled after 0s
deploy-chabokan / deploy (push) Canceled after 0s
This commit is contained in:
@@ -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 || 'خطا در بروزرسانی ملک';
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user