updates on the admincontroller and the milercontroller and changes in the creaet single order calculations as well
This commit is contained in:
@@ -44,7 +44,7 @@ func LoginMiler(cfg *config.Config) fiber.Handler {
|
||||
}
|
||||
|
||||
var user models.AppUser
|
||||
if err := db.DB.Where("contactno = ? AND configid = ?", req.Phone, configID).First(&user).Error; err != nil {
|
||||
if err := milerLoginLookup(req.Phone, configID).First(&user).Error; err != nil {
|
||||
return utils.NotFound(c, "no miler account found for this phone number")
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func LoginMiler(cfg *config.Config) fiber.Handler {
|
||||
}
|
||||
|
||||
if user.Status != "Active" {
|
||||
return utils.Forbidden(c, "miler account is not active")
|
||||
return utils.Forbidden(c, milerNotActiveMessage(user.Status))
|
||||
}
|
||||
|
||||
// pin_set tells the app which screen to show next: true → enter-PIN
|
||||
@@ -102,7 +102,7 @@ func VerifyMilerPin(cfg *config.Config) fiber.Handler {
|
||||
}
|
||||
|
||||
var user models.AppUser
|
||||
if err := db.DB.Where("contactno = ? AND configid = ?", req.Phone, configID).First(&user).Error; err != nil {
|
||||
if err := milerLoginLookup(req.Phone, configID).First(&user).Error; err != nil {
|
||||
return utils.NotFound(c, "no miler account found for this phone number")
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func VerifyMilerPin(cfg *config.Config) fiber.Handler {
|
||||
}
|
||||
|
||||
if user.Status != "Active" {
|
||||
return utils.Forbidden(c, "miler account is not active")
|
||||
return utils.Forbidden(c, milerNotActiveMessage(user.Status))
|
||||
}
|
||||
|
||||
if !utils.CheckPasswordHash(req.Pin, user.Password) {
|
||||
@@ -192,7 +192,7 @@ func ResetMilerPin(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
var user models.AppUser
|
||||
if err := db.DB.Where("contactno = ? AND configid = ?", req.Phone, configID).First(&user).Error; err != nil {
|
||||
if err := milerLoginLookup(req.Phone, configID).First(&user).Error; err != nil {
|
||||
return utils.NotFound(c, "no miler account found for this phone number")
|
||||
}
|
||||
|
||||
@@ -238,14 +238,14 @@ func SetMilerPin(cfg *config.Config) fiber.Handler {
|
||||
}
|
||||
|
||||
var user models.AppUser
|
||||
if err := db.DB.Where("contactno = ? AND configid = ?", req.Phone, configID).First(&user).Error; err != nil {
|
||||
if err := milerLoginLookup(req.Phone, configID).First(&user).Error; err != nil {
|
||||
return utils.NotFound(c, "no miler account found for this phone number")
|
||||
}
|
||||
if user.Roleid != 5 {
|
||||
return utils.Forbidden(c, "this endpoint is restricted to miler accounts")
|
||||
}
|
||||
if user.Status != "Active" {
|
||||
return utils.Forbidden(c, "miler account is not active")
|
||||
return utils.Forbidden(c, milerNotActiveMessage(user.Status))
|
||||
}
|
||||
if user.Password != "" {
|
||||
return utils.Conflict(c, "a PIN is already set for this account; use verify-pin to log in")
|
||||
@@ -428,6 +428,14 @@ func UpdateMilerAvailability(c *fiber.Ctx) error {
|
||||
if status == "" {
|
||||
return utils.BadRequest(c, "status is required")
|
||||
}
|
||||
// Blocking is an ops decision: a rider can neither lift it (Available
|
||||
// from a session that was open when the block happened) nor set it.
|
||||
if strings.EqualFold(status, constants.MilerBlocked) {
|
||||
return utils.BadRequest(c, "riders cannot set this status")
|
||||
}
|
||||
if milerIsBlocked(milerUserID) {
|
||||
return utils.Forbidden(c, milerNotActiveMessage(constants.MilerBlocked))
|
||||
}
|
||||
|
||||
var profile models.MilerProfile
|
||||
if err := db.DB.Where("userid = ?", milerUserID).First(&profile).Error; err != nil {
|
||||
@@ -702,7 +710,7 @@ func RejectMilerAssignment(c *fiber.Ctx) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := tx.Model(&models.MilerProfile{}).Where("userid = ?", milerUserID).
|
||||
if err := tx.Model(&models.MilerProfile{}).Where("userid = ? AND availabilitystatus <> ?", milerUserID, constants.MilerBlocked).
|
||||
Update("availabilitystatus", constants.MilerAvailable).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return utils.Internal(c, "failed to update miler availability")
|
||||
@@ -782,7 +790,7 @@ func MilerCancelAssignment(c *fiber.Ctx) error {
|
||||
return utils.Internal(c, "failed to release booking")
|
||||
}
|
||||
|
||||
if err := tx.Model(&models.MilerProfile{}).Where("userid = ?", milerUserID).
|
||||
if err := tx.Model(&models.MilerProfile{}).Where("userid = ? AND availabilitystatus <> ?", milerUserID, constants.MilerBlocked).
|
||||
Update("availabilitystatus", constants.MilerAvailable).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return utils.Internal(c, "failed to update miler availability")
|
||||
@@ -1526,7 +1534,7 @@ func BookingPickupComplete(c *fiber.Ctx) error {
|
||||
return utils.Internal(c, "failed to close assignment")
|
||||
}
|
||||
}
|
||||
if err := tx.Model(&models.MilerProfile{}).Where("userid = ?", milerUserID).
|
||||
if err := tx.Model(&models.MilerProfile{}).Where("userid = ? AND availabilitystatus <> ?", milerUserID, constants.MilerBlocked).
|
||||
Update("availabilitystatus", postPickupAvailability).Error; err != nil {
|
||||
tx.Rollback()
|
||||
return utils.Internal(c, "failed to update miler availability")
|
||||
|
||||
Reference in New Issue
Block a user