diff --git a/app/utils/api.js b/app/utils/api.js index f241c4a..4e0d8ca 100644 --- a/app/utils/api.js +++ b/app/utils/api.js @@ -317,26 +317,63 @@ export async function getMyRentListings() { return apiFetch("/RentProperties/GetMyRentListings"); } +function normalizeLocationValue(value) { + if (value === null || value === undefined || value === "") return ""; + + const normalizedValue = String(value).trim(); + const map = { + "دمشق": "Damascus", + "حلب": "Aleppo", + "حمص": "Homs", + "اللاذقية": "Latakia", + "درعا": "Daraa", + "طرطوس": "Tartous", + "السويداء": "Suweida", + "دير الزور": "DeirEzzor", + "الرقة": "Raqqa", + "إدلب": "Idlib", + "الحسكة": "Hasakah", + "القامشلي": "Qamishli", + "ريف دمشق": "RuralDamascus", + Damascus: "Damascus", + Aleppo: "Aleppo", + Homs: "Homs", + Latakia: "Latakia", + Daraa: "Daraa", + Tartous: "Tartous", + Sweida: "Suweida", + DeirEzzor: "DeirEzzor", + Raqqa: "Raqqa", + Idlib: "Idlib", + Hasakah: "Hasakah", + Qamishli: "Qamishli", + RuralDamascus: "RuralDamascus", + }; + + return map[normalizedValue] ?? normalizedValue; +} + export function buildRentPropertyPayload(data = {}) { const propertyInformation = data?.propertyInformation || {}; - const cityValue = + const rawCityValue = data?.city ?? data?.governorate ?? propertyInformation?.city ?? propertyInformation?.governorate ?? ""; + const normalizedCityValue = normalizeLocationValue(rawCityValue); const documentTypeValue = data?.documentType ?? propertyInformation?.documentType ?? ""; return { ...data, - city: cityValue, - governorate: cityValue, + city: normalizedCityValue, + governorate: normalizedCityValue, documentType: documentTypeValue, propertyInformation: { ...propertyInformation, - city: cityValue, - governorate: propertyInformation?.governorate ?? cityValue, + city: normalizedCityValue, + governorate: normalizeLocationValue(propertyInformation?.governorate ?? normalizedCityValue), documentType: documentTypeValue, }, }; @@ -345,14 +382,14 @@ export function buildRentPropertyPayload(data = {}) { export async function addRentProperty(data) { return apiFetch("/RentProperties/AddRentProperty", { method: "POST", - body: buildRentPropertyPayload(data), + body: { rentPropertyDto: buildRentPropertyPayload(data) }, }); } export async function editRentProperty(id, data) { return apiFetch(`/RentProperties/EditRentProperty/${id}`, { method: "PUT", - body: data, + body: { rentPropertyDto: buildRentPropertyPayload(data) }, }); }