Last active
February 12, 2020 07:16
-
-
Save martdn/8bab82a3cf6eed51e174a6259236fab1 to your computer and use it in GitHub Desktop.
Interactor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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