Skip to content

Instantly share code, notes, and snippets.

@martdn
Last active February 12, 2020 07:16
Show Gist options
  • Save martdn/8bab82a3cf6eed51e174a6259236fab1 to your computer and use it in GitHub Desktop.
Save martdn/8bab82a3cf6eed51e174a6259236fab1 to your computer and use it in GitHub Desktop.
Interactor
export default {
async created() {
try {
this.isLoading = true;
this.userLocation = await this.checkoutRepo.getUserLocation();
const getOrderInteraction = new GetOrderInteractor(this.checkoutRepo, {
apiRouter: this.$router,
route: this.$route
});
this.order = await getOrderInteraction.getOrder();
if (this.isEmptyObject(this.order.customer)) {
this.statusSteps.customer = true;
}
if (this.order.order.delivery_id) {
this.statusSteps.delivery = true;
} else {
await this.getDeliveryInfo();
return;
}
if (this.order.order.paid) {
this.statusSteps.payment = true;
} else {
await this.getPaymentMethods();
}
} catch (error) {
console.error(error);
} finally {
this.updateTotalPrice();
this.isLoading = false;
}
}
}
export class GetOrderInteractor {
constructor(checkoutRepo, { apiRouter, route }) {
this.checkoutRepo = checkoutRepo;
this.apiRouter = apiRouter;
this.route = route;
}
async getOrder() {
if (this.route && this.route.name === 'personal-order-make-id') {
const result = await this.checkoutRepo.getPreOrder({
id: this.route.params.id
});
if (result.order.paid) {
this.apiRouter.push('/');
return;
}
return result;
} else {
const result = await this.checkoutRepo.getBasket();
if (result.order.totalProducts === 0) {
this.apiRouter.push('/');
return;
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment