diff --git a/CUsersAdminAppDataLocalTempclaudeserver.log b/CUsersAdminAppDataLocalTempclaudeserver.log deleted file mode 100644 index ee11e1a..0000000 --- a/CUsersAdminAppDataLocalTempclaudeserver.log +++ /dev/null @@ -1,37 +0,0 @@ -{"level":"INFO","time":"2026-06-30T15:23:23+05:30","caller":"utils/logger.go:24","msg":"Starting Doormile Backend..."} -{"level":"INFO","time":"2026-06-30T15:23:23+05:30","caller":"utils/logger.go:24","msg":"Connecting to database","attempt":1,"host":"31.97.228.132","port":"5433"} -{"level":"INFO","time":"2026-06-30T15:23:24+05:30","caller":"utils/logger.go:24","msg":"✅ Database connected successfully"} -redis: 2026/06/30 15:23:24 redis.go:478: auto mode fallback: maintnotifications disabled due to handshake error: ERR unknown subcommand 'maint_notifications'. Try CLIENT HELP. -{"level":"INFO","time":"2026-06-30T15:23:24+05:30","caller":"utils/logger.go:24","msg":"✅ Redis connected successfully","addr":"31.97.228.132:6379"} -{"level":"INFO","time":"2026-06-30T15:23:24+05:30","caller":"utils/logger.go:24","msg":"✅ NATS JetStream connected successfully","url":"nats://66.116.226.161:4223"} -{"level":"WARN","time":"2026-06-30T15:23:24+05:30","caller":"utils/logger.go:36","msg":"FCM: FIREBASE_SERVICE_ACCOUNT_PATH not set — push notifications disabled"} -{"level":"INFO","time":"2026-06-30T15:23:24+05:30","caller":"utils/logger.go:24","msg":"Starting database auto-migrations for 21 logistics tables..."} -{"level":"INFO","time":"2026-06-30T15:23:45+05:30","caller":"utils/logger.go:24","msg":"✅ Database migration completed successfully!"} -{"level":"INFO","time":"2026-06-30T15:23:45+05:30","caller":"utils/logger.go:24","msg":"✅ context_embedding vector column ready"} -{"level":"INFO","time":"2026-06-30T15:23:45+05:30","caller":"utils/logger.go:24","msg":"✅ ivfflat index on context_embedding ready"} -{"level":"INFO","time":"2026-06-30T15:23:45+05:30","caller":"utils/logger.go:24","msg":"WarmPricingCache: warming pricing cache from Postgres..."} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"Pricing cache warmed","zone":"Local","servicetype":"Normal","count":10} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"Pricing cache warmed","zone":"Local","servicetype":"Express","count":9} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"Pricing cache warmed","zone":"Regional","servicetype":"Normal","count":9} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"Pricing cache warmed","zone":"Regional","servicetype":"Express","count":9} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"Pricing cache warmed","zone":"National","servicetype":"Normal","count":9} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"Pricing cache warmed","zone":"National","servicetype":"Express","count":9} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"WarmPricingCache: done","slabs_warmed":6} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"Server starting","port":"8081"} - - ┌───────────────────────────────────────────────────┐ - │ Doormile Logistics Service API v1 │ - │ Fiber v2.52.10 │ - │ http://127.0.0.1:8081 │ - │ (bound on host 0.0.0.0 and port 8081) │ - │ │ - │ Handlers ........... 206 Processes ........... 1 │ - │ Prefork ....... Disabled PID .............. 9448 │ - └───────────────────────────────────────────────────┘ - -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"BookingWorker: subscribed","subject":"api.v1.bookings.create","consumer":"bookings_create"} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"BookingWorker: subscribed","subject":"api.v1.bookings.update","consumer":"bookings_update"} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"BookingWorker: subscribed","subject":"api.v1.bookings.cancel","consumer":"bookings_cancel"} -{"level":"INFO","time":"2026-06-30T15:23:46+05:30","caller":"utils/logger.go:24","msg":"BookingWorker: running, waiting for messages..."} -{"level":"INFO","time":"2026-06-30T15:26:06+05:30","caller":"utils/logger.go:24","msg":"API request success","method":"GET","path":"/api/v1/health","status":200,"latency":0} -exit status 0xffffffff diff --git a/controllers/milerController.go b/controllers/milerController.go index e3358c0..e1cf47b 100644 --- a/controllers/milerController.go +++ b/controllers/milerController.go @@ -283,7 +283,9 @@ func GetMilerAssignments(c *fiber.Ctx) error { milerUserID := c.Locals("userid").(int) var assignments []models.BookingAssignment - if err := db.DB.Where("mileruserid = ?", milerUserID).Order("assignedat DESC").Find(&assignments).Error; err != nil { + if err := db.DB.Where("mileruserid = ? AND assignmentstatus IN ?", milerUserID, + []string{constants.AssignmentAssigned, constants.AssignmentAccepted}). + Order("assignedat DESC").Find(&assignments).Error; err != nil { return utils.Internal(c, "failed to fetch assignments") } @@ -326,6 +328,11 @@ func AcceptMilerAssignment(c *fiber.Ctx) error { return utils.NotFound(c, "assignment not found") } + if assignment.Assignmentstatus != constants.AssignmentAssigned { + tx.Rollback() + return utils.BadRequest(c, fmt.Sprintf("assignment is not pending acceptance (current status: %s)", assignment.Assignmentstatus)) + } + now := time.Now() assignment.Assignmentstatus = constants.AssignmentAccepted assignment.Acceptedat = &now @@ -367,6 +374,16 @@ func RejectMilerAssignment(c *fiber.Ctx) error { return utils.BadRequest(c, "invalid assignment ID") } + var req struct { + Reason string `json:"reason"` + } + if err := c.BodyParser(&req); err != nil { + return utils.BadRequest(c, "invalid request body") + } + if req.Reason == "" { + req.Reason = "Rejected by rider" + } + tx := db.DB.Begin() var ba models.BookingAssignment @@ -376,7 +393,7 @@ func RejectMilerAssignment(c *fiber.Ctx) error { } ba.Assignmentstatus = constants.AssignmentRejected - ba.Remarks = c.Query("reason", "Rejected by rider") + ba.Remarks = req.Reason tx.Save(&ba) var booking models.PickupBooking @@ -581,9 +598,23 @@ func BookingPickupComplete(c *fiber.Ctx) error { trackingNo := generateTrackingNo() var defaultHubID *int - var hub models.Hub - if tx.First(&hub).Error == nil { - defaultHubID = &hub.Hubid + if profile.Hubid != nil { + defaultHubID = profile.Hubid + } else { + utils.Warn("BookingPickupComplete: miler has no assigned hub, falling back to first hub row", "miler_user_id", milerUserID, "booking_id", bookingID) + var hub models.Hub + if tx.First(&hub).Error == nil { + defaultHubID = &hub.Hubid + } + } + + // Hyperlocal shortcut: pickup and delivery in the same postal area mean + // no hub-to-hub tripsheet leg is needed, so the same miler goes straight + // to final-mile delivery instead of parking the consignment at the hub. + consignmentStatus := constants.ConsignmentInwardedAtHub + if len(booking.Pickuppincode) >= 3 && len(booking.Deliverypincode) >= 3 && + booking.Pickuppincode[:3] == booking.Deliverypincode[:3] { + consignmentStatus = constants.ConsignmentOutForDelivery } consignment := models.Consignment{ @@ -602,7 +633,7 @@ func BookingPickupComplete(c *fiber.Ctx) error { Volumetricweight: totalChargeable - totalDead, Chargeableweight: totalChargeable, Paymentmode: "Prepaid", - Status: constants.ConsignmentInwardedAtHub, + Status: consignmentStatus, Estimateddeliveryat: nil, Createdby: milerUserID, Originhubid: defaultHubID, @@ -632,7 +663,7 @@ func BookingPickupComplete(c *fiber.Ctx) error { Consignmentid: consignment.Consignmentid, Hubid: defaultHubID, Userid: &milerUserID, - Eventstatus: constants.ConsignmentInwardedAtHub, + Eventstatus: consignmentStatus, Remarks: "Package collected by miler and converted to consignment", } tx.Create(&history) diff --git a/main.go b/main.go index 252c9b5..92c0b6c 100644 --- a/main.go +++ b/main.go @@ -50,7 +50,7 @@ func main() { // CORS policy app.Use(cors.New(cors.Config{ AllowHeaders: "Origin,Content-Type,Accept,Authorization", - AllowOrigins: "http://localhost:5173,http://localhost:5174,http://localhost:3000,http://localhost:3001,http://localhost:3002,http://localhost:8080,http://localhost:8081,https://doormile.com,https://www.doormile.com,https://admin.doormile.com,https://api.doormile.com,https://crm.doormile.com,https://console.doormile.com", + AllowOrigins: "http://localhost:5173,http://localhost:5174,http://localhost:3000,http://localhost:3001,http://localhost:3002,http://localhost:8080,http://localhost:8081,https://doormile.com,https://www.doormile.com,https://admin.doormile.com,https://api.doormile.com,https://crm.doormile.com,https://console.doormile.com,https://app.doormile.com", AllowCredentials: true, AllowMethods: "GET,POST,PUT,DELETE,PATCH,OPTIONS", }))