Skip to content

Commit

Permalink
Improved: added service and handling for the request cancellation bas…
Browse files Browse the repository at this point in the history
…ed on store setting (#92)
  • Loading branch information
amansinghbais committed Nov 29, 2024
1 parent 1a6d36c commit 7c9bfd3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 204 deletions.
11 changes: 10 additions & 1 deletion src/services/OrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,21 @@ const releaseRerouteOrderItem = async (payload: any): Promise<any> => {
});
}

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

export const OrderService = {
getOrder,
getRerouteOrderFacilityChangeHistory,
updateShippingAddress,
updatePickupFacility,
cancelOrderItem,
getProductStoreSetting,
releaseRerouteOrderItem
releaseRerouteOrderItem,
requestCancelRerouteOrderItem
}
174 changes: 0 additions & 174 deletions src/views/AddressModal.vue

This file was deleted.

79 changes: 50 additions & 29 deletions src/views/Order.vue
Original file line number Diff line number Diff line change
Expand Up @@ -502,48 +502,69 @@ export default defineComponent({
},
async cancelShipGroup(shipGroup: any, cancelledItems: any) {
let resp
const itemReasonMap = {} as any
let resp;
const itemReasonMap = {} as any;
if(!cancelledItems.length) {
shipGroup.items.map((item: any) => {
itemReasonMap[`irm_${item.itemSeqId}`] = "OICR_CHANGE_MIND"
itemReasonMap[`icm_${item.itemSeqId}`] = "Canceled by customer using Re-Route"
})
}
try {
if(!this.isCancellationAllowed) {
const itemsToCancel = cancelledItems?.length ? cancelledItems : shipGroup.items
const itemIds = [] as any;
let payload = {
"orderId": this.order.id,
"shipGroupSeqId": shipGroup.shipGroupSeqId,
"token": this.token
} as any
itemsToCancel.map((item: any) => {
itemIds.push(item.itemSeqId)
itemReasonMap[`crm_cancellationReason:${item.itemSeqId}`] = "Customer cancellation from reroute app"
})
try {
if(!cancelledItems.length) {
payload = { ...payload, ...itemReasonMap }
resp = await OrderService.requestCancelRerouteOrderItem({
"orderId": this.order.id,
"token": this.token,
"orderItemSeqId": itemIds,
...itemReasonMap
})
resp = await OrderService.cancelOrderItem(payload);
if(resp.status === 200 && !hasError(resp) && resp.data.orderId == this.order.id) {
if(!hasError(resp)) {
return true;
} else {
throw resp.data;
}
} else {
const responses = await Promise.allSettled(cancelledItems.map(async(item: any) => {
payload[`irm_${item.itemSeqId}`] = "OICR_CHANGE_MIND"
payload[`icm_${item.itemSeqId}`] = "Canceled by customer using Re-Route"
payload["orderItemSeqId"] = item.itemSeqId
let payload = {
"orderId": this.order.id,
"shipGroupSeqId": shipGroup.shipGroupSeqId,
"token": this.token
} as any
if(!cancelledItems.length) {
shipGroup.items.map((item: any) => {
itemReasonMap[`irm_${item.itemSeqId}`] = "OICR_CHANGE_MIND"
itemReasonMap[`icm_${item.itemSeqId}`] = "Canceled by customer using Re-Route"
})
payload = { ...payload, ...itemReasonMap }
resp = await OrderService.cancelOrderItem(payload);
if(!hasError(resp)) {
return true;
} else {
throw resp.data;
}
} else {
const responses = await Promise.allSettled(cancelledItems.map(async(item: any) => {
payload[`irm_${item.itemSeqId}`] = "OICR_CHANGE_MIND"
payload[`icm_${item.itemSeqId}`] = "Canceled by customer using Re-Route"
payload["orderItemSeqId"] = item.itemSeqId
return await OrderService.cancelOrderItem(payload)
}))
return await OrderService.cancelOrderItem(payload)
}))
const hasFailedResponse = responses.some((response: any) => response.status === 'rejected')
return !hasFailedResponse
const hasFailedResponse = responses.some((response: any) => response.status === 'rejected')
return !hasFailedResponse
}
}
} catch (error) {
console.error(error)
} catch(error) {
console.error(error);
}
return false;
return false
},
async cancelOrder(shipGroup: any) {
Expand Down

0 comments on commit 7c9bfd3

Please sign in to comment.