updates on the reverse logistics
This commit is contained in:
@@ -668,6 +668,11 @@ func MilerGetConsignment(c *fiber.Ctx) error {
|
||||
"next_hub": nextHubForConsignment(consignment),
|
||||
"can_inward_at_hub": consignment.Status == constants.ConsignmentCreated,
|
||||
"inwardedat": consignment.Inwardedat,
|
||||
// Reverse logistics (additive fields; older app builds ignore them).
|
||||
"returning": consignment.Status == constants.ConsignmentRTOInitiated,
|
||||
"can_return": consignment.Status == constants.ConsignmentRTOInitiated && rtoRiderFlowEnabled(),
|
||||
"return_reason": consignment.Returnreason,
|
||||
"return_to": returnDestination(consignment),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1006,16 +1011,18 @@ func MilerSkipDelivery(c *fiber.Ctx) error {
|
||||
return utils.BadRequest(c, "reason is required")
|
||||
}
|
||||
|
||||
var consignment models.Consignment
|
||||
if err := db.DB.First(&consignment, consignmentID).Error; err != nil {
|
||||
return utils.NotFound(c, "consignment not found")
|
||||
}
|
||||
|
||||
var booking models.PickupBooking
|
||||
if err := db.DB.Where("consignmentid = ? AND assignedmileruserid = ?", consignment.Consignmentid, milerUserID).
|
||||
First(&booking).Error; err != nil {
|
||||
// Ownership through the multi-destination-aware helper. The direct
|
||||
// pickupbookings.consignmentid lookup named only the FIRST order of a
|
||||
// pickup, so a rider could not report a failed attempt on orders 2..N.
|
||||
// Same responses as before.
|
||||
consignmentPtr, code, err := milerConsignmentForRider(milerUserID, consignmentID)
|
||||
if err != nil {
|
||||
if code == constants.ErrConsignmentNotFound {
|
||||
return utils.NotFound(c, "consignment not found")
|
||||
}
|
||||
return utils.Fail(c, fiber.StatusNotFound, constants.ErrConsignmentNotAssigned, "assigned consignment not found")
|
||||
}
|
||||
consignment := *consignmentPtr
|
||||
|
||||
// A failed attempt can be reported once the rider is carrying the parcel —
|
||||
// whether they had already tapped start-delivery (Out_for_Delivery) or not
|
||||
@@ -1063,6 +1070,11 @@ func MilerSkipDelivery(c *fiber.Ctx) error {
|
||||
db.DB.Create(&exception)
|
||||
}
|
||||
|
||||
// Reverse logistics: at RTO_AUTO_AFTER_ATTEMPTS failed attempts (default
|
||||
// 3) the parcel goes back to the sender instead of retrying forever. The
|
||||
// RTO resolves the exception raised just above.
|
||||
autoRTOAfterSkip(&consignment, milerUserID, req.Reason)
|
||||
|
||||
return utils.OK(c, fiber.Map{
|
||||
"consignmentid": consignment.Consignmentid,
|
||||
"attemptcount": consignment.Attemptcount,
|
||||
|
||||
Reference in New Issue
Block a user