2026-06-16 19:03:15 +03:00
|
|
|
import AuthService from "../services/AuthService";
|
2026-07-13 20:20:17 +03:00
|
|
|
|
|
|
|
|
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";
|
2026-03-26 22:20:33 +00:00
|
|
|
|
2026-06-06 03:55:53 -07:00
|
|
|
function isFormData(value) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return typeof FormData !== "undefined" && value instanceof FormData;
|
2026-06-06 03:55:53 -07:00
|
|
|
}
|
|
|
|
|
|
2026-06-14 18:04:05 +03:00
|
|
|
class ApiBlockedError extends Error {
|
2026-06-16 19:03:15 +03:00
|
|
|
constructor(message = "Your account is blocked") {
|
2026-06-14 18:04:05 +03:00
|
|
|
super(message);
|
2026-06-16 19:03:15 +03:00
|
|
|
this.name = "ApiBlockedError";
|
2026-06-14 18:04:05 +03:00
|
|
|
this.status = 451;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isApiBlockedError(error) {
|
|
|
|
|
return error instanceof ApiBlockedError || error?.status === 451;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function redirectToBlockedPage() {
|
2026-06-16 19:03:15 +03:00
|
|
|
if (
|
|
|
|
|
typeof window !== "undefined" &&
|
|
|
|
|
window.location.pathname !== "/blocked"
|
|
|
|
|
) {
|
|
|
|
|
window.location.replace("/blocked");
|
2026-06-14 18:04:05 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertNotBlocked(response) {
|
|
|
|
|
if (response.status === 451) {
|
|
|
|
|
redirectToBlockedPage();
|
|
|
|
|
throw new ApiBlockedError();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buildApiUrl(base, endpoint) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return `${base.replace(/\/$/, "")}${endpoint.startsWith("/") ? endpoint : `/${endpoint}`}`;
|
2026-06-14 18:04:05 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 22:20:33 +00:00
|
|
|
async function apiFetch(endpoint, options = {}) {
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
const token = AuthService.getToken();
|
2026-03-26 22:20:33 +00:00
|
|
|
|
|
|
|
|
const headers = {
|
|
|
|
|
...(token && { Authorization: `Bearer ${token}` }),
|
2026-06-06 03:55:53 -07:00
|
|
|
...(options.headers || {}),
|
2026-03-26 22:20:33 +00:00
|
|
|
};
|
|
|
|
|
|
2026-06-06 03:55:53 -07:00
|
|
|
const hasBody = options.body != null;
|
|
|
|
|
const bodyIsFormData = isFormData(options.body);
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
if (
|
|
|
|
|
hasBody &&
|
|
|
|
|
!bodyIsFormData &&
|
|
|
|
|
!headers["Content-Type"] &&
|
|
|
|
|
!headers["content-type"]
|
|
|
|
|
) {
|
|
|
|
|
headers["Content-Type"] = "application/json";
|
2026-06-06 03:55:53 -07:00
|
|
|
}
|
|
|
|
|
|
2026-06-14 08:22:59 -07:00
|
|
|
const url = `${API_BASE}${endpoint}`;
|
|
|
|
|
|
2026-03-26 22:46:57 +00:00
|
|
|
try {
|
2026-07-13 20:20:17 +03:00
|
|
|
const res = await fetch(url, {
|
|
|
|
|
...options,
|
|
|
|
|
headers,
|
|
|
|
|
body:
|
|
|
|
|
hasBody && !bodyIsFormData && typeof options.body !== "string"
|
|
|
|
|
? JSON.stringify(options.body)
|
|
|
|
|
: options.body,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assertNotBlocked(res);
|
|
|
|
|
|
|
|
|
|
if (!res.ok && res.status !== 206) {
|
|
|
|
|
const text = await res.text().catch(() => "");
|
|
|
|
|
throw new Error(`API ${res.status}: ${text || res.statusText}`);
|
2026-03-26 22:46:57 +00:00
|
|
|
}
|
2026-07-13 20:20:17 +03:00
|
|
|
|
|
|
|
|
const text = await res.text();
|
|
|
|
|
if (!text) return null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const json = JSON.parse(text);
|
|
|
|
|
if (json && typeof json === "object" && "data" in json) {
|
|
|
|
|
return json.data;
|
|
|
|
|
}
|
|
|
|
|
return json;
|
|
|
|
|
} catch {
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (error instanceof TypeError && error.message === 'Failed to fetch') {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`تعذر الاتصال بالخادم. تحقق من اتصالك بالإنترنت أو حاول مرة أخرى لاحقاً. (${API_BASE}${endpoint})`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
throw error;
|
2026-03-26 22:46:57 +00:00
|
|
|
}
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-28 16:17:14 +00:00
|
|
|
async function authFetch(endpoint, body, token = null) {
|
2026-06-06 03:55:53 -07:00
|
|
|
const headers = {};
|
|
|
|
|
|
|
|
|
|
const bodyIsFormData = isFormData(body);
|
|
|
|
|
if (!bodyIsFormData) {
|
2026-06-16 19:03:15 +03:00
|
|
|
headers["Content-Type"] = "application/json";
|
2026-06-06 03:55:53 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-28 16:17:14 +00:00
|
|
|
if (token) {
|
2026-06-16 19:03:15 +03:00
|
|
|
headers["Authorization"] = `Bearer ${token}`;
|
2026-03-28 16:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-13 20:20:17 +03:00
|
|
|
let res;
|
|
|
|
|
try {
|
|
|
|
|
res = await fetch(`${API_BASE}${endpoint}`, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers,
|
|
|
|
|
body: bodyIsFormData ? body : JSON.stringify(body),
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return { status: 0, data: null, ok: false, message: err.message };
|
|
|
|
|
}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-06-14 18:04:05 +03:00
|
|
|
assertNotBlocked(res);
|
|
|
|
|
|
|
|
|
|
const text = await res.text();
|
|
|
|
|
let data = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
data = text ? JSON.parse(text) : null;
|
2026-06-16 19:03:15 +03:00
|
|
|
if (data && typeof data === "object" && "data" in data) {
|
2026-06-14 18:04:05 +03:00
|
|
|
data = data.data;
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
data = text;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
const message =
|
|
|
|
|
typeof data === "object" && data?.message ? data.message : null;
|
2026-06-14 18:04:05 +03:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
return {
|
|
|
|
|
status: res.status,
|
|
|
|
|
data,
|
|
|
|
|
ok: res.ok || res.status === 206,
|
|
|
|
|
message,
|
|
|
|
|
};
|
2026-06-14 18:04:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function reportFetch(endpoint, body) {
|
2026-07-13 20:20:17 +03:00
|
|
|
let res;
|
|
|
|
|
try {
|
|
|
|
|
res = await fetch(buildApiUrl(REPORT_API_BASE, endpoint), {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return { status: 0, data: null, ok: false, message: err.message };
|
|
|
|
|
}
|
2026-06-14 18:04:05 +03:00
|
|
|
|
|
|
|
|
assertNotBlocked(res);
|
|
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
const text = await res.text();
|
|
|
|
|
let data = null;
|
2026-06-06 03:55:53 -07:00
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
try {
|
|
|
|
|
data = text ? JSON.parse(text) : null;
|
2026-06-16 19:03:15 +03:00
|
|
|
if (data && typeof data === "object" && "data" in data) {
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
data = data.data;
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
data = text;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
const message =
|
|
|
|
|
typeof data === "object" && data?.message ? data.message : null;
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
return {
|
|
|
|
|
status: res.status,
|
|
|
|
|
data,
|
|
|
|
|
ok: res.ok || res.status === 206,
|
|
|
|
|
message,
|
|
|
|
|
};
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 22:20:33 +00:00
|
|
|
export async function getRentProperties() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/RentProperties/GetRentProperties");
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getRentProperty(id) {
|
2026-03-28 15:29:06 +00:00
|
|
|
return apiFetch(`/RentProperties/GetRentPropertyById/${id}`);
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getRentPropertyLocations(params = {}) {
|
|
|
|
|
const qs = new URLSearchParams();
|
2026-06-16 19:03:15 +03:00
|
|
|
if (params.maxOffset != null) qs.set("maxOffset", params.maxOffset);
|
|
|
|
|
if (params.minOffset != null) qs.set("minOffset", params.minOffset);
|
2026-03-26 22:20:33 +00:00
|
|
|
const query = qs.toString();
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch(
|
|
|
|
|
`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ""}`,
|
|
|
|
|
);
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getSaleProperties() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/SaleProperties/GetSaleProperties");
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getSaleProperty(id) {
|
2026-06-16 19:03:15 +03:00
|
|
|
const items = await apiFetch("/SaleProperties/GetSaleProperties");
|
2026-03-26 23:27:28 +00:00
|
|
|
if (!Array.isArray(items)) return items;
|
2026-06-06 03:55:53 -07:00
|
|
|
return items.find((p) => p.id == id) || items[0];
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getProperty(id) {
|
|
|
|
|
return apiFetch(`/Properties/Get/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getRecommendations() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Recommendations/GetRecommendations");
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getTopRecommendations(count = 10) {
|
2026-03-26 22:46:57 +00:00
|
|
|
return apiFetch(`/Recommendations/GetTopRecommendations?count=${count}`);
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
export async function getAvailableDateRanges(
|
|
|
|
|
propertyId,
|
|
|
|
|
fromDate = null,
|
|
|
|
|
toDate = null,
|
|
|
|
|
) {
|
2026-04-28 12:57:06 -07:00
|
|
|
const qs = new URLSearchParams();
|
2026-06-16 19:03:15 +03:00
|
|
|
if (fromDate) qs.set("fromDate", fromDate);
|
|
|
|
|
if (toDate) qs.set("toDate", toDate);
|
2026-04-28 12:57:06 -07:00
|
|
|
const query = qs.toString();
|
|
|
|
|
|
|
|
|
|
return apiFetch(
|
2026-06-16 19:03:15 +03:00
|
|
|
`/Reservations/GetAvailableDates/available/${propertyId}${query ? `?${query}` : ""}`,
|
2026-04-28 12:57:06 -07:00
|
|
|
);
|
2026-03-29 21:16:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 22:20:33 +00:00
|
|
|
export async function getReservations() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/GetAllReservations");
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getReservation(id) {
|
2026-03-26 22:46:57 +00:00
|
|
|
return apiFetch(`/Reservations/GetReservation?id=${id}`);
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
export async function checkAvailability(
|
|
|
|
|
propertyId,
|
|
|
|
|
fromDate = null,
|
|
|
|
|
toDate = null,
|
|
|
|
|
) {
|
2026-03-26 22:20:33 +00:00
|
|
|
const qs = new URLSearchParams();
|
2026-06-16 19:03:15 +03:00
|
|
|
if (fromDate) qs.set("fromDate", fromDate);
|
|
|
|
|
if (toDate) qs.set("toDate", toDate);
|
2026-03-26 22:20:33 +00:00
|
|
|
const query = qs.toString();
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch(
|
|
|
|
|
`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ""}`,
|
|
|
|
|
);
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-28 12:57:06 -07:00
|
|
|
export async function bookReservation(propertyInfoId, startDate, endDate) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/BookReservation/book", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: {
|
|
|
|
|
propertyInfoId,
|
|
|
|
|
startDate,
|
|
|
|
|
endDate,
|
|
|
|
|
},
|
2026-03-26 22:20:33 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 13:59:17 +03:00
|
|
|
export async function getARTerms() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Configuration/GetARTerms");
|
2026-06-16 13:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getENTerms() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Configuration/GetENTerms");
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
|
2026-03-28 17:03:40 +00:00
|
|
|
export async function getCustomerByUserId(userId) {
|
|
|
|
|
return apiFetch(`/Customer/GetByUserId/${userId}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerByUserId(userId) {
|
|
|
|
|
return apiFetch(`/Owner/GetByUserId/${userId}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 18:46:12 +00:00
|
|
|
export async function getMyRentListings() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/RentProperties/GetMyRentListings");
|
2026-03-29 22:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-04 12:24:13 +03:00
|
|
|
export function buildRentPropertyPayload(data = {}) {
|
|
|
|
|
const propertyInformation = data?.propertyInformation || {};
|
2026-07-16 10:56:59 -07:00
|
|
|
|
2026-07-15 19:42:59 +03:00
|
|
|
const rawCityValue =
|
2026-07-04 12:24:13 +03:00
|
|
|
data?.city ??
|
|
|
|
|
data?.governorate ??
|
|
|
|
|
propertyInformation?.city ??
|
|
|
|
|
propertyInformation?.governorate ??
|
2026-07-16 10:56:59 -07:00
|
|
|
1;
|
|
|
|
|
|
|
|
|
|
const cityInt = parseInt(rawCityValue, 10) || 1;
|
|
|
|
|
|
2026-07-04 12:24:13 +03:00
|
|
|
const documentTypeValue =
|
2026-07-16 10:56:59 -07:00
|
|
|
data?.documentType ?? propertyInformation?.documentType ?? 1;
|
2026-07-04 12:24:13 +03:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...data,
|
2026-07-16 10:56:59 -07:00
|
|
|
city: cityInt,
|
|
|
|
|
governorate: cityInt,
|
2026-07-04 12:24:13 +03:00
|
|
|
documentType: documentTypeValue,
|
|
|
|
|
propertyInformation: {
|
|
|
|
|
...propertyInformation,
|
2026-07-16 10:56:59 -07:00
|
|
|
city: cityInt,
|
|
|
|
|
governorate: cityInt,
|
2026-07-04 12:24:13 +03:00
|
|
|
documentType: documentTypeValue,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 18:00:44 +00:00
|
|
|
export async function addRentProperty(data) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/RentProperties/AddRentProperty", {
|
|
|
|
|
method: "POST",
|
2026-07-16 10:56:59 -07:00
|
|
|
body: buildRentPropertyPayload(data),
|
2026-03-28 18:00:44 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-25 21:27:39 +03:00
|
|
|
export async function editRentProperty(id, data) {
|
|
|
|
|
return apiFetch(`/RentProperties/EditRentProperty/${id}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
2026-07-25 13:26:48 +03:00
|
|
|
body: { rentPropertyDto: buildRentPropertyPayload(data) },
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-26 04:35:03 +03:00
|
|
|
export async function editSaleProperty(id, data) {
|
|
|
|
|
return apiFetch(`/SaleProperties/EditSaleProperty/${id}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-26 04:35:03 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-25 21:27:39 +03:00
|
|
|
export async function addSaleProperty(data) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/SaleProperties/AddSaleProperty", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getMySaleListings() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/SaleProperties/GetMySaleListings");
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getSalePropertyById(id) {
|
|
|
|
|
return apiFetch(`/SaleProperties/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 18:21:52 +03:00
|
|
|
export async function updateRentPropertyStatus(id, status) {
|
|
|
|
|
return apiFetch(`/RentProperties/UpdateStatus/${id}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
2026-06-09 18:21:52 +03:00
|
|
|
body: { status },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateSalePropertyStatus(id, status) {
|
|
|
|
|
return apiFetch(`/SaleProperties/UpdateStatus/${id}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
2026-06-09 18:21:52 +03:00
|
|
|
body: { status },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 19:40:03 +00:00
|
|
|
export async function getCurrencies() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Currency/GetAll");
|
2026-03-28 19:40:03 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-04 01:49:04 +03:00
|
|
|
export async function getPaymentTypes() {
|
|
|
|
|
return apiFetch("/PaymentType/GetAll");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 00:57:52 +00:00
|
|
|
export async function uploadPicture(file) {
|
|
|
|
|
const formData = new FormData();
|
2026-06-16 19:03:15 +03:00
|
|
|
formData.append("image", file);
|
2026-06-06 03:55:53 -07:00
|
|
|
|
2026-03-30 00:57:52 +00:00
|
|
|
const token = AuthService.getToken();
|
2026-04-28 12:57:06 -07:00
|
|
|
|
2026-07-13 20:20:17 +03:00
|
|
|
let res;
|
|
|
|
|
try {
|
|
|
|
|
res = await fetch(`${API_BASE}/Files/UploadPicture`, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
...(token && { Authorization: `Bearer ${token}` }),
|
|
|
|
|
},
|
|
|
|
|
body: formData,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw new Error(`تعذر الاتصال بالخادم: ${err.message}`);
|
|
|
|
|
}
|
2026-04-28 12:57:06 -07:00
|
|
|
|
2026-06-14 18:04:05 +03:00
|
|
|
assertNotBlocked(res);
|
|
|
|
|
|
2026-03-30 00:57:52 +00:00
|
|
|
const text = await res.text();
|
2026-04-28 12:57:06 -07:00
|
|
|
|
2026-03-30 00:57:52 +00:00
|
|
|
if (!res.ok) throw new Error(`Upload failed: ${res.status} ${text}`);
|
2026-04-28 12:57:06 -07:00
|
|
|
|
2026-03-30 00:57:52 +00:00
|
|
|
try {
|
|
|
|
|
const json = JSON.parse(text);
|
|
|
|
|
return json?.data || json;
|
|
|
|
|
} catch {
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 15:15:09 +00:00
|
|
|
async function multipartAuthFetch(endpoint, formData) {
|
2026-06-06 03:55:53 -07:00
|
|
|
const token = AuthService.getToken();
|
|
|
|
|
|
2026-03-28 15:15:09 +00:00
|
|
|
const res = await fetch(`${API_BASE}${endpoint}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
headers: {
|
|
|
|
|
...(token && { Authorization: `Bearer ${token}` }),
|
|
|
|
|
},
|
2026-03-28 15:15:09 +00:00
|
|
|
body: formData,
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-14 18:04:05 +03:00
|
|
|
assertNotBlocked(res);
|
|
|
|
|
|
2026-03-28 15:15:09 +00:00
|
|
|
const text = await res.text();
|
|
|
|
|
let data = null;
|
2026-04-28 12:57:06 -07:00
|
|
|
|
2026-03-28 15:15:09 +00:00
|
|
|
try {
|
|
|
|
|
data = text ? JSON.parse(text) : null;
|
2026-06-16 19:03:15 +03:00
|
|
|
if (data && typeof data === "object" && "data" in data) {
|
2026-03-28 15:15:09 +00:00
|
|
|
data = data.data;
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
data = text;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
return {
|
|
|
|
|
status: res.status,
|
|
|
|
|
data,
|
|
|
|
|
ok: res.ok || res.status === 206,
|
|
|
|
|
message: data?.message,
|
|
|
|
|
};
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
export async function addOwner(
|
|
|
|
|
data,
|
|
|
|
|
frontImage = null,
|
|
|
|
|
backImage = null,
|
|
|
|
|
licenseImage = null,
|
|
|
|
|
) {
|
2026-03-28 15:15:09 +00:00
|
|
|
const formData = new FormData();
|
2026-06-05 18:33:51 -07:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
formData.append("FirstName", data.firstName || data.FirstName || "");
|
|
|
|
|
formData.append("LastName", data.lastName || data.LastName || "");
|
|
|
|
|
formData.append("Email", data.email || data.Email || "");
|
2026-06-05 18:33:51 -07:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
const phoneValue =
|
|
|
|
|
data.phone || data.phoneNumber || data.Phone || data.PhoneNumber || "";
|
2026-06-05 18:33:51 -07:00
|
|
|
const whatsappValue =
|
2026-06-16 19:03:15 +03:00
|
|
|
data.whatsAppNumber ||
|
|
|
|
|
data.whatsapp ||
|
|
|
|
|
data.WhatsAppNumber ||
|
|
|
|
|
data.WhatsApp ||
|
|
|
|
|
"";
|
|
|
|
|
|
|
|
|
|
formData.append("PhoneNumber", phoneValue);
|
|
|
|
|
formData.append("Phone", phoneValue);
|
|
|
|
|
formData.append("WhatsAppNumber", whatsappValue);
|
|
|
|
|
|
|
|
|
|
formData.append(
|
|
|
|
|
"NationalNumber",
|
|
|
|
|
data.nationalNumber || data.NationalNumber || "",
|
|
|
|
|
);
|
|
|
|
|
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));
|
2026-03-28 15:15:09 +00:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
if (frontImage) formData.append("FrontIdCarImagePath", frontImage);
|
|
|
|
|
if (backImage) formData.append("RearIdCarImagePath", backImage);
|
|
|
|
|
if (licenseImage) formData.append("LicenseImagePath", licenseImage);
|
2026-03-28 15:15:09 +00:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
return multipartAuthFetch("/Owner/Add", formData);
|
2026-03-28 15:15:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addCustomer(data, frontImage = null, backImage = null) {
|
|
|
|
|
const formData = new FormData();
|
2026-06-16 19:03:15 +03:00
|
|
|
formData.append("FirstName", data.firstName || data.FirstName || "");
|
|
|
|
|
formData.append("LastName", data.lastName || data.LastName || "");
|
|
|
|
|
formData.append("Email", data.email || "");
|
|
|
|
|
formData.append("PhoneNumber", data.phoneNumber || "");
|
|
|
|
|
formData.append("WhatsAppNumber", data.whatsAppNumber || "");
|
|
|
|
|
formData.append("Phone", data.phone || "");
|
|
|
|
|
formData.append("NationalNumber", data.nationalNumber || "");
|
|
|
|
|
formData.append("Password", data.password || "");
|
|
|
|
|
formData.append("Type", String(data.customerType ?? data.Type ?? 0));
|
|
|
|
|
formData.append("Language", "0");
|
2026-03-28 15:15:09 +00:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
if (frontImage) formData.append("FrontIdCarImagePath", frontImage);
|
|
|
|
|
if (backImage) formData.append("RearIdCarImagePath", backImage);
|
2026-03-28 15:15:09 +00:00
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
return multipartAuthFetch("/Customer/Add", formData);
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
export async function loginWithEmail(credential, password) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return authFetch("/Auth/LogInWithEmail", {
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
credential,
|
|
|
|
|
password,
|
|
|
|
|
device: 0,
|
2026-06-16 19:03:15 +03:00
|
|
|
appVersion: "",
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function loginWithPhone(credential, password) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return authFetch("/Auth/LogInWithPhoneNumber", {
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
credential,
|
|
|
|
|
password,
|
|
|
|
|
device: 0,
|
2026-06-16 19:03:15 +03:00
|
|
|
appVersion: "",
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendEmailOTP() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Auth/SendEmailOTP", { method: "POST" });
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendPhoneOTP() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Auth/SendPhoneNumberOTP", { method: "POST" });
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function verifyEmail(code) {
|
2026-03-28 16:31:27 +00:00
|
|
|
const token = AuthService.getToken();
|
2026-06-16 19:03:15 +03:00
|
|
|
return authFetch(
|
|
|
|
|
`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`,
|
|
|
|
|
{},
|
|
|
|
|
token,
|
|
|
|
|
);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function verifyPhone(code) {
|
2026-03-28 16:31:27 +00:00
|
|
|
const token = AuthService.getToken();
|
2026-06-16 19:03:15 +03:00
|
|
|
return authFetch(
|
|
|
|
|
`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`,
|
|
|
|
|
{},
|
|
|
|
|
token,
|
|
|
|
|
);
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isEmail(value) {
|
|
|
|
|
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isPhoneNumber(value) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return /^\+?\d{7,15}$/.test(value.replace(/[\s\-()]/g, ""));
|
Implement login with email/phone + OTP verification flow
Login page:
- Email/phone tabs with auto-detect from input
- Calls LogInWithEmail or LogInWithPhoneNumber API
- On 206 (Partial Content): shows OTP step, sends OTP, then verifies
- On 200: stores JWT in localStorage, decodes user info
- OTP step with resend button and back navigation
- Console logs throughout all auth flows
API client:
- Added authFetch() for raw status code handling (200/206)
- Added loginWithEmail, loginWithPhone, sendEmailOTP, sendPhoneOTP,
verifyEmail, verifyPhone, isEmail, isPhoneNumber
- apiFetch now accepts 206 as non-error
2026-03-26 23:56:18 +00:00
|
|
|
}
|
2026-03-30 17:54:42 +00:00
|
|
|
|
|
|
|
|
export async function getUserFavoriteProperties() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/FavoriteProperty/GetUserFavoriteProperties");
|
2026-03-30 17:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addFavoriteProperty(propId) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch(`/FavoriteProperty/Add?propId=${propId}`, { method: "POST" });
|
2026-03-30 17:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function removeFavoriteProperty(favePropId) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch(`/FavoriteProperty/Remove?favePropId=${favePropId}`, {
|
|
|
|
|
method: "DELETE",
|
|
|
|
|
});
|
2026-03-30 17:54:42 +00:00
|
|
|
}
|
2026-04-15 12:07:39 +03:00
|
|
|
|
|
|
|
|
export async function getUserNotifications() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Notifications/GetUserNotifications");
|
2026-04-15 12:07:39 +03:00
|
|
|
}
|
2026-04-15 12:28:01 +03:00
|
|
|
|
|
|
|
|
export async function confirmDepositPayment(bookingId) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/ConfirmDepositPayment", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: { bookingId },
|
2026-04-15 12:28:01 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
export async function adminConfirmDeposit(
|
|
|
|
|
reservationId,
|
|
|
|
|
adminId,
|
|
|
|
|
comment = null,
|
|
|
|
|
) {
|
|
|
|
|
const token = AuthService.getToken();
|
|
|
|
|
const normalizedComment =
|
|
|
|
|
typeof comment === "string" && comment.trim() ? comment.trim() : null;
|
|
|
|
|
const payload = {
|
|
|
|
|
reservationId,
|
|
|
|
|
adminId,
|
|
|
|
|
comment: normalizedComment,
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-13 20:20:17 +03:00
|
|
|
const res = await fetch(buildApiUrl(API_BASE, "/Reservations/AdminConfirmDeposit/admin-confirm-deposit"), {
|
2026-06-16 19:03:15 +03:00
|
|
|
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 };
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-15 12:28:01 +03:00
|
|
|
export async function updateBookingStatus(bookingId, status) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/UpdateStatus", {
|
|
|
|
|
method: "PUT",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: { bookingId, status },
|
2026-04-15 12:28:01 +03:00
|
|
|
});
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerReservationRequests() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/GetOwnerResevationRequests");
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerReservationsByStatuses(filterStatuses) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/GetAllReservationsByStateForOwner", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: { filterStatuses },
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getUserReservations() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/GetUserResevations");
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function ownerConfirmReservation(id) {
|
|
|
|
|
return apiFetch(`/Reservations/OwnerConfirmReservation/owner-confirm/${id}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 20:20:17 +03:00
|
|
|
export async function getMyTransaction() {
|
|
|
|
|
return apiFetch("/Customer/GetMyTransaction");
|
|
|
|
|
}
|
2026-07-11 05:21:38 -07:00
|
|
|
|
2026-05-25 21:27:39 +03:00
|
|
|
export async function payDeposit(data) {
|
2026-07-11 05:21:38 -07:00
|
|
|
const formData = new FormData();
|
|
|
|
|
|
|
|
|
|
formData.append(
|
|
|
|
|
"ReservationId",
|
|
|
|
|
String(data.reservationId ?? data.ReservationId ?? "")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
formData.append(
|
|
|
|
|
"PaymentTypeId",
|
|
|
|
|
String(data.paymentTypeId ?? data.PaymentTypeId ?? "")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (data.comment) {
|
|
|
|
|
formData.append("Comment", data.comment);
|
|
|
|
|
} else {
|
|
|
|
|
formData.append("Comment", "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.paymentImage) {
|
|
|
|
|
formData.append("paymentImage", data.paymentImage);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reservations/PayDeposit/pay-deposit", {
|
|
|
|
|
method: "POST",
|
2026-07-11 05:21:38 -07:00
|
|
|
body: formData,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerContactInformation(propertyInformationId) {
|
2026-06-06 03:55:53 -07:00
|
|
|
return apiFetch(
|
2026-06-16 19:03:15 +03:00
|
|
|
`/Owner/GetOwnerContactInformation?propertyInformationId=${propertyInformationId}`,
|
2026-06-06 03:55:53 -07:00
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerStatistics() {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Statistics/GetOwnerStatistics");
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function registerRealEstateAgent(formData) {
|
|
|
|
|
const token = AuthService.getToken();
|
2026-06-06 03:55:53 -07:00
|
|
|
|
2026-05-25 21:27:39 +03:00
|
|
|
const res = await fetch(`${API_BASE}/RealEstateAgent/Add`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
headers: {
|
|
|
|
|
...(token && { Authorization: `Bearer ${token}` }),
|
|
|
|
|
},
|
2026-05-25 21:27:39 +03:00
|
|
|
body: formData,
|
|
|
|
|
});
|
2026-06-06 03:55:53 -07:00
|
|
|
|
2026-06-14 18:04:05 +03:00
|
|
|
assertNotBlocked(res);
|
|
|
|
|
|
2026-05-25 21:27:39 +03:00
|
|
|
const text = await res.text();
|
|
|
|
|
let data = null;
|
2026-06-06 03:55:53 -07:00
|
|
|
|
2026-06-05 18:33:51 -07:00
|
|
|
try {
|
|
|
|
|
data = text ? JSON.parse(text) : null;
|
2026-06-16 19:03:15 +03:00
|
|
|
if (data && typeof data === "object" && "data" in data) data = data.data;
|
2026-06-05 18:33:51 -07:00
|
|
|
} catch {
|
|
|
|
|
data = text;
|
|
|
|
|
}
|
2026-06-06 03:55:53 -07:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
status: res.status,
|
|
|
|
|
data,
|
|
|
|
|
ok: res.ok || res.status === 206,
|
2026-06-16 19:03:15 +03:00
|
|
|
message: data?.message || (typeof data === "string" ? data : null),
|
2026-06-06 03:55:53 -07:00
|
|
|
};
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function changePassword(oldPassword, newPassword) {
|
2026-06-06 03:55:53 -07:00
|
|
|
return apiFetch(
|
|
|
|
|
`/User/ChangePassword?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`,
|
|
|
|
|
{
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
|
|
|
|
},
|
2026-06-06 03:55:53 -07:00
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function requestForgetPasswordOtp(email) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch(`/User/ForgetPassword?email=${encodeURIComponent(email)}`, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
});
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function verifyForgetPasswordOtp(email, code, newPassword) {
|
2026-06-06 03:55:53 -07:00
|
|
|
return apiFetch(
|
|
|
|
|
`/User/VerifyForgetPasswordOTP?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code)}&newPassword=${encodeURIComponent(newPassword)}`,
|
|
|
|
|
{
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "POST",
|
|
|
|
|
},
|
2026-06-06 03:55:53 -07:00
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function resetPassword(token) {
|
|
|
|
|
return apiFetch(`/Auth/ResetPassword?token=${encodeURIComponent(token)}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteMyAccount(password) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch(
|
|
|
|
|
`/User/DeleteMyAccount?password=${encodeURIComponent(password)}`,
|
|
|
|
|
{
|
|
|
|
|
method: "DELETE",
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function setFCMToken(token, deviceType = 2) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/User/SetFCMToken", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: { token, deviceType },
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function filterRentProperties(params = {}) {
|
|
|
|
|
const qs = new URLSearchParams();
|
2026-06-06 03:55:53 -07:00
|
|
|
Object.entries(params).forEach(([k, v]) => {
|
2026-06-16 19:03:15 +03:00
|
|
|
if (v != null && v !== "") qs.set(k, v);
|
2026-06-06 03:55:53 -07:00
|
|
|
});
|
2026-05-25 21:27:39 +03:00
|
|
|
const query = qs.toString();
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch(
|
|
|
|
|
`/RentProperties/FilterRentProperties${query ? `?${query}` : ""}`,
|
|
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
2026-06-14 18:04:05 +03:00
|
|
|
export async function sendGeneralReport(subject, reportBody) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return reportFetch("/Reports/SendGeneralReport", {
|
2026-06-14 18:04:05 +03:00
|
|
|
subject,
|
|
|
|
|
body: reportBody,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-25 21:27:39 +03:00
|
|
|
export async function submitReport(subject, body) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Reports/SendGeneralReport", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: { subject, body },
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function submitReservationReport(data) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/ReservationReports", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateReservationReport(id, data) {
|
|
|
|
|
return apiFetch(`/ReservationReports/${id}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function submitSaleReport(data) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/SaleReports", {
|
|
|
|
|
method: "POST",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateSaleReport(id, data) {
|
|
|
|
|
return apiFetch(`/SaleReports/${id}`, {
|
2026-06-16 19:03:15 +03:00
|
|
|
method: "PUT",
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-16 13:59:17 +03:00
|
|
|
export async function addOrUpdateTerms(terms) {
|
2026-06-16 19:03:15 +03:00
|
|
|
return apiFetch("/Terms/AddOrUpdateTerms", {
|
|
|
|
|
method: "POST",
|
2026-06-16 13:59:17 +03:00
|
|
|
body: terms,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
2026-06-24 06:53:18 -07:00
|
|
|
}
|