Skip to content

Commit

Permalink
Improved: endpoints for the services and handled the changes as requi…
Browse files Browse the repository at this point in the history
…red(#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
  • Loading branch information
ymaheshwari1 committed Jun 18, 2024
1 parent cd3f227 commit bf433cb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
11 changes: 7 additions & 4 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import Order from "@/views/Order.vue"

const routes: Array<RouteRecordRaw> = [
{
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
}
]

Expand Down
15 changes: 8 additions & 7 deletions src/services/OrderService.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { api } from '@/adapter';
import store from '@/store';

const getOrder = async (token: string): Promise <any> => {
const getOrder = async (payload: any): Promise <any> => {
let baseURL = store.getters['user/getInstanceUrl'];
baseURL = baseURL && baseURL.startsWith('http') ? baseURL : `https://${baseURL}.hotwax.io/api/`;

Check warning on line 6 in src/services/OrderService.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'baseURL' is assigned a value but never used

Check warning on line 6 in src/services/OrderService.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'baseURL' is assigned a value but never used
return api({
url: "getRerouteOrder",
method: "POST",
data: {
token
}
method: "post",
data: payload
});
}

const updateShippingAddress = async (payload: any): Promise <any> => {
return api({
url: "updateShippingAddressRerouteOrder",
url: "updateShippingAddressOfRerouteOrder",
method: "post",
data: payload
});
Expand All @@ -36,7 +37,7 @@ const cancelOrderItem = async (payload: any): Promise <any> => {

const getProductStoreSetting = async (payload: any): Promise<any> => {
return api({
url: 'getProductStoreSetting',
url: "getProductStoreSettingForRerouteOrder",
method: "post",
data: payload
});
Expand Down
2 changes: 1 addition & 1 deletion src/services/UtilityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { api } from '@/adapter';

const getAssociatedStates = async (payload: any): Promise <any> => {
return api({
url: "getStates",
url: "getStatesForRerouteOrder",
method: "post",
data: payload,
});
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ const actions: ActionTree<UserState, RootState> = {
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)
Expand Down
3 changes: 2 additions & 1 deletion src/views/AddressModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
}
Expand Down
23 changes: 13 additions & 10 deletions src/views/Order.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<ion-list>
<ion-label>{{ shipGroup.selectedFacility.facilityName }} </ion-label>
<ion-label color="dark">{{ shipGroup.selectedFacility.address1 }} </ion-label>
<ion-label color="dark">{{ shipGroup.selectedFacility.city }} {{ shipGroup.selectedFacility.stateCode }} {{ shipGroup.selectedFacility.postalCode }}</ion-label>
<ion-label color="dark">{{ shipGroup.selectedFacility.city }} {{ shipGroup.selectedFacility.stateCode }} {{ shipGroup.shipTo.postalAddress.country }} {{ shipGroup.selectedFacility.postalCode }}</ion-label>
</ion-list>
<ion-button :disabled="!hasPermission(Actions.APP_SHPGRP_PCKUP_UPDATE) && shipGroup.shipmentMethodTypeId === 'STOREPICKUP'" slot="end" @click="updatePickupLocation(shipGroup)" color="medium" fill="outline">{{ $t("Change Store")}}</ion-button>
</ion-item>
Expand Down Expand Up @@ -148,24 +148,23 @@ export default defineComponent({
name: 'Shipping',
value: 'STANDARD'
}
],
token: ""
]
}
},
computed: {
...mapGetters({
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: {
Expand All @@ -174,6 +173,7 @@ export default defineComponent({
}
}
})
this.store.dispatch("user/setUserInstanceUrl", `${this.$route.query.oms}/api/`)
await this.getOrder();
}
},
Expand Down Expand Up @@ -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_') {
Expand All @@ -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])
}
Expand Down Expand Up @@ -335,6 +337,7 @@ export default defineComponent({
backdropDismiss: false,
componentProps: {
shipGroup,
token: this.token
}
})
modal.onDidDismiss().then((result) => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/PickupLocationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ion-list>
<ion-label>{{ shipGroup.shipTo.postalAddress.toName }}</ion-label>
<ion-label color="dark">{{ shipGroup.shipTo.postalAddress.address1 }} </ion-label>
<ion-label color="dark">{{ shipGroup.shipTo.postalAddress.city }} {{ shipGroup.shipTo.postalAddress.country }} {{ shipGroup.shipTo.postalAddress.postalCode }}</ion-label>
<ion-label color="dark">{{ shipGroup.shipTo.postalAddress.city }} {{ shipGroup.shipTo.postalAddress.stateCode }} {{ shipGroup.shipTo.postalAddress.country }} {{ shipGroup.shipTo.postalAddress.postalCode }}</ion-label>
</ion-list>
</ion-item>
</ion-card>
Expand Down

0 comments on commit bf433cb

Please sign in to comment.