From 7c9bfd3fcc266d970a8d53a6f08ff23f474a369a Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Fri, 29 Nov 2024 16:50:17 +0530 Subject: [PATCH] Improved: added service and handling for the request cancellation based on store setting (#92) --- src/services/OrderService.ts | 11 ++- src/views/AddressModal.vue | 174 ----------------------------------- src/views/Order.vue | 79 ++++++++++------ 3 files changed, 60 insertions(+), 204 deletions(-) delete mode 100644 src/views/AddressModal.vue diff --git a/src/services/OrderService.ts b/src/services/OrderService.ts index 0dde0eae..c389d1f0 100644 --- a/src/services/OrderService.ts +++ b/src/services/OrderService.ts @@ -56,6 +56,14 @@ const releaseRerouteOrderItem = async (payload: any): Promise => { }); } +const requestCancelRerouteOrderItem = async (payload: any): Promise => { + return api({ + url: "requestCancelRerouteOrderItem", + method: "post", + data: payload + }); +} + export const OrderService = { getOrder, getRerouteOrderFacilityChangeHistory, @@ -63,5 +71,6 @@ export const OrderService = { updatePickupFacility, cancelOrderItem, getProductStoreSetting, - releaseRerouteOrderItem + releaseRerouteOrderItem, + requestCancelRerouteOrderItem } \ No newline at end of file diff --git a/src/views/AddressModal.vue b/src/views/AddressModal.vue deleted file mode 100644 index 899cb0db..00000000 --- a/src/views/AddressModal.vue +++ /dev/null @@ -1,174 +0,0 @@ - - - \ No newline at end of file diff --git a/src/views/Order.vue b/src/views/Order.vue index 5bd6c3d5..0e8f0cd0 100644 --- a/src/views/Order.vue +++ b/src/views/Order.vue @@ -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) {