Skip to content

Commit

Permalink
Improved: code to handle duplicate shipmentIds while retrying shippin…
Browse files Browse the repository at this point in the history
…g label and voiding label (#801)
  • Loading branch information
amansinghbais committed Dec 11, 2024
1 parent 853882d commit 2d914e4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/components/GenerateTrackingCodeModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ export default defineComponent({
// Getting all the shipmentIds from shipmentPackages for which label is missing
const shipmentIds = order.shipmentPackages
?.filter((shipmentPackage: any) => !shipmentPackage.trackingCode)
.map((shipmentPackage: any) => shipmentPackage.shipmentId);
.reduce((uniqueIds: any[], shipmentPackage: any) => {
if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId);
return uniqueIds;
}, []);
if(!shipmentIds?.length) {
showToast(translate("Failed to generate shipping label"))
Expand Down
6 changes: 4 additions & 2 deletions src/components/OrderLookupLabelActionsPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ export default defineComponent({
const shippingLabelPdfUrls = [] as any;
shipmentPackages.map((shipmentPackage: any) => {
shipmentIds.push(shipmentPackage.shipmentId)
shippingLabelPdfUrls.push(shipmentPackage.labelImageUrl)
if(!shipmentIds.includes(shipmentPackage.shipmentId)) {
shipmentIds.push(shipmentPackage.shipmentId)
shippingLabelPdfUrls.push(shipmentPackage.labelImageUrl)
}
})
await OrderService.printShippingLabel(shipmentIds, shippingLabelPdfUrls)
Expand Down
18 changes: 11 additions & 7 deletions src/components/ShippingLabelActionPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@
popoverController.dismiss()
},
async voidShippingLabel(order: any) {
const shipmentIds = [] as any;
let resp = {} as any;
try {
for (const shipmentPackage of order.shipmentPackages) {
resp = await OrderService.voidShipmentLabel({
"shipmentId": shipmentPackage.shipmentId,
"shipmentRouteSegmentId": shipmentPackage.shipmentRouteSegmentId
})
if(hasError(resp)) {
throw resp.data;
if(!shipmentIds.includes(shipmentPackage.shipmentId)) {
resp = await OrderService.voidShipmentLabel({
"shipmentId": shipmentPackage.shipmentId,
"shipmentRouteSegmentId": shipmentPackage.shipmentRouteSegmentId
})
if(hasError(resp)) {
throw resp.data;
}
shipmentIds.push(shipmentPackage.shipmentId);
}
}
showToast(translate("Shipping label voided successfully."))
Expand Down
5 changes: 4 additions & 1 deletion src/views/Completed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,10 @@ export default defineComponent({
// Getting all the shipmentIds from shipmentPackages for which label is missing
const shipmentIds = order.shipmentPackages
?.filter((shipmentPackage: any) => !shipmentPackage.trackingCode)
.map((shipmentPackage: any) => shipmentPackage.shipmentId);
.reduce((uniqueIds: any[], shipmentPackage: any) => {
if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId);
return uniqueIds;
}, []);
// Don't make any api call when we does not have any shipmentIds for order
if(!shipmentIds?.length) {
Expand Down
10 changes: 8 additions & 2 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,10 @@ export default defineComponent({
// Getting all the shipmentIds from shipmentPackages for which label is missing
const shipmentIds = order.shipmentPackages
?.filter((shipmentPackage: any) => !shipmentPackage.trackingCode)
.map((shipmentPackage: any) => shipmentPackage.shipmentId);
.reduce((uniqueIds: any[], shipmentPackage: any) => {
if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId);
return uniqueIds;
}, []);
if(!shipmentIds?.length) {
showToast(translate("Failed to generate shipping label"))
Expand Down Expand Up @@ -1076,7 +1079,10 @@ export default defineComponent({
return popover.present();
},
async printShippingLabel(order: any) {
const shipmentIds = order.shipmentIds ? order.shipmentIds : order.shipmentPackages?.map((shipmentPackage: any) => shipmentPackage.shipmentId);
const shipmentIds = order.shipmentIds ? order.shipmentIds : order.shipmentPackages?.reduce((uniqueIds: any[], shipmentPackage: any) => {
if(!uniqueIds.includes(shipmentPackage.shipmentId)) uniqueIds.push(shipmentPackage.shipmentId);
return uniqueIds;
}, []);;
const shippingLabelPdfUrls = order.shipmentPackages
?.filter((shipmentPackage: any) => shipmentPackage.labelPdfUrl)
.map((shipmentPackage: any) => shipmentPackage.labelPdfUrl);
Expand Down

0 comments on commit 2d914e4

Please sign in to comment.