78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import axios from "@/config/axios";
|
|
import type {
|
|
CreateUserAddressResponse,
|
|
CreateUserAddressType,
|
|
CreateUserResponse,
|
|
CreateUserType,
|
|
GetCustomersResponse,
|
|
GetUserGroupsForUserResponse,
|
|
GetUsersParams,
|
|
ImportUsersResponse,
|
|
SearchUserByPhoneResponse,
|
|
UpdateUserResponse,
|
|
UpdateUserType,
|
|
} from "@/pages/customers/types/Types";
|
|
|
|
export const getUsers = async (params?: GetUsersParams) => {
|
|
const { data } = await axios.get<GetCustomersResponse>(`/admin/users`, {
|
|
params,
|
|
});
|
|
return data;
|
|
};
|
|
|
|
export const searchUserByPhone = async (phone: string) => {
|
|
const { data } = await axios.get<SearchUserByPhoneResponse>(
|
|
"/admin/users/search-by-phone",
|
|
{ params: { phone } },
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const createUser = async (params: CreateUserType) => {
|
|
const { data } = await axios.post<CreateUserResponse>("/admin/users", params);
|
|
return data;
|
|
};
|
|
|
|
export const updateUser = async (userId: string, params: UpdateUserType) => {
|
|
const { data } = await axios.patch<UpdateUserResponse>(
|
|
`/admin/users/${userId}`,
|
|
params,
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const getUserGroups = async (userId: string) => {
|
|
const { data } = await axios.get<GetUserGroupsForUserResponse>(
|
|
`/admin/users/${userId}/groups`,
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const createUserAddress = async (
|
|
userId: string,
|
|
params: CreateUserAddressType,
|
|
) => {
|
|
const { data } = await axios.post<CreateUserAddressResponse>(
|
|
`/admin/users/${userId}/addresses`,
|
|
params,
|
|
);
|
|
return data;
|
|
};
|
|
|
|
export const importUsersFromExcel = async (file: File) => {
|
|
const formData = new FormData();
|
|
formData.append("file", file);
|
|
|
|
const { data } = await axios.post<ImportUsersResponse>(
|
|
`/admin/users/import`,
|
|
formData,
|
|
{
|
|
headers: {
|
|
"Content-Type": "multipart/form-data",
|
|
},
|
|
},
|
|
);
|
|
|
|
return data.data;
|
|
};
|