backend requirements onthe xustomer app
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"doormile/db"
|
||||
"doormile/dto"
|
||||
"doormile/internal/assignment"
|
||||
"doormile/internal/cxstage"
|
||||
"doormile/internal/notify"
|
||||
"doormile/models"
|
||||
"doormile/utils"
|
||||
@@ -2770,6 +2771,18 @@ func AdminCancelBooking(c *fiber.Ctx) error {
|
||||
return utils.Internal(c, "failed to cancel booking")
|
||||
}
|
||||
|
||||
// Tell the customer's projection too. Without this the pickup keeps
|
||||
// rendering as active and cancellable in the customer app, because
|
||||
// customerstatus was written as "active" at booking time and nothing here
|
||||
// ever moved it. Best-effort and outside the save above: an ops cancel that
|
||||
// has already committed must not be reported as failed because the
|
||||
// customer-side write did not land. No-op for console-created bookings.
|
||||
if err := cxstage.Cancel(db.DB, booking.Bookingid, "Cancelled by Doormile operations",
|
||||
constants.CxActorOps, opsActorID(c), "POST /admin/bookings/{id}/cancel"); err != nil {
|
||||
utils.Error("AdminCancelBooking: could not update the customer projection",
|
||||
"booking_id", booking.Bookingid, "error", err)
|
||||
}
|
||||
|
||||
if booking.Assignedmileruserid != nil {
|
||||
db.DB.Model(&models.MilerProfile{}).
|
||||
Where("userid = ?", *booking.Assignedmileruserid).
|
||||
@@ -2849,6 +2862,15 @@ func AdminBulkCancelBookings(c *fiber.Ctx) error {
|
||||
continue
|
||||
}
|
||||
|
||||
// Same reason as AdminCancelBooking: without this the pickup keeps
|
||||
// rendering as active and cancellable in the customer app. No-op for
|
||||
// console-created bookings.
|
||||
if err := cxstage.Cancel(db.DB, booking.Bookingid, "Cancelled by Doormile operations",
|
||||
constants.CxActorOps, opsActorID(c), "POST /admin/bookings/bulk-cancel"); err != nil {
|
||||
utils.Error("AdminBulkCancelBookings: could not update the customer projection",
|
||||
"booking_id", booking.Bookingid, "error", err)
|
||||
}
|
||||
|
||||
if booking.Assignedmileruserid != nil {
|
||||
db.DB.Model(&models.MilerProfile{}).
|
||||
Where("userid = ?", *booking.Assignedmileruserid).
|
||||
@@ -3895,3 +3917,13 @@ func InternalReassign(c *fiber.Ctx) error {
|
||||
"booking_id": booking.Bookingid,
|
||||
})
|
||||
}
|
||||
|
||||
// opsActorID returns the console user behind an ops action, for the customer's
|
||||
// audit trail. Nil when the request carries no user id, which is a legitimate
|
||||
// state for an internal caller rather than something to fail on.
|
||||
func opsActorID(c *fiber.Ctx) *int {
|
||||
if uid, ok := c.Locals("userid").(int); ok && uid != 0 {
|
||||
return &uid
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user