Skip to content

Commit

Permalink
Merge pull request #77 from ymaheshwari1/#73
Browse files Browse the repository at this point in the history
Improved: the api endpoints for performing operations on order(#73)
  • Loading branch information
ymaheshwari1 authored Jun 18, 2024
2 parents db2bdd4 + 6b62bbb commit 94ebcee
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"Add address": "Add address",
"Are you sure you want to save the changes?": "Are you sure you want to save the changes?",
"Are you sure you want to cancel the order items?": "Are you sure you want to cancel the order items?",
"Cancel": "Cancel",
"Cancel items": "Cancel items",
"Change Store": "Change Store",
"Changes saved": "Changes saved",
"City": "City",
"Confirm": "Confirm",
"Click the backdrop to dismiss.": "Click the backdrop to dismiss.",
Expand All @@ -15,8 +17,10 @@
"Fetching order details.": "Fetching order details.",
"Fetching stores.": "Fetching stores.",
"First name": "First name",
"Failed to cancel the order": "Failed to cancel the order",
"Failed to update the pickup store": "Failed to update the pickup store",
"Failed to update the shipping addess": "Failed to update the shipping addess",
"Fetching address": "Fetching address",
"Last name": "Last name",
"Login": "Login",
"Logout": "Logout",
Expand Down
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
22 changes: 13 additions & 9 deletions src/services/OrderService.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
import { api } from '@/adapter';
import store from '@/store';

const getOrder = async (): 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 / build_and_deploy

'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: "orders",
method: "get",
url: "getRerouteOrder",
method: "post",
data: payload
});
}

const updateShippingAddress = async (payload: any): Promise <any> => {
return api({
url: "service/updateShippingInformationOfShipGroup",
url: "updateShippingAddressOfRerouteOrder",
method: "post",
data: payload,
data: payload
});
}

const updatePickupFacility = async (payload: any): Promise <any> => {
return api({
url: "service/updateOrderItemShipGroup",
url: "updatePickupFacility",
method: "post",
data: payload,
data: payload
});
}

const cancelOrderItem = async (payload: any): Promise <any> => {
return api({
url: 'cancelOrderItem',
url: "cancelRerouteOrderItem",
method: "post",
data: payload
});
}

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
28 changes: 24 additions & 4 deletions src/views/AddressModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ import {
IonSelectOption,
IonTitle,
IonToolbar,
modalController
modalController,
loadingController
} from '@ionic/vue';
import { defineComponent } from 'vue';
import { closeOutline } from 'ionicons/icons';
Expand Down Expand Up @@ -90,13 +91,16 @@ export default defineComponent({
countryGeoId: ""
} as any,
contactMechId: '',
states: [] as any
states: [] as any,
loader: null as any
};
},
props: ["shipGroup"],
props: ["shipGroup", "token"],
async mounted() {
this.presentLoader()
await this.getAssociatedStates()
if (this.shipGroup.shipmentMethodTypeId != 'STOREPICKUP') this.prepareAddress();
this.dismissLoader()
},
methods: {
async updateAddress() {
Expand All @@ -106,7 +110,9 @@ export default defineComponent({
})
if (hasEmptyValues) return showToast(translate("Please fill all the fields"))
const state = this.states.find((state: any) => state.geoId === this.address.stateProvinceGeoId);
this.address.stateCode = state.geoCode;
// In some cases, we get a stateProvinceGeoId that does not exist in data, thus state is not displayed on the UI but originally the field has information thus toast of empty field is not displayed
// thus added a check that if the geoCode is not found in the states fetched from the server, do not stop the address update process and pass the same state that was previously in the address.
this.address.stateCode = state?.geoCode || this.address.stateProvinceGeoId;
this.close(this.address);
},
prepareAddress() {
Expand All @@ -129,6 +135,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 All @@ -145,6 +152,19 @@ export default defineComponent({
close(address?: any) {
modalController.dismiss({ dismissed: true }, address);
},
async presentLoader() {
this.loader = await loadingController
.create({
message: this.$t("Fetching address")
});
await this.loader.present();
},
dismissLoader() {
if (this.loader) {
this.loader.dismiss();
this.loader = null;
}
},
},
setup() {
const router = useRouter();
Expand Down
28 changes: 20 additions & 8 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 @@ -156,14 +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;
}
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 @@ -172,6 +173,7 @@ export default defineComponent({
}
}
})
this.store.dispatch("user/setUserInstanceUrl", `${this.$route.query.oms}/api/`)
await this.getOrder();
}
},
Expand All @@ -194,9 +196,15 @@ export default defineComponent({
await this.presentLoader()
let resp;
let order
if(!this.token) {
return;
}
try {
resp = await OrderService.getOrder();
if (!hasError(resp)) {
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) => {
Expand All @@ -211,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 @@ -260,7 +268,8 @@ export default defineComponent({
"city": shipGroup.updatedAddress.city,
"stateProvinceGeoId": shipGroup.updatedAddress.stateProvinceGeoId,
"postalCode": shipGroup.updatedAddress.postalCode,
"countryGeoId": shipGroup.updatedAddress.countryGeoId
"countryGeoId": shipGroup.updatedAddress.countryGeoId,
"token": this.token
} as any
if (shipGroup.selectedShipmentMethodTypeId === shipGroup.shipmentMethodTypeId) {
Expand Down Expand Up @@ -294,6 +303,7 @@ export default defineComponent({
"shipmentMethod": "STOREPICKUP@_NA_@CARRIER", // TODO Check why CARRIER is needed
"contactMechPurposeTypeId": "SHIPPING_LOCATION",
"facilityId": shipGroup.selectedFacility.facilityId,
"token": this.token
}
try {
Expand Down Expand Up @@ -327,6 +337,7 @@ export default defineComponent({
backdropDismiss: false,
componentProps: {
shipGroup,
token: this.token
}
})
modal.onDidDismiss().then((result) => {
Expand Down Expand Up @@ -386,7 +397,8 @@ export default defineComponent({
const payload = {
"orderId": this.order.id,
"shipGroupSeqId": shipGroup.shipGroupSeqId,
"itemReasonMap": itemReasonMap
"itemReasonMap": itemReasonMap,
"token": this.token
} as any
try {
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 94ebcee

Please sign in to comment.