updates on the sweeper and eligibility things in the order
This commit is contained in:
@@ -2,6 +2,7 @@ package assignment
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
@@ -101,6 +102,9 @@ func tryCustomerAssign(bookingID int) (bool, error) {
|
||||
|
||||
// Steps 4–6 — Commit to DB and publish to NATS.
|
||||
if err := commitCustomerAssignment(&booking, miler, provider, etaMinutes, agentDecisionID); err != nil {
|
||||
if errors.Is(err, errBookingTaken) {
|
||||
return true, nil
|
||||
}
|
||||
return false, fmt.Errorf("commit: %w", err)
|
||||
}
|
||||
|
||||
@@ -192,6 +196,20 @@ func commitCustomerAssignment(
|
||||
|
||||
tx := db.DB.Begin()
|
||||
|
||||
bookingUpdates := map[string]interface{}{
|
||||
"assignedmileruserid": milerUserID,
|
||||
"status": constants.BookingMilerAssigned,
|
||||
"updatedat": time.Now(),
|
||||
}
|
||||
if provider.company != "" {
|
||||
bookingUpdates["providercompany"] = provider.company
|
||||
}
|
||||
// Claim first, only if still unassigned and not cancelled (claimBooking).
|
||||
if err := claimBooking(tx, booking.Bookingid, bookingUpdates); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
ba := models.BookingAssignment{
|
||||
Bookingid: booking.Bookingid,
|
||||
Mileruserid: milerUserID,
|
||||
@@ -204,20 +222,6 @@ func commitCustomerAssignment(
|
||||
return fmt.Errorf("create BookingAssignment: %w", err)
|
||||
}
|
||||
|
||||
bookingUpdates := map[string]interface{}{
|
||||
"assignedmileruserid": milerUserID,
|
||||
"status": constants.BookingMilerAssigned,
|
||||
"updatedat": time.Now(),
|
||||
}
|
||||
if provider.company != "" {
|
||||
bookingUpdates["providercompany"] = provider.company
|
||||
}
|
||||
|
||||
if err := tx.Model(booking).Updates(bookingUpdates).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return fmt.Errorf("update PickupBooking: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Model(&models.MilerProfile{}).
|
||||
Where("userid = ?", milerUserID).
|
||||
Update("availabilitystatus", constants.MilerAssigned).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user