added create or update address
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// imports
|
||||
|
||||
import { useMutation } from "@tanstack/vue-query";
|
||||
import { API_ENDPOINTS } from "~/constants";
|
||||
|
||||
// types
|
||||
|
||||
export type CreateOrUpdateAddressRequest = Address;
|
||||
|
||||
const useCreateOrUpdateAddress = (update: ComputedRef<Boolean>) => {
|
||||
// state
|
||||
|
||||
const { $axios: axios } = useNuxtApp();
|
||||
|
||||
// method
|
||||
|
||||
const handleCreateOrUpdateAddress = async (
|
||||
addressData: CreateOrUpdateAddressRequest
|
||||
) => {
|
||||
const { data } = await axios[update.value ? "put" : "post"](
|
||||
update.value
|
||||
? `${API_ENDPOINTS.account.address.update}/${addressData.id}`
|
||||
: API_ENDPOINTS.account.address.create,
|
||||
{
|
||||
...addressData,
|
||||
for_me: addressData.for_me == "بله" ? true : false,
|
||||
}
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (addressData: CreateOrUpdateAddressRequest) =>
|
||||
handleCreateOrUpdateAddress(addressData),
|
||||
});
|
||||
};
|
||||
|
||||
export default useCreateOrUpdateAddress;
|
||||
Reference in New Issue
Block a user