create driver page and client page also create oll driver , client layer

This commit is contained in:
m7amedez5511
2026-06-14 16:25:56 +03:00
parent 68bfce4345
commit bcc4baf28a
35 changed files with 5551 additions and 816 deletions

View File

@@ -0,0 +1,50 @@
// خدمة عناوين العملاء — كل نداءات الـ API الخاصة بالعناوين تكون هنا فقط
// Mirrors user.service.ts pattern: explicit token param, buildPayload helper.
import { get, post, put, patch, del } from "./api";
import type {
ApiResponse,
ClientAddress,
ClientAddressFormData,
} from "../types/client";
const base = (clientId: string) => `client/${clientId}/addresses`;
export const clientAddressService = {
/** جلب جميع عناوين عميل معين */
getAll: (clientId: string, token: string | null) =>
get<ApiResponse<ClientAddress[]>>(base(clientId), token),
/** جلب عنوان واحد بالـ ID */
getById: (clientId: string, addressId: string, token: string | null) =>
get<ApiResponse<ClientAddress>>(`${base(clientId)}/${addressId}`, token),
/** إضافة عنوان جديد لعميل */
create: (clientId: string, data: ClientAddressFormData, token: string | null) =>
post<ApiResponse<ClientAddress>>(base(clientId), buildPayload(clientId, data), token),
/** تعديل عنوان موجود */
update: (clientId: string, addressId: string, data: ClientAddressFormData, token: string | null) =>
put<ApiResponse<ClientAddress>>(`${base(clientId)}/${addressId}`, buildPayload(clientId, data), token),
/** حذف عنوان */
delete: (clientId: string, addressId: string, token: string | null) =>
del<void>(`${base(clientId)}/${addressId}`, token),
/** تعيين عنوان كعنوان رئيسي — الباكند يُلغي الاختيار عن الباقين */
setPrimary: (clientId: string, addressId: string, token: string | null) =>
patch<ApiResponse<ClientAddress>>(`${base(clientId)}/${addressId}/primary`, {}, token),
};
/** تحويل بيانات النموذج إلى payload */
function buildPayload(clientId: string, data: ClientAddressFormData): Record<string, unknown> {
return {
clientId,
label: data.label.trim(),
street: data.street.trim(),
city: data.city.trim(),
state: data.state.trim(),
postalCode: data.postalCode.trim(),
country: data.country.trim(),
isPrimary: data.isPrimary,
};
}