create middleware block and update proxy file also make token stored in cookes and up date user page to can show user details also fixed delete user error and delete car error and broken corse inginx image block now we can uplode image to server and but it in my app
This commit is contained in:
@@ -20,36 +20,52 @@ export const userService = {
|
||||
get<ApiListResponse<User>>(`users${buildUsersQuery(page, search)}`, token),
|
||||
|
||||
/** إنشاء مستخدم جديد */
|
||||
create: (data: Omit<UserFormData, "password"> & { password: string }, token: string | null) =>
|
||||
post<UserResponse>("users", buildPayload(data, true), token),
|
||||
create: (
|
||||
data: Omit<UserFormData, "password"> & { password: string },
|
||||
token: string | null,
|
||||
) => post<UserResponse>("users", buildPayload(data, true), token),
|
||||
|
||||
/** تعديل بيانات مستخدم موجود */
|
||||
update: (id: string, data: UserFormData, token: string | null) =>
|
||||
put<UserResponse>(`users/${id}`, buildPayload(data, false), token),
|
||||
|
||||
/** حذف مستخدم */
|
||||
delete: (id: string, token: string | null) =>
|
||||
del<void>(`users/${id}`, token),
|
||||
|
||||
/** جلب قائمة الأدوار لاستخدامها في نموذج المستخدم */
|
||||
delete: (id: string, token: string | null) => del<void>(`users/${id}`, token),
|
||||
//get role
|
||||
getRoles: (token: string | null) =>
|
||||
get<{ data: { data: Role[] } }>("role?limit=100", token),
|
||||
|
||||
/** جلب قائمة الفروع لاستخدامها في نموذج المستخدم */
|
||||
//get Branches for user form
|
||||
getBranches: (token: string | null) =>
|
||||
get<{ data: { data: Branch[] } }>("branches?limit=100", token),
|
||||
//get user by id
|
||||
getById: (id: string, token: string | null) =>
|
||||
get<{
|
||||
data: User & {
|
||||
photo: string | null;
|
||||
refreshToken: string | null;
|
||||
isDeleted: boolean;
|
||||
deletedAt: string | null;
|
||||
updatedAt: string;
|
||||
passwordChangedAt: string | null;
|
||||
role: { name: string; description: string };
|
||||
branch: { name: string };
|
||||
};
|
||||
}>(`users/${id}`, token),
|
||||
};
|
||||
|
||||
/** تحويل بيانات النموذج إلى payload مناسب للـ API */
|
||||
function buildPayload(data: UserFormData, isNew: boolean): Record<string, string> {
|
||||
function buildPayload(
|
||||
data: UserFormData,
|
||||
isNew: boolean,
|
||||
): Record<string, string> {
|
||||
const payload: Record<string, string> = {
|
||||
name: data.name.trim(),
|
||||
phone: data.phone.trim(),
|
||||
roleId: data.roleId,
|
||||
name: data.name.trim(),
|
||||
phone: data.phone.trim(),
|
||||
roleId: data.roleId,
|
||||
branchId: data.branchId,
|
||||
};
|
||||
if (data.email) payload.email = data.email.trim();
|
||||
if (isNew && data.password) payload.password = data.password;
|
||||
else if (!isNew && data.password) payload.password = data.password;
|
||||
if (data.email) payload.email = data.email.trim();
|
||||
if (isNew && data.password) payload.password = data.password;
|
||||
else if (!isNew && data.password) payload.password = data.password;
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user