fixing the build
All checks were successful
Build frontend / build (push) Successful in 59s

This commit is contained in:
mouazkh
2026-06-16 19:03:15 +03:00
parent eaa4206b0b
commit bf45a48504

View File

@ -373,99 +373,20 @@
// // ─── Booking/Reservation Management ─── // // ─── Booking/Reservation Management ───
// export async function confirmDepositPayment(bookingId) { import AuthService from "../services/AuthService";
// return apiFetch('/Reservations/ConfirmDepositPayment', { const API_BASE =
// method: 'POST', process.env.NEXT_PUBLIC_API_URL || "https://45.93.137.91.nip.io/api";
// body: JSON.stringify({ bookingId }), const REPORT_API_BASE =
// }); process.env.NEXT_PUBLIC_REPORT_API_URL || "http://45.93.137.91/api";
// }
// export async function adminConfirmDeposit(reservationId, adminId, comment = null) {
// const token = AuthService.getToken();
// const endpoint = `${API_BASE}/Reservations/AdminConfirmDeposit/admin-confirm-deposit`;
// const normalizedComment =
// typeof comment === 'string' && comment.trim()
// ? comment.trim()
// : null;
// const payload = {
// reservationId,
// adminId,
// comment: normalizedComment,
// };
// console.log('[API] AdminConfirmDeposit request', {
// method: 'PUT',
// endpoint,
// payload,
// adminIdSource: 'jwt-user-id',
// hasToken: Boolean(token),
// tokenPreview: token ? `${token.slice(0, 18)}...${token.slice(-8)}` : null,
// });
// const res = await fetch(endpoint, {
// method: 'PUT',
// headers: {
// 'Content-Type': 'application/json',
// ...(token && { Authorization: `Bearer ${token}` }),
// },
// body: JSON.stringify(payload),
// });
// const text = await res.text();
// let data = null;
// console.log('[API] AdminConfirmDeposit raw response', {
// status: res.status,
// ok: res.ok,
// endpoint,
// rawText: text,
// });
// try {
// data = text ? JSON.parse(text) : null;
// if (data && typeof data === 'object' && 'data' in data) {
// data = data.data;
// }
// } catch {
// data = text;
// }
// const message = typeof data === 'object' && data?.message ? data.message : null;
// console.log('[API] AdminConfirmDeposit parsed response', {
// status: res.status,
// ok: res.ok,
// message,
// data,
// });
// return { status: res.status, data, ok: res.ok, message };
// }
// export async function updateBookingStatus(bookingId, status) {
// return apiFetch('/Reservations/UpdateStatus', {
// method: 'PUT',
// body: JSON.stringify({ bookingId, status }),
// });
// }
import AuthService from '../services/AuthService';
const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api';
const REPORT_API_BASE = process.env.NEXT_PUBLIC_REPORT_API_URL || 'http://45.93.137.91/api';
function isFormData(value) { function isFormData(value) {
return typeof FormData !== 'undefined' && value instanceof FormData; return typeof FormData !== "undefined" && value instanceof FormData;
} }
class ApiBlockedError extends Error { class ApiBlockedError extends Error {
constructor(message = 'Your account is blocked') { constructor(message = "Your account is blocked") {
super(message); super(message);
this.name = 'ApiBlockedError'; this.name = "ApiBlockedError";
this.status = 451; this.status = 451;
} }
} }
@ -475,8 +396,11 @@ export function isApiBlockedError(error) {
} }
function redirectToBlockedPage() { function redirectToBlockedPage() {
if (typeof window !== 'undefined' && window.location.pathname !== '/blocked') { if (
window.location.replace('/blocked'); typeof window !== "undefined" &&
window.location.pathname !== "/blocked"
) {
window.location.replace("/blocked");
} }
} }
@ -488,7 +412,7 @@ function assertNotBlocked(response) {
} }
function buildApiUrl(base, endpoint) { function buildApiUrl(base, endpoint) {
return `${base.replace(/\/$/, '')}${endpoint.startsWith('/') ? endpoint : `/${endpoint}`}`; return `${base.replace(/\/$/, "")}${endpoint.startsWith("/") ? endpoint : `/${endpoint}`}`;
} }
/** /**
@ -505,32 +429,37 @@ async function apiFetch(endpoint, options = {}) {
const hasBody = options.body != null; const hasBody = options.body != null;
const bodyIsFormData = isFormData(options.body); const bodyIsFormData = isFormData(options.body);
if (hasBody && !bodyIsFormData && !headers['Content-Type'] && !headers['content-type']) { if (
headers['Content-Type'] = 'application/json'; hasBody &&
!bodyIsFormData &&
!headers["Content-Type"] &&
!headers["content-type"]
) {
headers["Content-Type"] = "application/json";
} }
const url = `${API_BASE}${endpoint}`; const url = `${API_BASE}${endpoint}`;
console.log('API Request:', url); console.log("API Request:", url);
console.log('API Method:', options.method || 'GET'); console.log("API Method:", options.method || "GET");
console.log('API Body:', hasBody ? options.body : null); console.log("API Body:", hasBody ? options.body : null);
const res = await fetch(url, { const res = await fetch(url, {
...options, ...options,
headers, headers,
body: body:
hasBody && !bodyIsFormData && typeof options.body !== 'string' hasBody && !bodyIsFormData && typeof options.body !== "string"
? JSON.stringify(options.body) ? JSON.stringify(options.body)
: options.body, : options.body,
}); });
console.log('API Response Status:', res.status); console.log("API Response Status:", res.status);
console.log('API Response OK:', res.ok); console.log("API Response OK:", res.ok);
assertNotBlocked(res); assertNotBlocked(res);
if (!res.ok && res.status !== 206) { if (!res.ok && res.status !== 206) {
const text = await res.text().catch(() => ''); const text = await res.text().catch(() => "");
console.error('API Error Response:', text || res.statusText); console.error("API Error Response:", text || res.statusText);
throw new Error(`API ${res.status}: ${text || res.statusText}`); throw new Error(`API ${res.status}: ${text || res.statusText}`);
} }
@ -539,7 +468,7 @@ async function apiFetch(endpoint, options = {}) {
try { try {
const json = JSON.parse(text); const json = JSON.parse(text);
if (json && typeof json === 'object' && 'data' in json) { if (json && typeof json === "object" && "data" in json) {
return json.data; return json.data;
} }
return json; return json;
@ -556,15 +485,15 @@ async function authFetch(endpoint, body, token = null) {
const bodyIsFormData = isFormData(body); const bodyIsFormData = isFormData(body);
if (!bodyIsFormData) { if (!bodyIsFormData) {
headers['Content-Type'] = 'application/json'; headers["Content-Type"] = "application/json";
} }
if (token) { if (token) {
headers['Authorization'] = `Bearer ${token}`; headers["Authorization"] = `Bearer ${token}`;
} }
const res = await fetch(`${API_BASE}${endpoint}`, { const res = await fetch(`${API_BASE}${endpoint}`, {
method: 'POST', method: "POST",
headers, headers,
body: bodyIsFormData ? body : JSON.stringify(body), body: bodyIsFormData ? body : JSON.stringify(body),
}); });
@ -576,23 +505,29 @@ async function authFetch(endpoint, body, token = null) {
try { try {
data = text ? JSON.parse(text) : null; data = text ? JSON.parse(text) : null;
if (data && typeof data === 'object' && 'data' in data) { if (data && typeof data === "object" && "data" in data) {
data = data.data; data = data.data;
} }
} catch { } catch {
data = text; data = text;
} }
const message = typeof data === 'object' && data?.message ? data.message : null; const message =
typeof data === "object" && data?.message ? data.message : null;
return { status: res.status, data, ok: res.ok || res.status === 206, message }; return {
status: res.status,
data,
ok: res.ok || res.status === 206,
message,
};
} }
async function reportFetch(endpoint, body) { async function reportFetch(endpoint, body) {
const res = await fetch(buildApiUrl(REPORT_API_BASE, endpoint), { const res = await fetch(buildApiUrl(REPORT_API_BASE, endpoint), {
method: 'POST', method: "POST",
headers: { headers: {
'Content-Type': 'application/json', "Content-Type": "application/json",
}, },
body: JSON.stringify(body), body: JSON.stringify(body),
}); });
@ -604,22 +539,28 @@ async function reportFetch(endpoint, body) {
try { try {
data = text ? JSON.parse(text) : null; data = text ? JSON.parse(text) : null;
if (data && typeof data === 'object' && 'data' in data) { if (data && typeof data === "object" && "data" in data) {
data = data.data; data = data.data;
} }
} catch { } catch {
data = text; data = text;
} }
const message = typeof data === 'object' && data?.message ? data.message : null; const message =
typeof data === "object" && data?.message ? data.message : null;
return { status: res.status, data, ok: res.ok || res.status === 206, message }; return {
status: res.status,
data,
ok: res.ok || res.status === 206,
message,
};
} }
// ─── Rent Properties ─── // ─── Rent Properties ───
export async function getRentProperties() { export async function getRentProperties() {
return apiFetch('/RentProperties/GetRentProperties'); return apiFetch("/RentProperties/GetRentProperties");
} }
export async function getRentProperty(id) { export async function getRentProperty(id) {
@ -628,20 +569,22 @@ export async function getRentProperty(id) {
export async function getRentPropertyLocations(params = {}) { export async function getRentPropertyLocations(params = {}) {
const qs = new URLSearchParams(); const qs = new URLSearchParams();
if (params.maxOffset != null) qs.set('maxOffset', params.maxOffset); if (params.maxOffset != null) qs.set("maxOffset", params.maxOffset);
if (params.minOffset != null) qs.set('minOffset', params.minOffset); if (params.minOffset != null) qs.set("minOffset", params.minOffset);
const query = qs.toString(); const query = qs.toString();
return apiFetch(`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ''}`); return apiFetch(
`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ""}`,
);
} }
// ─── Sale Properties ─── // ─── Sale Properties ───
export async function getSaleProperties() { export async function getSaleProperties() {
return apiFetch('/SaleProperties/GetSaleProperties'); return apiFetch("/SaleProperties/GetSaleProperties");
} }
export async function getSaleProperty(id) { export async function getSaleProperty(id) {
const items = await apiFetch('/SaleProperties/GetSaleProperties'); const items = await apiFetch("/SaleProperties/GetSaleProperties");
if (!Array.isArray(items)) return items; if (!Array.isArray(items)) return items;
return items.find((p) => p.id == id) || items[0]; return items.find((p) => p.id == id) || items[0];
} }
@ -655,7 +598,7 @@ export async function getProperty(id) {
// ─── Recommendations ─── // ─── Recommendations ───
export async function getRecommendations() { export async function getRecommendations() {
return apiFetch('/Recommendations/GetRecommendations'); return apiFetch("/Recommendations/GetRecommendations");
} }
export async function getTopRecommendations(count = 10) { export async function getTopRecommendations(count = 10) {
@ -664,36 +607,46 @@ export async function getTopRecommendations(count = 10) {
// ─── Reservations ─── // ─── Reservations ───
export async function getAvailableDateRanges(propertyId, fromDate = null, toDate = null) { export async function getAvailableDateRanges(
propertyId,
fromDate = null,
toDate = null,
) {
const qs = new URLSearchParams(); const qs = new URLSearchParams();
if (fromDate) qs.set('fromDate', fromDate); if (fromDate) qs.set("fromDate", fromDate);
if (toDate) qs.set('toDate', toDate); if (toDate) qs.set("toDate", toDate);
const query = qs.toString(); const query = qs.toString();
return apiFetch( return apiFetch(
`/Reservations/GetAvailableDates/available/${propertyId}${query ? `?${query}` : ''}` `/Reservations/GetAvailableDates/available/${propertyId}${query ? `?${query}` : ""}`,
); );
} }
export async function getReservations() { export async function getReservations() {
return apiFetch('/Reservations/GetAllReservations'); return apiFetch("/Reservations/GetAllReservations");
} }
export async function getReservation(id) { export async function getReservation(id) {
return apiFetch(`/Reservations/GetReservation?id=${id}`); return apiFetch(`/Reservations/GetReservation?id=${id}`);
} }
export async function checkAvailability(propertyId, fromDate = null, toDate = null) { export async function checkAvailability(
propertyId,
fromDate = null,
toDate = null,
) {
const qs = new URLSearchParams(); const qs = new URLSearchParams();
if (fromDate) qs.set('fromDate', fromDate); if (fromDate) qs.set("fromDate", fromDate);
if (toDate) qs.set('toDate', toDate); if (toDate) qs.set("toDate", toDate);
const query = qs.toString(); const query = qs.toString();
return apiFetch(`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ''}`); return apiFetch(
`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ""}`,
);
} }
export async function bookReservation(propertyInfoId, startDate, endDate) { export async function bookReservation(propertyInfoId, startDate, endDate) {
return apiFetch('/Reservations/BookReservation/book', { return apiFetch("/Reservations/BookReservation/book", {
method: 'POST', method: "POST",
body: { body: {
propertyInfoId, propertyInfoId,
startDate, startDate,
@ -705,11 +658,11 @@ export async function bookReservation(propertyInfoId, startDate, endDate) {
// ─── Terms ─── // ─── Terms ───
export async function getARTerms() { export async function getARTerms() {
return apiFetch('/Configuration/GetARTerms'); return apiFetch("/Configuration/GetARTerms");
} }
export async function getENTerms() { export async function getENTerms() {
return apiFetch('/Configuration/GetENTerms'); return apiFetch("/Configuration/GetENTerms");
} }
// ─── Profile ─── // ─── Profile ───
@ -725,39 +678,39 @@ export async function getOwnerByUserId(userId) {
// ─── Properties ─── // ─── Properties ───
export async function getMyRentListings() { export async function getMyRentListings() {
return apiFetch('/RentProperties/GetMyRentListings'); return apiFetch("/RentProperties/GetMyRentListings");
} }
export async function addRentProperty(data) { export async function addRentProperty(data) {
return apiFetch('/RentProperties/AddRentProperty', { return apiFetch("/RentProperties/AddRentProperty", {
method: 'POST', method: "POST",
body: data, body: data,
}); });
} }
export async function editRentProperty(id, data) { export async function editRentProperty(id, data) {
return apiFetch(`/RentProperties/EditRentProperty/${id}`, { return apiFetch(`/RentProperties/EditRentProperty/${id}`, {
method: 'PUT', method: "PUT",
body: data, body: data,
}); });
} }
export async function editSaleProperty(id, data) { export async function editSaleProperty(id, data) {
return apiFetch(`/SaleProperties/EditSaleProperty/${id}`, { return apiFetch(`/SaleProperties/EditSaleProperty/${id}`, {
method: 'PUT', method: "PUT",
body: data, body: data,
}); });
} }
export async function addSaleProperty(data) { export async function addSaleProperty(data) {
return apiFetch('/SaleProperties/AddSaleProperty', { return apiFetch("/SaleProperties/AddSaleProperty", {
method: 'POST', method: "POST",
body: data, body: data,
}); });
} }
export async function getMySaleListings() { export async function getMySaleListings() {
return apiFetch('/SaleProperties/GetMySaleListings'); return apiFetch("/SaleProperties/GetMySaleListings");
} }
export async function getSalePropertyById(id) { export async function getSalePropertyById(id) {
@ -766,14 +719,14 @@ export async function getSalePropertyById(id) {
export async function updateRentPropertyStatus(id, status) { export async function updateRentPropertyStatus(id, status) {
return apiFetch(`/RentProperties/UpdateStatus/${id}`, { return apiFetch(`/RentProperties/UpdateStatus/${id}`, {
method: 'PUT', method: "PUT",
body: { status }, body: { status },
}); });
} }
export async function updateSalePropertyStatus(id, status) { export async function updateSalePropertyStatus(id, status) {
return apiFetch(`/SaleProperties/UpdateStatus/${id}`, { return apiFetch(`/SaleProperties/UpdateStatus/${id}`, {
method: 'PUT', method: "PUT",
body: { status }, body: { status },
}); });
} }
@ -781,19 +734,19 @@ export async function updateSalePropertyStatus(id, status) {
// ─── Currencies ─── // ─── Currencies ───
export async function getCurrencies() { export async function getCurrencies() {
return apiFetch('/Currency/GetAll'); return apiFetch("/Currency/GetAll");
} }
// ─── Files ─── // ─── Files ───
export async function uploadPicture(file) { export async function uploadPicture(file) {
const formData = new FormData(); const formData = new FormData();
formData.append('image', file); formData.append("image", file);
const token = AuthService.getToken(); const token = AuthService.getToken();
const res = await fetch(`${API_BASE}/Files/UploadPicture`, { const res = await fetch(`${API_BASE}/Files/UploadPicture`, {
method: 'POST', method: "POST",
headers: { headers: {
...(token && { Authorization: `Bearer ${token}` }), ...(token && { Authorization: `Bearer ${token}` }),
}, },
@ -820,7 +773,7 @@ async function multipartAuthFetch(endpoint, formData) {
const token = AuthService.getToken(); const token = AuthService.getToken();
const res = await fetch(`${API_BASE}${endpoint}`, { const res = await fetch(`${API_BASE}${endpoint}`, {
method: 'POST', method: "POST",
headers: { headers: {
...(token && { Authorization: `Bearer ${token}` }), ...(token && { Authorization: `Bearer ${token}` }),
}, },
@ -834,100 +787,129 @@ async function multipartAuthFetch(endpoint, formData) {
try { try {
data = text ? JSON.parse(text) : null; data = text ? JSON.parse(text) : null;
if (data && typeof data === 'object' && 'data' in data) { if (data && typeof data === "object" && "data" in data) {
data = data.data; data = data.data;
} }
} catch { } catch {
data = text; data = text;
} }
return { status: res.status, data, ok: res.ok || res.status === 206, message: data?.message }; return {
status: res.status,
data,
ok: res.ok || res.status === 206,
message: data?.message,
};
} }
export async function addOwner(data, frontImage = null, backImage = null, licenseImage = null) { export async function addOwner(
data,
frontImage = null,
backImage = null,
licenseImage = null,
) {
const formData = new FormData(); const formData = new FormData();
formData.append('FirstName', data.firstName || data.FirstName || ''); formData.append("FirstName", data.firstName || data.FirstName || "");
formData.append('LastName', data.lastName || data.LastName || ''); formData.append("LastName", data.lastName || data.LastName || "");
formData.append('Email', data.email || data.Email || ''); formData.append("Email", data.email || data.Email || "");
const phoneValue = data.phone || data.phoneNumber || data.Phone || data.PhoneNumber || ''; const phoneValue =
data.phone || data.phoneNumber || data.Phone || data.PhoneNumber || "";
const whatsappValue = const whatsappValue =
data.whatsAppNumber || data.whatsapp || data.WhatsAppNumber || data.WhatsApp || ''; data.whatsAppNumber ||
data.whatsapp ||
data.WhatsAppNumber ||
data.WhatsApp ||
"";
formData.append('PhoneNumber', phoneValue); formData.append("PhoneNumber", phoneValue);
formData.append('Phone', phoneValue); formData.append("Phone", phoneValue);
formData.append('WhatsAppNumber', whatsappValue); formData.append("WhatsAppNumber", whatsappValue);
formData.append('NationalNumber', data.nationalNumber || data.NationalNumber || ''); formData.append(
formData.append('Password', data.password || data.Password || ''); "NationalNumber",
formData.append('Type', String(data.type ?? data.ownerType ?? data.Type ?? 0)); data.nationalNumber || data.NationalNumber || "",
formData.append('Language', String(data.language ?? data.Language ?? 1)); );
formData.append("Password", data.password || data.Password || "");
formData.append(
"Type",
String(data.type ?? data.ownerType ?? data.Type ?? 0),
);
formData.append("Language", String(data.language ?? data.Language ?? 1));
if (frontImage) formData.append('FrontIdCarImagePath', frontImage); if (frontImage) formData.append("FrontIdCarImagePath", frontImage);
if (backImage) formData.append('RearIdCarImagePath', backImage); if (backImage) formData.append("RearIdCarImagePath", backImage);
if (licenseImage) formData.append('LicenseImagePath', licenseImage); if (licenseImage) formData.append("LicenseImagePath", licenseImage);
return multipartAuthFetch('/Owner/Add', formData); return multipartAuthFetch("/Owner/Add", formData);
} }
export async function addCustomer(data, frontImage = null, backImage = null) { export async function addCustomer(data, frontImage = null, backImage = null) {
const formData = new FormData(); const formData = new FormData();
formData.append('FirstName', data.firstName || data.FirstName || ''); formData.append("FirstName", data.firstName || data.FirstName || "");
formData.append('LastName', data.lastName || data.LastName || ''); formData.append("LastName", data.lastName || data.LastName || "");
formData.append('Email', data.email || ''); formData.append("Email", data.email || "");
formData.append('PhoneNumber', data.phoneNumber || ''); formData.append("PhoneNumber", data.phoneNumber || "");
formData.append('WhatsAppNumber', data.whatsAppNumber || ''); formData.append("WhatsAppNumber", data.whatsAppNumber || "");
formData.append('Phone', data.phone || ''); formData.append("Phone", data.phone || "");
formData.append('NationalNumber', data.nationalNumber || ''); formData.append("NationalNumber", data.nationalNumber || "");
formData.append('Password', data.password || ''); formData.append("Password", data.password || "");
formData.append('Type', String(data.customerType ?? data.Type ?? 0)); formData.append("Type", String(data.customerType ?? data.Type ?? 0));
formData.append('Language', '0'); formData.append("Language", "0");
if (frontImage) formData.append('FrontIdCarImagePath', frontImage); if (frontImage) formData.append("FrontIdCarImagePath", frontImage);
if (backImage) formData.append('RearIdCarImagePath', backImage); if (backImage) formData.append("RearIdCarImagePath", backImage);
return multipartAuthFetch('/Customer/Add', formData); return multipartAuthFetch("/Customer/Add", formData);
} }
// ─── Auth: Login ─── // ─── Auth: Login ───
export async function loginWithEmail(credential, password) { export async function loginWithEmail(credential, password) {
return authFetch('/Auth/LogInWithEmail', { return authFetch("/Auth/LogInWithEmail", {
credential, credential,
password, password,
device: 0, device: 0,
appVersion: '', appVersion: "",
}); });
} }
export async function loginWithPhone(credential, password) { export async function loginWithPhone(credential, password) {
return authFetch('/Auth/LogInWithPhoneNumber', { return authFetch("/Auth/LogInWithPhoneNumber", {
credential, credential,
password, password,
device: 0, device: 0,
appVersion: '', appVersion: "",
}); });
} }
// ─── Auth: OTP ─── // ─── Auth: OTP ───
export async function sendEmailOTP() { export async function sendEmailOTP() {
return apiFetch('/Auth/SendEmailOTP', { method: 'POST' }); return apiFetch("/Auth/SendEmailOTP", { method: "POST" });
} }
export async function sendPhoneOTP() { export async function sendPhoneOTP() {
return apiFetch('/Auth/SendPhoneNumberOTP', { method: 'POST' }); return apiFetch("/Auth/SendPhoneNumberOTP", { method: "POST" });
} }
export async function verifyEmail(code) { export async function verifyEmail(code) {
const token = AuthService.getToken(); const token = AuthService.getToken();
return authFetch(`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`, {}, token); return authFetch(
`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`,
{},
token,
);
} }
export async function verifyPhone(code) { export async function verifyPhone(code) {
const token = AuthService.getToken(); const token = AuthService.getToken();
return authFetch(`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`, {}, token); return authFetch(
`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`,
{},
token,
);
} }
// ─── Helpers ─── // ─── Helpers ───
@ -937,39 +919,83 @@ export function isEmail(value) {
} }
export function isPhoneNumber(value) { export function isPhoneNumber(value) {
return /^\+?\d{7,15}$/.test(value.replace(/[\s\-()]/g, '')); return /^\+?\d{7,15}$/.test(value.replace(/[\s\-()]/g, ""));
} }
// ─── Favorites ─── // ─── Favorites ───
export async function getUserFavoriteProperties() { export async function getUserFavoriteProperties() {
return apiFetch('/FavoriteProperty/GetUserFavoriteProperties'); return apiFetch("/FavoriteProperty/GetUserFavoriteProperties");
} }
export async function addFavoriteProperty(propId) { export async function addFavoriteProperty(propId) {
return apiFetch(`/FavoriteProperty/Add?propId=${propId}`, { method: 'POST' }); return apiFetch(`/FavoriteProperty/Add?propId=${propId}`, { method: "POST" });
} }
export async function removeFavoriteProperty(favePropId) { export async function removeFavoriteProperty(favePropId) {
return apiFetch(`/FavoriteProperty/Remove?favePropId=${favePropId}`, { method: 'DELETE' }); return apiFetch(`/FavoriteProperty/Remove?favePropId=${favePropId}`, {
method: "DELETE",
});
} }
export async function getUserNotifications() { export async function getUserNotifications() {
return apiFetch('/Notifications/GetUserNotifications'); return apiFetch("/Notifications/GetUserNotifications");
} }
// ─── Booking/Reservation Management ─── // ─── Booking/Reservation Management ───
export async function confirmDepositPayment(bookingId) { export async function confirmDepositPayment(bookingId) {
return apiFetch('/Reservations/ConfirmDepositPayment', { return apiFetch("/Reservations/ConfirmDepositPayment", {
method: 'POST', method: "POST",
body: { bookingId }, body: { bookingId },
}); });
} }
export async function adminConfirmDeposit(
reservationId,
adminId,
comment = null,
) {
const token = AuthService.getToken();
const endpoint = `${API_BASE}/Reservations/AdminConfirmDeposit/admin-confirm-deposit`;
const normalizedComment =
typeof comment === "string" && comment.trim() ? comment.trim() : null;
const payload = {
reservationId,
adminId,
comment: normalizedComment,
};
const res = await fetch(endpoint, {
method: "PUT",
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
},
body: JSON.stringify(payload),
});
const text = await res.text();
let data = null;
try {
data = text ? JSON.parse(text) : null;
if (data && typeof data === "object" && "data" in data) {
data = data.data;
}
} catch {
data = text;
}
const message =
typeof data === "object" && data?.message ? data.message : null;
return { status: res.status, data, ok: res.ok, message };
}
export async function updateBookingStatus(bookingId, status) { export async function updateBookingStatus(bookingId, status) {
return apiFetch('/Reservations/UpdateStatus', { return apiFetch("/Reservations/UpdateStatus", {
method: 'PUT', method: "PUT",
body: { bookingId, status }, body: { bookingId, status },
}); });
} }
@ -977,31 +1003,31 @@ export async function updateBookingStatus(bookingId, status) {
// ─── Owner / Reservations ─── // ─── Owner / Reservations ───
export async function getOwnerReservationRequests() { export async function getOwnerReservationRequests() {
return apiFetch('/Reservations/GetOwnerResevationRequests'); return apiFetch("/Reservations/GetOwnerResevationRequests");
} }
export async function getOwnerReservationsByStatuses(filterStatuses) { export async function getOwnerReservationsByStatuses(filterStatuses) {
return apiFetch('/Reservations/GetAllReservationsByStateForOwner', { return apiFetch("/Reservations/GetAllReservationsByStateForOwner", {
method: 'POST', method: "POST",
body: { filterStatuses }, body: { filterStatuses },
}); });
} }
export async function getUserReservations() { export async function getUserReservations() {
return apiFetch('/Reservations/GetUserResevations'); return apiFetch("/Reservations/GetUserResevations");
} }
export async function ownerConfirmReservation(id) { export async function ownerConfirmReservation(id) {
return apiFetch(`/Reservations/OwnerConfirmReservation/owner-confirm/${id}`, { return apiFetch(`/Reservations/OwnerConfirmReservation/owner-confirm/${id}`, {
method: 'PUT', method: "PUT",
}); });
} }
// ─── Payments ─── // ─── Payments ───
export async function payDeposit(data) { export async function payDeposit(data) {
return apiFetch('/Reservations/PayDeposit/pay-deposit', { return apiFetch("/Reservations/PayDeposit/pay-deposit", {
method: 'POST', method: "POST",
body: data, body: data,
}); });
} }
@ -1010,12 +1036,12 @@ export async function payDeposit(data) {
export async function getOwnerContactInformation(propertyInformationId) { export async function getOwnerContactInformation(propertyInformationId) {
return apiFetch( return apiFetch(
`/Owner/GetOwnerContactInformation?propertyInformationId=${propertyInformationId}` `/Owner/GetOwnerContactInformation?propertyInformationId=${propertyInformationId}`,
); );
} }
export async function getOwnerStatistics() { export async function getOwnerStatistics() {
return apiFetch('/Statistics/GetOwnerStatistics'); return apiFetch("/Statistics/GetOwnerStatistics");
} }
// ─── Agent Registration ─── // ─── Agent Registration ───
@ -1024,7 +1050,7 @@ export async function registerRealEstateAgent(formData) {
const token = AuthService.getToken(); const token = AuthService.getToken();
const res = await fetch(`${API_BASE}/RealEstateAgent/Add`, { const res = await fetch(`${API_BASE}/RealEstateAgent/Add`, {
method: 'POST', method: "POST",
headers: { headers: {
...(token && { Authorization: `Bearer ${token}` }), ...(token && { Authorization: `Bearer ${token}` }),
}, },
@ -1038,7 +1064,7 @@ export async function registerRealEstateAgent(formData) {
try { try {
data = text ? JSON.parse(text) : null; data = text ? JSON.parse(text) : null;
if (data && typeof data === 'object' && 'data' in data) data = data.data; if (data && typeof data === "object" && "data" in data) data = data.data;
} catch { } catch {
data = text; data = text;
} }
@ -1047,7 +1073,7 @@ export async function registerRealEstateAgent(formData) {
status: res.status, status: res.status,
data, data,
ok: res.ok || res.status === 206, ok: res.ok || res.status === 206,
message: data?.message || (typeof data === 'string' ? data : null), message: data?.message || (typeof data === "string" ? data : null),
}; };
} }
@ -1057,23 +1083,25 @@ export async function changePassword(oldPassword, newPassword) {
return apiFetch( return apiFetch(
`/User/ChangePassword?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`, `/User/ChangePassword?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`,
{ {
method: 'PUT', method: "PUT",
} },
); );
} }
// ─── Forget Password (OTP flow) ─── // ─── Forget Password (OTP flow) ───
export async function requestForgetPasswordOtp(email) { export async function requestForgetPasswordOtp(email) {
return apiFetch(`/User/ForgetPassword?email=${encodeURIComponent(email)}`, { method: 'POST' }); return apiFetch(`/User/ForgetPassword?email=${encodeURIComponent(email)}`, {
method: "POST",
});
} }
export async function verifyForgetPasswordOtp(email, code, newPassword) { export async function verifyForgetPasswordOtp(email, code, newPassword) {
return apiFetch( return apiFetch(
`/User/VerifyForgetPasswordOTP?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code)}&newPassword=${encodeURIComponent(newPassword)}`, `/User/VerifyForgetPasswordOTP?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code)}&newPassword=${encodeURIComponent(newPassword)}`,
{ {
method: 'POST', method: "POST",
} },
); );
} }
@ -1086,16 +1114,19 @@ export async function resetPassword(token) {
// ─── Delete Account ─── // ─── Delete Account ───
export async function deleteMyAccount(password) { export async function deleteMyAccount(password) {
return apiFetch(`/User/DeleteMyAccount?password=${encodeURIComponent(password)}`, { return apiFetch(
method: 'DELETE', `/User/DeleteMyAccount?password=${encodeURIComponent(password)}`,
}); {
method: "DELETE",
},
);
} }
// ─── Set FCM Token ─── // ─── Set FCM Token ───
export async function setFCMToken(token, deviceType = 2) { export async function setFCMToken(token, deviceType = 2) {
return apiFetch('/User/SetFCMToken', { return apiFetch("/User/SetFCMToken", {
method: 'POST', method: "POST",
body: { token, deviceType }, body: { token, deviceType },
}); });
} }
@ -1105,52 +1136,54 @@ export async function setFCMToken(token, deviceType = 2) {
export async function filterRentProperties(params = {}) { export async function filterRentProperties(params = {}) {
const qs = new URLSearchParams(); const qs = new URLSearchParams();
Object.entries(params).forEach(([k, v]) => { Object.entries(params).forEach(([k, v]) => {
if (v != null && v !== '') qs.set(k, v); if (v != null && v !== "") qs.set(k, v);
}); });
const query = qs.toString(); const query = qs.toString();
return apiFetch(`/RentProperties/FilterRentProperties${query ? `?${query}` : ''}`); return apiFetch(
`/RentProperties/FilterRentProperties${query ? `?${query}` : ""}`,
);
} }
// ─── Reports ─── // ─── Reports ───
export async function sendGeneralReport(subject, reportBody) { export async function sendGeneralReport(subject, reportBody) {
return reportFetch('/Reports/SendGeneralReport', { return reportFetch("/Reports/SendGeneralReport", {
subject, subject,
body: reportBody, body: reportBody,
}); });
} }
export async function submitReport(subject, body) { export async function submitReport(subject, body) {
return apiFetch('/Reports/SendGeneralReport', { return apiFetch("/Reports/SendGeneralReport", {
method: 'POST', method: "POST",
body: { subject, body }, body: { subject, body },
}); });
} }
export async function submitReservationReport(data) { export async function submitReservationReport(data) {
return apiFetch('/ReservationReports', { return apiFetch("/ReservationReports", {
method: 'POST', method: "POST",
body: data, body: data,
}); });
} }
export async function updateReservationReport(id, data) { export async function updateReservationReport(id, data) {
return apiFetch(`/ReservationReports/${id}`, { return apiFetch(`/ReservationReports/${id}`, {
method: 'PUT', method: "PUT",
body: data, body: data,
}); });
} }
export async function submitSaleReport(data) { export async function submitSaleReport(data) {
return apiFetch('/SaleReports', { return apiFetch("/SaleReports", {
method: 'POST', method: "POST",
body: data, body: data,
}); });
} }
export async function updateSaleReport(id, data) { export async function updateSaleReport(id, data) {
return apiFetch(`/SaleReports/${id}`, { return apiFetch(`/SaleReports/${id}`, {
method: 'PUT', method: "PUT",
body: data, body: data,
}); });
} }
@ -1158,8 +1191,8 @@ export async function updateSaleReport(id, data) {
// ─── Terms (Add or Update) ─── // ─── Terms (Add or Update) ───
export async function addOrUpdateTerms(terms) { export async function addOrUpdateTerms(terms) {
return apiFetch('/Terms/AddOrUpdateTerms', { return apiFetch("/Terms/AddOrUpdateTerms", {
method: 'POST', method: "POST",
body: terms, body: terms,
}); });
} }