24 lines
655 B
JavaScript
24 lines
655 B
JavaScript
export default function useCustomer({ activeCart, getCarts }) {
|
|
const { $getdata, $patchapi } = useNuxtApp();
|
|
|
|
const addresses = ref([]);
|
|
async function getAddresses() {
|
|
addresses.value = await $getdata("Customer_Address", {
|
|
filter: { customer: activeCart.value.customer },
|
|
});
|
|
}
|
|
|
|
const isChangingCus = ref(false);
|
|
async function changeCustomer(cusId) {
|
|
isChangingCus.value = true;
|
|
const updatedCart = await $patchapi("Cart", {
|
|
id: activeCart.value.id,
|
|
customer: cusId,
|
|
});
|
|
await getCarts();
|
|
isChangingCus.value = false;
|
|
}
|
|
|
|
return { addresses, getAddresses, isChangingCus, changeCustomer };
|
|
}
|