From bf433cb074da808828f77bb6801dcfd65f0e9a49 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Tue, 18 Jun 2024 12:14:21 +0530 Subject: [PATCH] Improved: endpoints for the services and handled the changes as required(#73) Updated endpoints to use reroute specific endpoints Removed passing token in the headers as we are passing token in the params Displayed stateCode in the store pickup modal and country on the shipping info card Updated routes to handle the token as prop in the route, previously we use to get the same as params --- src/router/index.ts | 11 +++++++---- src/services/OrderService.ts | 15 ++++++++------- src/services/UtilityService.ts | 2 +- src/store/modules/user/actions.ts | 6 ++++-- src/views/AddressModal.vue | 3 ++- src/views/Order.vue | 23 +++++++++++++---------- src/views/PickupLocationModal.vue | 2 +- 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index e6b3c540..749b4ca5 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -4,13 +4,16 @@ import Order from "@/views/Order.vue" const routes: Array = [ { - path: '/', - redirect: "/order", + path: "/order/:token", + name: "Order", + component: Order, + props: true }, { - path: "/order", + path: '/:token', // Added this route as when using redirect we can't define props as true and thus the redirect fails name: "Order", - component: Order + component: Order, + props: true } ] diff --git a/src/services/OrderService.ts b/src/services/OrderService.ts index 2970886d..5a34501d 100644 --- a/src/services/OrderService.ts +++ b/src/services/OrderService.ts @@ -1,18 +1,19 @@ import { api } from '@/adapter'; +import store from '@/store'; -const getOrder = async (token: string): Promise => { +const getOrder = async (payload: any): Promise => { + let baseURL = store.getters['user/getInstanceUrl']; + baseURL = baseURL && baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`; return api({ url: "getRerouteOrder", - method: "POST", - data: { - token - } + method: "post", + data: payload }); } const updateShippingAddress = async (payload: any): Promise => { return api({ - url: "updateShippingAddressRerouteOrder", + url: "updateShippingAddressOfRerouteOrder", method: "post", data: payload }); @@ -36,7 +37,7 @@ const cancelOrderItem = async (payload: any): Promise => { const getProductStoreSetting = async (payload: any): Promise => { return api({ - url: 'getProductStoreSetting', + url: "getProductStoreSettingForRerouteOrder", method: "post", data: payload }); diff --git a/src/services/UtilityService.ts b/src/services/UtilityService.ts index 930cf3b9..30dc14f5 100644 --- a/src/services/UtilityService.ts +++ b/src/services/UtilityService.ts @@ -2,7 +2,7 @@ import { api } from '@/adapter'; const getAssociatedStates = async (payload: any): Promise => { return api({ - url: "getStates", + url: "getStatesForRerouteOrder", method: "post", data: payload, }); diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index 0c59850c..3021eb86 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -114,14 +114,16 @@ const actions: ActionTree = { updateInstanceUrl(payload) }, - async getConfiguration({ commit }, productStoreId) { + async getConfiguration({ commit }, { productStoreId, token }) { try { const resp = await OrderService.getProductStoreSetting({ + token, inputFields: { productStoreId, "settingTypeEnumId": ["CUST_DLVRMTHD_UPDATE", "CUST_DLVRADR_UPDATE", "CUST_PCKUP_UPDATE", "CUST_ALLOW_CNCL", "RF_SHIPPING_METHOD"], "settingTypeEnumId_op": "in" - } + }, + viewSize: 100 }) if (!hasError(resp)) { const permissions = resp.data.docs.filter((permission: any) => permission.settingValue == 'true').map((permission: any) => permission.settingTypeEnumId) diff --git a/src/views/AddressModal.vue b/src/views/AddressModal.vue index 5c4ed8e9..15386b9d 100644 --- a/src/views/AddressModal.vue +++ b/src/views/AddressModal.vue @@ -93,7 +93,7 @@ export default defineComponent({ states: [] as any }; }, - props: ["shipGroup"], + props: ["shipGroup", "token"], async mounted() { await this.getAssociatedStates() if (this.shipGroup.shipmentMethodTypeId != 'STOREPICKUP') this.prepareAddress(); @@ -126,6 +126,7 @@ export default defineComponent({ async getAssociatedStates() { try { const payload = { + "token": this.token, "countryGeoId": this.shipGroup.shipTo.postalAddress.countryGeoId, "viewSize": process.env.VUE_APP_VIEW_SIZE } diff --git a/src/views/Order.vue b/src/views/Order.vue index 3e73f301..1440c0ac 100644 --- a/src/views/Order.vue +++ b/src/views/Order.vue @@ -45,7 +45,7 @@ {{ shipGroup.selectedFacility.facilityName }} {{ shipGroup.selectedFacility.address1 }} - {{ shipGroup.selectedFacility.city }} {{ shipGroup.selectedFacility.stateCode }} {{ shipGroup.selectedFacility.postalCode }} + {{ shipGroup.selectedFacility.city }} {{ shipGroup.selectedFacility.stateCode }} {{ shipGroup.shipTo.postalAddress.country }} {{ shipGroup.selectedFacility.postalCode }} {{ $t("Change Store")}} @@ -148,8 +148,7 @@ export default defineComponent({ name: 'Shipping', value: 'STANDARD' } - ], - token: "" + ] } }, computed: { @@ -157,15 +156,15 @@ export default defineComponent({ deliveryMethod: 'user/getDeliveryMethod', }) }, + props: ["token"], async mounted() { if (Object.keys(this.$route.query).length > 0) { - if(!this.$route.query.oms || !this.$route.query.token) { + if(!this.$route.query.oms || !this.token) { // invalid request return; } - this.token = this.$route.query.token as any initialise({ - token: this.$route.query.token, + token: "", // Not passing token, as in this app we don't want to send the token in the Authorizartion header and instead the token will be passed in the params/body instanceUrl: `${this.$route.query.oms}/api/`, cacheMaxAge: this.maxAge, events: { @@ -174,6 +173,7 @@ export default defineComponent({ } } }) + this.store.dispatch("user/setUserInstanceUrl", `${this.$route.query.oms}/api/`) await this.getOrder(); } }, @@ -201,9 +201,11 @@ export default defineComponent({ } try { - resp = await OrderService.getOrder(this.token); - if (!hasError(resp) && resp.data.order) { - order = resp.data.order; + resp = await OrderService.getOrder({ + token: this.token + }); + if (!hasError(resp) && resp.data.id) { + order = resp.data; const productIds: any = new Set(); order.shipGroup = order.shipGroup.filter((group: any) => { if(group.facilityId === '_NA_') { @@ -217,7 +219,7 @@ export default defineComponent({ } }) if (productIds.length) await this.fetchProducts([...productIds]) - await this.store.dispatch("user/getConfiguration", order.productStoreId); + await this.store.dispatch("user/getConfiguration", { productStoreId: order.productStoreId, token: this.token}); this.order = order; if (productIds.size) await this.fetchProducts([...productIds]) } @@ -335,6 +337,7 @@ export default defineComponent({ backdropDismiss: false, componentProps: { shipGroup, + token: this.token } }) modal.onDidDismiss().then((result) => { diff --git a/src/views/PickupLocationModal.vue b/src/views/PickupLocationModal.vue index 8bcb84fb..e103804d 100644 --- a/src/views/PickupLocationModal.vue +++ b/src/views/PickupLocationModal.vue @@ -18,7 +18,7 @@ {{ shipGroup.shipTo.postalAddress.toName }} {{ shipGroup.shipTo.postalAddress.address1 }} - {{ shipGroup.shipTo.postalAddress.city }} {{ shipGroup.shipTo.postalAddress.country }} {{ shipGroup.shipTo.postalAddress.postalCode }} + {{ shipGroup.shipTo.postalAddress.city }} {{ shipGroup.shipTo.postalAddress.stateCode }} {{ shipGroup.shipTo.postalAddress.country }} {{ shipGroup.shipTo.postalAddress.postalCode }}