updates on the milerappcontroller and routes allother thing
This commit is contained in:
@@ -37,7 +37,7 @@ func MilerStartDuty(c *fiber.Ctx) error {
|
||||
var existing models.MilerDutyLog
|
||||
if err := db.DB.Where("userid = ? AND onduty = ? AND logoutat IS NULL AND loginat >= ?", milerUserID, true, midnight).
|
||||
First(&existing).Error; err == nil {
|
||||
return utils.BadRequest(c, "already on duty, end current duty first")
|
||||
return resumeMilerDuty(c, milerUserID, existing, req.Lat, req.Lon)
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
@@ -79,6 +79,37 @@ func MilerStartDuty(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
// resumeMilerDuty answers a start-duty for a rider whose duty from earlier
|
||||
// today is still open — after a reinstall, a crash, or signing in again. It
|
||||
// used to answer 400 "already on duty" and change nothing: the app treated
|
||||
// that as "on duty" and showed the rider online, while their profile stayed
|
||||
// Offline, so the console listed them Offline and auto-assignment skipped
|
||||
// them. Now the open duty is resumed: an Offline rider becomes Available
|
||||
// (a rider mid-delivery or on a break keeps that status) and is made findable
|
||||
// again from where they are.
|
||||
func resumeMilerDuty(c *fiber.Ctx, milerUserID int, duty models.MilerDutyLog, lat, lon float64) error {
|
||||
now := time.Now()
|
||||
db.DB.Model(&models.MilerProfile{}).
|
||||
Where("userid = ? AND availabilitystatus = ?", milerUserID, constants.MilerOffline).
|
||||
Updates(map[string]interface{}{"availabilitystatus": constants.MilerAvailable, "updatedat": now})
|
||||
if lat != 0 && lon != 0 {
|
||||
db.DB.Model(&models.MilerProfile{}).Where("userid = ?", milerUserID).Updates(map[string]interface{}{
|
||||
"currentlatitude": lat,
|
||||
"currentlongitude": lon,
|
||||
"lastlocationupdatedat": now,
|
||||
})
|
||||
indexMilerLocation(milerUserID, lat, lon)
|
||||
go assignment.SweepNear(lat, lon)
|
||||
}
|
||||
db.DB.Model(&models.AppUser{}).Where("userid = ?", milerUserID).Update("onduty", 1)
|
||||
|
||||
return utils.OK(c, fiber.Map{
|
||||
"dutylogid": duty.Dutylogid,
|
||||
"loginat": duty.Loginat,
|
||||
"resumed": true,
|
||||
})
|
||||
}
|
||||
|
||||
func MilerEndDuty(c *fiber.Ctx) error {
|
||||
milerUserID := c.Locals("userid").(int)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user