Fix 9 backend bugs: pricing, zones, geocoding, device tokens, assignment retry

- pricingid null: lookupDoormilePrice now returns matched rule ID; wired to BookingServiceOption.Pricingid
- Zone rename: Interstate→Regional, OtherState→National throughout (code + DB migrated)
- Zone from pincodes: CheckPrice now accepts pickup_pincode+delivery_pincode and auto-resolves zone
- Delivery geocoding: pincodeToLatLon() maps 3-digit prefix to city coords when lat/lon are 0
- Device tokens: device_token field added to PinVerify DTOs; saved on both customer and miler login
- Assignment retry: RejectMilerAssignment now re-triggers AssignCustomerMiler/AssignCRMMiler immediately
- Provider empty B2C: defaults to Doormile when no pricing provider row matches
- City gate 422→400: StatusUnprocessableEntity corrected to StatusBadRequest
- Miler GPS 0,0: WS tracking falls back to MilerProfile DB coords when Redis key is expired

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 11:47:41 +05:30
parent c91c887726
commit 9d409a0d85
9 changed files with 116 additions and 40 deletions

View File

@@ -16,9 +16,9 @@ import (
// Valid enum values
var validZones = map[string]bool{
"Local": true,
"Interstate": true,
"OtherState": true,
"Local": true,
"Regional": true,
"National": true,
}
var validCategories = map[string]bool{
@@ -158,10 +158,12 @@ func buildPriceResponse(zone, servicetype string, weight float64, rules []models
// Body: { zone, service_type, weight, category? }
func CheckPrice(c *fiber.Ctx) error {
type req struct {
Zone string `json:"zone"`
ServiceType string `json:"service_type"`
Weight float64 `json:"weight"`
Category string `json:"category"`
Zone string `json:"zone"`
ServiceType string `json:"service_type"`
Weight float64 `json:"weight"`
Category string `json:"category"`
PickupPincode string `json:"pickup_pincode"`
DeliveryPincode string `json:"delivery_pincode"`
}
body := new(req)
@@ -169,11 +171,16 @@ func CheckPrice(c *fiber.Ctx) error {
return utils.BadRequest(c, "invalid request body")
}
// Auto-resolve zone from pincodes when not explicitly provided.
if body.Zone == "" && body.PickupPincode != "" && body.DeliveryPincode != "" {
body.Zone = resolveZone(body.PickupPincode, body.DeliveryPincode)
}
if !validZones[body.Zone] {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"success": false,
"message": "invalid zone",
"valid_zones": []string{"Local", "Interstate", "OtherState"},
"valid_zones": []string{"Local", "Regional", "National"},
})
}
if !validServiceTypes[body.ServiceType] {
@@ -425,7 +432,7 @@ func WarmPricingCache() {
utils.Info("WarmPricingCache: warming pricing cache from Postgres...")
// Iterate every zone × servicetype combination
zones := []string{"Local", "Interstate", "OtherState"}
zones := []string{"Local", "Regional", "National"}
serviceTypes := []string{"Normal", "Express"}
warmed := 0
@@ -451,8 +458,8 @@ func GetPricingMeta(c *fiber.Ctx) error {
return utils.OK(c, fiber.Map{
"zones": []fiber.Map{
{"value": "Local", "label": "Local / Same City"},
{"value": "Interstate", "label": "Interstate"},
{"value": "OtherState", "label": "Other State"},
{"value": "Regional", "label": "Regional / Same State"},
{"value": "National", "label": "National / Other State"},
},
"categories": []fiber.Map{
{"value": "General", "label": "General Goods"},