2026-04-28 12:57:06 -07:00
|
|
|
// import AuthService from '../services/AuthService';
|
|
|
|
|
|
|
|
|
|
// const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api';
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * Generic API fetch — attaches auth token, unwraps { data } envelope
|
|
|
|
|
// */
|
|
|
|
|
// async function apiFetch(endpoint, options = {}) {
|
|
|
|
|
// const token = AuthService.getToken();
|
|
|
|
|
|
|
|
|
|
// const headers = {
|
|
|
|
|
// 'Content-Type': 'application/json',
|
|
|
|
|
// ...(token && { Authorization: `Bearer ${token}` }),
|
|
|
|
|
// ...options.headers,
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// console.log('[API] Request:', options.method || 'GET', `${API_BASE}${endpoint}`);
|
|
|
|
|
|
|
|
|
|
// const res = await fetch(`${API_BASE}${endpoint}`, {
|
|
|
|
|
// ...options,
|
|
|
|
|
// headers,
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// console.log('[API] Response:', res.status, endpoint);
|
|
|
|
|
|
|
|
|
|
// if (!res.ok && res.status !== 206) {
|
|
|
|
|
// const text = await res.text().catch(() => '');
|
|
|
|
|
// console.error('[API] Error:', res.status, text);
|
|
|
|
|
// throw new Error(`API ${res.status}: ${text || res.statusText}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * Auth fetch — returns full { status, data, ok } for status-code handling
|
|
|
|
|
// */
|
|
|
|
|
// async function authFetch(endpoint, body, token = null) {
|
|
|
|
|
// console.log('[Auth] Request:', `${API_BASE}${endpoint}`);
|
|
|
|
|
|
|
|
|
|
// const headers = { 'Content-Type': 'application/json' };
|
|
|
|
|
// if (token) {
|
|
|
|
|
// headers['Authorization'] = `Bearer ${token}`;
|
|
|
|
|
// console.log('[Auth] Sending with Bearer token');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const res = await fetch(`${API_BASE}${endpoint}`, {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// headers,
|
|
|
|
|
// body: JSON.stringify(body),
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// console.log('[Auth] Response status:', res.status, endpoint);
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // Build message from response for toast display
|
|
|
|
|
// const message = (typeof data === 'object' && data?.message) ? data.message : null;
|
|
|
|
|
|
|
|
|
|
// return { status: res.status, data, ok: res.ok || res.status === 206, message };
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Rent Properties ───
|
|
|
|
|
|
|
|
|
|
// export async function getRentProperties() {
|
|
|
|
|
// return apiFetch('/RentProperties/GetRentProperties');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getRentProperty(id) {
|
|
|
|
|
// return apiFetch(`/RentProperties/GetRentPropertyById/${id}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getRentPropertyLocations(params = {}) {
|
|
|
|
|
// const qs = new URLSearchParams();
|
|
|
|
|
// if (params.maxOffset != null) qs.set('maxOffset', params.maxOffset);
|
|
|
|
|
// if (params.minOffset != null) qs.set('minOffset', params.minOffset);
|
|
|
|
|
// const query = qs.toString();
|
|
|
|
|
// return apiFetch(`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ''}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Sale Properties ───
|
|
|
|
|
|
|
|
|
|
// export async function getSaleProperties() {
|
|
|
|
|
// return apiFetch('/SaleProperties/GetSaleProperties');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getSaleProperty(id) {
|
|
|
|
|
// const items = await apiFetch('/SaleProperties/GetSaleProperties');
|
|
|
|
|
// if (!Array.isArray(items)) return items;
|
|
|
|
|
// return items.find(p => p.id == id) || items[0];
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Properties (generic) ───
|
|
|
|
|
|
|
|
|
|
// export async function getProperty(id) {
|
|
|
|
|
// return apiFetch(`/Properties/Get/${id}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Recommendations ───
|
|
|
|
|
|
|
|
|
|
// export async function getRecommendations() {
|
|
|
|
|
// return apiFetch('/Recommendations/GetRecommendations');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getTopRecommendations(count = 10) {
|
|
|
|
|
// return apiFetch(`/Recommendations/GetTopRecommendations?count=${count}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Reservations ───
|
|
|
|
|
|
|
|
|
|
// export async function getAvailableDateRanges(propertyId) {
|
|
|
|
|
// console.log('[API] Fetching available dates for property:', propertyId);
|
|
|
|
|
// return apiFetch(`/Reservations/GetAvailableDates/available/${propertyId}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getReservations() {
|
|
|
|
|
// return apiFetch('/Reservations/GetAllReservations');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getReservation(id) {
|
|
|
|
|
// return apiFetch(`/Reservations/GetReservation?id=${id}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function checkAvailability(propertyId, fromDate = null, toDate = null) {
|
|
|
|
|
// const qs = new URLSearchParams();
|
|
|
|
|
// if (fromDate) qs.set('fromDate', fromDate);
|
|
|
|
|
// if (toDate) qs.set('toDate', toDate);
|
|
|
|
|
// const query = qs.toString();
|
|
|
|
|
// return apiFetch(`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ''}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function bookReservation(propertyId, startDate, endDate) {
|
|
|
|
|
// console.log('[API] Booking reservation:', { propertyId, startDate, endDate });
|
|
|
|
|
// return apiFetch('/Reservations/BookReservation/book', {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// body: JSON.stringify({ propertyId, startDate, endDate }),
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Terms ───
|
|
|
|
|
|
|
|
|
|
// export async function getTerms() {
|
|
|
|
|
// return apiFetch('/Terms/GetTerms');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Profile ───
|
|
|
|
|
|
|
|
|
|
// export async function getCustomerByUserId(userId) {
|
|
|
|
|
// console.log('[API] Fetching customer by user ID:', userId);
|
|
|
|
|
// return apiFetch(`/Customer/GetByUserId/${userId}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getOwnerByUserId(userId) {
|
|
|
|
|
// console.log('[API] Fetching owner by user ID:', userId);
|
|
|
|
|
// return apiFetch(`/Owner/GetByUserId/${userId}`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Properties ───
|
|
|
|
|
|
|
|
|
|
// export async function getMyRentListings() {
|
|
|
|
|
// console.log('[API] Fetching my rent listings');
|
|
|
|
|
// return apiFetch(`/RentProperties/GetMyRentListings`);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function addRentProperty(data) {
|
|
|
|
|
// console.log('[API] Adding rent property:', data.PropertyInformation?.Address);
|
|
|
|
|
// return apiFetch('/RentProperties/AddRentProperty', {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// body: JSON.stringify(data),
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Currencies ───
|
|
|
|
|
|
|
|
|
|
// export async function getCurrencies() {
|
|
|
|
|
// return apiFetch('/Currency/GetAll');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Files ───
|
|
|
|
|
|
|
|
|
|
// export async function uploadPicture(file) {
|
|
|
|
|
// console.log('[API] Uploading picture:', file.name);
|
|
|
|
|
// const formData = new FormData();
|
|
|
|
|
// formData.append('image', file);
|
|
|
|
|
// const token = AuthService.getToken();
|
|
|
|
|
// const res = await fetch(`${API_BASE}/Files/UploadPicture`, {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// headers: {
|
|
|
|
|
// ...(token && { Authorization: `Bearer ${token}` }),
|
|
|
|
|
// },
|
|
|
|
|
// body: formData,
|
|
|
|
|
// });
|
|
|
|
|
// const text = await res.text();
|
|
|
|
|
// console.log('[API] Upload response:', res.status, text?.substring(0, 100));
|
|
|
|
|
// if (!res.ok) throw new Error(`Upload failed: ${res.status} ${text}`);
|
|
|
|
|
// // Response is the relative path string (e.g. /Pictures/abc123.jpg)
|
|
|
|
|
// try {
|
|
|
|
|
// const json = JSON.parse(text);
|
|
|
|
|
// return json?.data || json;
|
|
|
|
|
// } catch {
|
|
|
|
|
// return text;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Auth: Registration ───
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * Register a new owner
|
|
|
|
|
// * @param {Object} data — { name, email, phoneNumber, whatsAppNumber, password, ownerType }
|
|
|
|
|
// * @returns {Promise<{status, data, ok, message}>}
|
|
|
|
|
// */
|
|
|
|
|
// // Multipart form-data fetch for file uploads
|
|
|
|
|
// async function multipartAuthFetch(endpoint, formData) {
|
|
|
|
|
// console.log('[Auth] Multipart request:', `${API_BASE}${endpoint}`);
|
|
|
|
|
|
|
|
|
|
// const res = await fetch(`${API_BASE}${endpoint}`, {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// // Don't set Content-Type — browser sets it with boundary
|
|
|
|
|
// body: formData,
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// console.log('[Auth] Response status:', res.status, endpoint);
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return { status: res.status, data, ok: res.ok || res.status === 206, message: data?.message };
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function addOwner(data, frontImage = null, backImage = null) {
|
|
|
|
|
// console.log('[Auth] Registering owner (multipart):', data.email);
|
|
|
|
|
|
|
|
|
|
// const formData = new FormData();
|
|
|
|
|
// 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.ownerType ?? data.Type ?? 0));
|
|
|
|
|
// formData.append('Language', '0');
|
|
|
|
|
|
|
|
|
|
// if (frontImage) formData.append('FrontIdCarImagePath', frontImage);
|
|
|
|
|
// if (backImage) formData.append('RearIdCarImagePath', backImage);
|
|
|
|
|
|
|
|
|
|
// return multipartAuthFetch('/Owner/Add', formData);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function addCustomer(data, frontImage = null, backImage = null) {
|
|
|
|
|
// console.log('[Auth] Registering customer (multipart):', data.email);
|
|
|
|
|
|
|
|
|
|
// const formData = new FormData();
|
|
|
|
|
// 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');
|
|
|
|
|
|
|
|
|
|
// if (frontImage) formData.append('FrontIdCarImagePath', frontImage);
|
|
|
|
|
// if (backImage) formData.append('RearIdCarImagePath', backImage);
|
|
|
|
|
|
|
|
|
|
// return multipartAuthFetch('/Customer/Add', formData);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Auth: Login ───
|
|
|
|
|
|
|
|
|
|
// export async function loginWithEmail(credential, password) {
|
|
|
|
|
// console.log('[Auth] Login with email:', credential);
|
|
|
|
|
// return authFetch('/Auth/LogInWithEmail', {
|
|
|
|
|
// credential,
|
|
|
|
|
// password,
|
|
|
|
|
// device: 0,
|
|
|
|
|
// appVersion: '',
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function loginWithPhone(credential, password) {
|
|
|
|
|
// console.log('[Auth] Login with phone:', credential);
|
|
|
|
|
// return authFetch('/Auth/LogInWithPhoneNumber', {
|
|
|
|
|
// credential,
|
|
|
|
|
// password,
|
|
|
|
|
// device: 0,
|
|
|
|
|
// appVersion: '',
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Auth: OTP ───
|
|
|
|
|
|
|
|
|
|
// export async function sendEmailOTP() {
|
|
|
|
|
// console.log('[Auth] Sending email OTP...');
|
|
|
|
|
// return apiFetch('/Auth/SendEmailOTP', { method: 'POST' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function sendPhoneOTP() {
|
|
|
|
|
// console.log('[Auth] Sending phone OTP...');
|
|
|
|
|
// return apiFetch('/Auth/SendPhoneNumberOTP', { method: 'POST' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function verifyEmail(code) {
|
|
|
|
|
// console.log('[Auth] Verifying email with code:', code);
|
|
|
|
|
// const token = AuthService.getToken();
|
|
|
|
|
// return authFetch(`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`, {}, token);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function verifyPhone(code) {
|
|
|
|
|
// console.log('[Auth] Verifying phone with code:', code);
|
|
|
|
|
// const token = AuthService.getToken();
|
|
|
|
|
// return authFetch(`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`, {}, token);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Helpers ───
|
|
|
|
|
|
|
|
|
|
// export function isEmail(value) {
|
|
|
|
|
// return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export function isPhoneNumber(value) {
|
|
|
|
|
// return /^\+?\d{7,15}$/.test(value.replace(/[\s\-()]/g, ''));
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Favorites ───
|
|
|
|
|
|
|
|
|
|
// export async function getUserFavoriteProperties() {
|
|
|
|
|
// return apiFetch('/FavoriteProperty/GetUserFavoriteProperties');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function addFavoriteProperty(propId) {
|
|
|
|
|
// return apiFetch(`/FavoriteProperty/Add?propId=${propId}`, { method: 'POST' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function removeFavoriteProperty(favePropId) {
|
|
|
|
|
// return apiFetch(`/FavoriteProperty/Remove?favePropId=${favePropId}`, { method: 'DELETE' });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// export async function getUserNotifications() {
|
|
|
|
|
// return apiFetch('/Notifications/GetUserNotifications');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// // ─── Booking/Reservation Management ───
|
|
|
|
|
|
|
|
|
|
// export async function confirmDepositPayment(bookingId) {
|
|
|
|
|
// return apiFetch('/Reservations/ConfirmDepositPayment', {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// body: JSON.stringify({ 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,
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// 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 }),
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
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
|
|
|
import AuthService from '../services/AuthService';
|
|
|
|
|
|
2026-03-31 22:48:50 +00:00
|
|
|
const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api';
|
2026-03-26 22:20:33 +00:00
|
|
|
|
2026-06-06 03:55:53 -07:00
|
|
|
function isFormData(value) {
|
|
|
|
|
return typeof FormData !== 'undefined' && value instanceof 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
|
|
|
/**
|
|
|
|
|
* Generic API fetch — attaches auth token, unwraps { data } envelope
|
|
|
|
|
*/
|
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);
|
|
|
|
|
|
|
|
|
|
if (hasBody && !bodyIsFormData && !headers['Content-Type'] && !headers['content-type']) {
|
|
|
|
|
headers['Content-Type'] = 'application/json';
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 22:20:33 +00:00
|
|
|
const res = await fetch(`${API_BASE}${endpoint}`, {
|
|
|
|
|
...options,
|
|
|
|
|
headers,
|
2026-06-06 03:55:53 -07:00
|
|
|
body:
|
|
|
|
|
hasBody && !bodyIsFormData && typeof options.body !== 'string'
|
|
|
|
|
? JSON.stringify(options.body)
|
|
|
|
|
: options.body,
|
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
|
|
|
if (!res.ok && res.status !== 206) {
|
2026-03-26 22:20:33 +00:00
|
|
|
const text = await res.text().catch(() => '');
|
|
|
|
|
throw new Error(`API ${res.status}: ${text || res.statusText}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const text = await res.text();
|
2026-03-26 22:46:57 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
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-03-28 16:17:14 +00:00
|
|
|
* Auth fetch — returns full { status, data, ok } for status-code handling
|
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-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) {
|
|
|
|
|
headers['Content-Type'] = 'application/json';
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 16:17:14 +00:00
|
|
|
if (token) {
|
|
|
|
|
headers['Authorization'] = `Bearer ${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
|
|
|
const res = await fetch(`${API_BASE}${endpoint}`, {
|
|
|
|
|
method: 'POST',
|
2026-03-28 16:17:14 +00:00
|
|
|
headers,
|
2026-06-06 03:55:53 -07:00
|
|
|
body: bodyIsFormData ? body : JSON.stringify(body),
|
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;
|
|
|
|
|
if (data && typeof data === 'object' && 'data' in data) {
|
|
|
|
|
data = data.data;
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
data = text;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-06 03:55:53 -07: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
|
|
|
|
|
|
|
|
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
|
|
|
// ─── Rent Properties ───
|
|
|
|
|
|
|
|
|
|
export async function getRentProperties() {
|
2026-03-26 23:27:28 +00: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();
|
|
|
|
|
if (params.maxOffset != null) qs.set('maxOffset', params.maxOffset);
|
|
|
|
|
if (params.minOffset != null) qs.set('minOffset', params.minOffset);
|
|
|
|
|
const query = qs.toString();
|
2026-03-26 22:46:57 +00:00
|
|
|
return apiFetch(`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ''}`);
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Sale Properties ───
|
|
|
|
|
|
|
|
|
|
export async function getSaleProperties() {
|
2026-03-26 23:27:28 +00:00
|
|
|
return apiFetch('/SaleProperties/GetSaleProperties');
|
2026-03-26 22:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getSaleProperty(id) {
|
2026-03-26 23:27:28 +00:00
|
|
|
const items = await apiFetch('/SaleProperties/GetSaleProperties');
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Properties (generic) ───
|
|
|
|
|
|
|
|
|
|
export async function getProperty(id) {
|
|
|
|
|
return apiFetch(`/Properties/Get/${id}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Recommendations ───
|
|
|
|
|
|
|
|
|
|
export async function getRecommendations() {
|
2026-03-26 22:46:57 +00: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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Reservations ───
|
|
|
|
|
|
2026-04-28 12:57:06 -07:00
|
|
|
export async function getAvailableDateRanges(propertyId, fromDate = null, toDate = null) {
|
|
|
|
|
const qs = new URLSearchParams();
|
|
|
|
|
if (fromDate) qs.set('fromDate', fromDate);
|
|
|
|
|
if (toDate) qs.set('toDate', toDate);
|
|
|
|
|
const query = qs.toString();
|
|
|
|
|
|
|
|
|
|
return apiFetch(
|
|
|
|
|
`/Reservations/GetAvailableDates/available/${propertyId}${query ? `?${query}` : ''}`
|
|
|
|
|
);
|
2026-03-29 21:16:00 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-26 22:20:33 +00:00
|
|
|
export async function getReservations() {
|
2026-04-16 22:13:14 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function checkAvailability(propertyId, fromDate = null, toDate = null) {
|
|
|
|
|
const qs = new URLSearchParams();
|
|
|
|
|
if (fromDate) qs.set('fromDate', fromDate);
|
|
|
|
|
if (toDate) qs.set('toDate', toDate);
|
|
|
|
|
const query = qs.toString();
|
2026-03-26 22:46:57 +00: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-03-29 21:23:51 +00:00
|
|
|
return apiFetch('/Reservations/BookReservation/book', {
|
2026-03-26 22:20:33 +00:00
|
|
|
method: 'POST',
|
2026-06-06 03:55:53 -07:00
|
|
|
body: {
|
|
|
|
|
propertyInfoId,
|
|
|
|
|
startDate,
|
|
|
|
|
endDate,
|
|
|
|
|
},
|
2026-03-26 22:20:33 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Terms ───
|
|
|
|
|
|
|
|
|
|
export async function getTerms() {
|
2026-03-26 22:46:57 +00:00
|
|
|
return apiFetch('/Terms/GetTerms');
|
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
|
|
|
// ─── Profile ───
|
|
|
|
|
|
|
|
|
|
export async function getCustomerByUserId(userId) {
|
|
|
|
|
return apiFetch(`/Customer/GetByUserId/${userId}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerByUserId(userId) {
|
|
|
|
|
return apiFetch(`/Owner/GetByUserId/${userId}`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 18:00:44 +00:00
|
|
|
// ─── Properties ───
|
|
|
|
|
|
2026-03-31 18:46:12 +00:00
|
|
|
export async function getMyRentListings() {
|
2026-06-06 03:55:53 -07:00
|
|
|
return apiFetch('/RentProperties/GetMyRentListings');
|
2026-03-29 22:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-28 18:00:44 +00:00
|
|
|
export async function addRentProperty(data) {
|
|
|
|
|
return apiFetch('/RentProperties/AddRentProperty', {
|
|
|
|
|
method: 'POST',
|
2026-06-06 03:55:53 -07:00
|
|
|
body: 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}`, {
|
|
|
|
|
method: 'PUT',
|
2026-06-06 03:55:53 -07:00
|
|
|
body: 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}`, {
|
|
|
|
|
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) {
|
|
|
|
|
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() {
|
|
|
|
|
return apiFetch('/SaleProperties/GetMySaleListings');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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}`, {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
body: { status },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateSalePropertyStatus(id, status) {
|
|
|
|
|
return apiFetch(`/SaleProperties/UpdateStatus/${id}`, {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
body: { status },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 19:40:03 +00:00
|
|
|
// ─── Currencies ───
|
|
|
|
|
|
|
|
|
|
export async function getCurrencies() {
|
|
|
|
|
return apiFetch('/Currency/GetAll');
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 00:57:52 +00:00
|
|
|
// ─── Files ───
|
|
|
|
|
|
|
|
|
|
export async function uploadPicture(file) {
|
|
|
|
|
const formData = new FormData();
|
2026-03-30 01:15:57 +00: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-03-30 00:57:52 +00:00
|
|
|
const res = await fetch(`${API_BASE}/Files/UploadPicture`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
...(token && { Authorization: `Bearer ${token}` }),
|
|
|
|
|
},
|
|
|
|
|
body: formData,
|
|
|
|
|
});
|
2026-04-28 12:57:06 -07:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// ─── Auth: Registration ───
|
|
|
|
|
|
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}`, {
|
|
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
if (data && typeof data === 'object' && 'data' in data) {
|
|
|
|
|
data = data.data;
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
data = text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-05 18:33:51 -07: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-03-28 15:29:06 +00:00
|
|
|
formData.append('FirstName', data.firstName || data.FirstName || '');
|
|
|
|
|
formData.append('LastName', data.lastName || data.LastName || '');
|
2026-06-05 18:33:51 -07:00
|
|
|
formData.append('Email', data.email || data.Email || '');
|
|
|
|
|
|
2026-06-06 03:55:53 -07:00
|
|
|
const phoneValue = data.phone || data.phoneNumber || data.Phone || data.PhoneNumber || '';
|
2026-06-05 18:33:51 -07:00
|
|
|
const whatsappValue =
|
|
|
|
|
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-03-28 15:29:06 +00:00
|
|
|
if (frontImage) formData.append('FrontIdCarImagePath', frontImage);
|
|
|
|
|
if (backImage) formData.append('RearIdCarImagePath', backImage);
|
2026-06-05 18:33:51 -07:00
|
|
|
if (licenseImage) formData.append('LicenseImagePath', licenseImage);
|
2026-03-28 15:15:09 +00:00
|
|
|
|
|
|
|
|
return multipartAuthFetch('/Owner/Add', formData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addCustomer(data, frontImage = null, backImage = null) {
|
|
|
|
|
const formData = new FormData();
|
2026-03-28 15:29:06 +00:00
|
|
|
formData.append('FirstName', data.firstName || data.FirstName || '');
|
|
|
|
|
formData.append('LastName', data.lastName || data.LastName || '');
|
2026-03-28 15:15:09 +00:00
|
|
|
formData.append('Email', data.email || '');
|
|
|
|
|
formData.append('PhoneNumber', data.phoneNumber || '');
|
2026-03-28 15:29:06 +00:00
|
|
|
formData.append('WhatsAppNumber', data.whatsAppNumber || '');
|
2026-03-28 15:51:25 +00:00
|
|
|
formData.append('Phone', data.phone || '');
|
2026-03-28 15:29:06 +00:00
|
|
|
formData.append('NationalNumber', data.nationalNumber || '');
|
2026-03-28 15:15:09 +00:00
|
|
|
formData.append('Password', data.password || '');
|
|
|
|
|
formData.append('Type', String(data.customerType ?? data.Type ?? 0));
|
2026-03-28 15:29:06 +00:00
|
|
|
formData.append('Language', '0');
|
2026-03-28 15:15:09 +00:00
|
|
|
|
2026-03-28 15:29:06 +00:00
|
|
|
if (frontImage) formData.append('FrontIdCarImagePath', frontImage);
|
|
|
|
|
if (backImage) formData.append('RearIdCarImagePath', backImage);
|
2026-03-28 15:15:09 +00: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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Auth: Login ───
|
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) {
|
|
|
|
|
return authFetch('/Auth/LogInWithEmail', {
|
|
|
|
|
credential,
|
|
|
|
|
password,
|
|
|
|
|
device: 0,
|
2026-03-27 00:06:13 +00: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) {
|
|
|
|
|
return authFetch('/Auth/LogInWithPhoneNumber', {
|
|
|
|
|
credential,
|
|
|
|
|
password,
|
|
|
|
|
device: 0,
|
2026-03-27 00:06:13 +00: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
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// ─── Auth: OTP ───
|
|
|
|
|
|
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() {
|
|
|
|
|
return apiFetch('/Auth/SendEmailOTP', { method: 'POST' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendPhoneOTP() {
|
|
|
|
|
return apiFetch('/Auth/SendPhoneNumberOTP', { method: 'POST' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function verifyEmail(code) {
|
2026-03-28 16:31:27 +00:00
|
|
|
const token = AuthService.getToken();
|
2026-03-28 16:17:14 +00: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-03-28 16:17:14 +00: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
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// ─── Helpers ───
|
|
|
|
|
|
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) {
|
|
|
|
|
return /^\+?\d{7,15}$/.test(value.replace(/[\s\-()]/g, ''));
|
|
|
|
|
}
|
2026-03-30 17:54:42 +00:00
|
|
|
|
|
|
|
|
// ─── Favorites ───
|
|
|
|
|
|
|
|
|
|
export async function getUserFavoriteProperties() {
|
|
|
|
|
return apiFetch('/FavoriteProperty/GetUserFavoriteProperties');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addFavoriteProperty(propId) {
|
|
|
|
|
return apiFetch(`/FavoriteProperty/Add?propId=${propId}`, { method: 'POST' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function removeFavoriteProperty(favePropId) {
|
|
|
|
|
return apiFetch(`/FavoriteProperty/Remove?favePropId=${favePropId}`, { method: 'DELETE' });
|
|
|
|
|
}
|
2026-04-15 12:07:39 +03:00
|
|
|
|
|
|
|
|
export async function getUserNotifications() {
|
|
|
|
|
return apiFetch('/Notifications/GetUserNotifications');
|
|
|
|
|
}
|
2026-04-15 12:28:01 +03:00
|
|
|
|
|
|
|
|
// ─── Booking/Reservation Management ───
|
|
|
|
|
|
|
|
|
|
export async function confirmDepositPayment(bookingId) {
|
|
|
|
|
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-04-16 21:15:21 +03:00
|
|
|
export async function adminConfirmDeposit(reservationId, adminId, comment = null) {
|
|
|
|
|
const token = AuthService.getToken();
|
2026-04-16 22:33:19 +03:00
|
|
|
const endpoint = `${API_BASE}/Reservations/AdminConfirmDeposit/admin-confirm-deposit`;
|
2026-04-28 12:57:06 -07:00
|
|
|
|
2026-04-16 22:40:59 +03:00
|
|
|
const normalizedComment =
|
|
|
|
|
typeof comment === 'string' && comment.trim()
|
|
|
|
|
? comment.trim()
|
|
|
|
|
: null;
|
2026-04-28 12:57:06 -07:00
|
|
|
|
2026-04-16 22:40:59 +03:00
|
|
|
const payload = {
|
|
|
|
|
reservationId,
|
|
|
|
|
adminId,
|
|
|
|
|
comment: normalizedComment,
|
|
|
|
|
};
|
2026-04-16 21:15:21 +03:00
|
|
|
|
2026-04-16 22:33:19 +03:00
|
|
|
const res = await fetch(endpoint, {
|
2026-04-16 21:15:21 +03:00
|
|
|
method: 'PUT',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
...(token && { Authorization: `Bearer ${token}` }),
|
|
|
|
|
},
|
2026-04-16 22:33:19 +03:00
|
|
|
body: JSON.stringify(payload),
|
2026-04-16 21:15:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Owner / Reservations ───
|
|
|
|
|
|
|
|
|
|
export async function getOwnerReservationRequests() {
|
|
|
|
|
return apiFetch('/Reservations/GetOwnerResevationRequests');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerReservationsByStatuses(filterStatuses) {
|
|
|
|
|
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() {
|
|
|
|
|
return apiFetch('/Reservations/GetUserResevations');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function ownerConfirmReservation(id) {
|
|
|
|
|
return apiFetch(`/Reservations/OwnerConfirmReservation/owner-confirm/${id}`, {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Payments ───
|
|
|
|
|
|
|
|
|
|
export async function payDeposit(data) {
|
|
|
|
|
return apiFetch('/Reservations/PayDeposit/pay-deposit', {
|
|
|
|
|
method: 'POST',
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Owner Contact & Stats ───
|
|
|
|
|
|
|
|
|
|
export async function getOwnerContactInformation(propertyInformationId) {
|
2026-06-06 03:55:53 -07:00
|
|
|
return apiFetch(
|
|
|
|
|
`/Owner/GetOwnerContactInformation?propertyInformationId=${propertyInformationId}`
|
|
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOwnerStatistics() {
|
|
|
|
|
return apiFetch('/Statistics/GetOwnerStatistics');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Agent Registration ───
|
|
|
|
|
|
|
|
|
|
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`, {
|
|
|
|
|
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-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;
|
|
|
|
|
if (data && typeof data === 'object' && 'data' in data) data = data.data;
|
|
|
|
|
} catch {
|
|
|
|
|
data = text;
|
|
|
|
|
}
|
2026-06-06 03:55:53 -07:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
status: res.status,
|
|
|
|
|
data,
|
|
|
|
|
ok: res.ok || res.status === 206,
|
|
|
|
|
message: data?.message || (typeof data === 'string' ? data : null),
|
|
|
|
|
};
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Change Password ───
|
|
|
|
|
|
|
|
|
|
export async function changePassword(oldPassword, newPassword) {
|
2026-06-06 03:55:53 -07:00
|
|
|
return apiFetch(
|
|
|
|
|
`/User/ChangePassword?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`,
|
|
|
|
|
{
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
}
|
|
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Forget Password (OTP flow) ───
|
|
|
|
|
|
|
|
|
|
export async function requestForgetPasswordOtp(email) {
|
|
|
|
|
return apiFetch(`/User/ForgetPassword?email=${encodeURIComponent(email)}`, { method: 'POST' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)}`,
|
|
|
|
|
{
|
|
|
|
|
method: 'POST',
|
|
|
|
|
}
|
|
|
|
|
);
|
2026-05-25 21:27:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Reset Password (token flow) ───
|
|
|
|
|
|
|
|
|
|
export async function resetPassword(token) {
|
|
|
|
|
return apiFetch(`/Auth/ResetPassword?token=${encodeURIComponent(token)}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Delete Account ───
|
|
|
|
|
|
|
|
|
|
export async function deleteMyAccount(password) {
|
|
|
|
|
return apiFetch(`/User/DeleteMyAccount?password=${encodeURIComponent(password)}`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Set FCM Token ───
|
|
|
|
|
|
|
|
|
|
export async function setFCMToken(token, deviceType = 2) {
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Filter Rent Properties ───
|
|
|
|
|
|
|
|
|
|
export async function filterRentProperties(params = {}) {
|
|
|
|
|
const qs = new URLSearchParams();
|
2026-06-06 03:55:53 -07:00
|
|
|
Object.entries(params).forEach(([k, v]) => {
|
|
|
|
|
if (v != null && v !== '') qs.set(k, v);
|
|
|
|
|
});
|
2026-05-25 21:27:39 +03:00
|
|
|
const query = qs.toString();
|
|
|
|
|
return apiFetch(`/RentProperties/FilterRentProperties${query ? `?${query}` : ''}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Reports ───
|
|
|
|
|
|
|
|
|
|
export async function submitReport(subject, body) {
|
|
|
|
|
return apiFetch('/Reports', {
|
|
|
|
|
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) {
|
|
|
|
|
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}`, {
|
|
|
|
|
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) {
|
|
|
|
|
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}`, {
|
|
|
|
|
method: 'PUT',
|
2026-06-06 03:55:53 -07:00
|
|
|
body: data,
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Terms (Add) ───
|
|
|
|
|
|
|
|
|
|
export async function addTerm(name, description) {
|
|
|
|
|
return apiFetch('/Terms', {
|
|
|
|
|
method: 'POST',
|
2026-06-06 03:55:53 -07:00
|
|
|
body: { name, description },
|
2026-05-25 21:27:39 +03:00
|
|
|
});
|
2026-06-06 03:55:53 -07:00
|
|
|
}
|