feat: expose tenantname on miler verify-pin and profile responses

The miler app resolves a rider's service profile (hyperlocal vs logistics,
which decides whether the Start-delivery button renders) from the tenant NAME
in preference to the raw tenantid. Neither verify-pin nor GET /miler/profile
returned a tenant name — the field the app keys off did not exist. Add
resolveTenantName and include tenantname (+ tenantid) on both responses.

Including it on GET /miler/profile lets the app refresh tenantname at launch
without forcing a re-login after this rollout.

This is the precondition for safely enabling MILER_COLLECTED_STATE_ENABLED:
without tenantname, any tenant whose id the app hasn't mapped falls back to the
logistics profile (no Start-delivery button) and would strand collected
hyperlocal parcels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WRaFH5hMRqmUQvVPQsyjZD
This commit is contained in:
Suriyakumarvijayanayagam
2026-08-26 17:05:06 +05:30
parent 549a35a63a
commit 55bc7f70d1

View File

@@ -68,6 +68,23 @@ func LoginMiler(cfg *config.Config) fiber.Handler {
} }
} }
// resolveTenantName returns the tenant's display name for a tenantid, or ""
// when the id is unset/unknown. The miler app resolves a rider's service
// profile (hyperlocal vs logistics) from this name in preference to the raw
// tenantid, so it must be present on the login and profile responses — a rider
// whose tenant we don't name falls back to id-matching, and any unmapped id
// falls back to logistics (no Start-delivery button). Cheap single-row lookup.
func resolveTenantName(tenantID int) string {
if tenantID == 0 {
return ""
}
var t models.Tenant
if err := db.DB.Select("tenantname").Where("tenantid = ?", tenantID).First(&t).Error; err != nil {
return ""
}
return t.Tenantname
}
func VerifyMilerPin(cfg *config.Config) fiber.Handler { func VerifyMilerPin(cfg *config.Config) fiber.Handler {
return func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error {
req := new(dto.MilerPinVerifyRequest) req := new(dto.MilerPinVerifyRequest)
@@ -123,15 +140,24 @@ func VerifyMilerPin(cfg *config.Config) fiber.Handler {
db.DB.Model(&profile).Update("device_token", req.DeviceToken) db.DB.Model(&profile).Update("device_token", req.DeviceToken)
} }
// tenantname drives the app's service-profile resolution (hyperlocal vs
// logistics), checked ahead of the raw tenantid. Persisted client-side at
// verify-pin, so a rider picks up a changed tenant name on next login.
tenantName := resolveTenantName(user.Tenantid)
return c.JSON(fiber.Map{ return c.JSON(fiber.Map{
"success": true, "success": true,
"token": token, "token": token,
"tenantid": user.Tenantid,
"tenantname": tenantName,
"user": fiber.Map{ "user": fiber.Map{
"userid": user.Userid, "userid": user.Userid,
"authname": user.Authname, "authname": user.Authname,
"email": user.Email, "email": user.Email,
"contactno": user.Contactno, "contactno": user.Contactno,
"profile": profile, "tenantid": user.Tenantid,
"tenantname": tenantName,
"profile": profile,
}, },
}) })
} }
@@ -192,12 +218,16 @@ func GetMilerProfile(c *fiber.Ctx) error {
return utils.NotFound(c, "miler profile not found") return utils.NotFound(c, "miler profile not found")
} }
// tenantname is included here too so the app can refresh it at launch via
// GET /miler/profile without forcing a re-login after the tenantname rollout.
return utils.OK(c, fiber.Map{ return utils.OK(c, fiber.Map{
"userid": user.Userid, "userid": user.Userid,
"authname": user.Authname, "authname": user.Authname,
"email": user.Email, "email": user.Email,
"contactno": user.Contactno, "contactno": user.Contactno,
"profile": profile, "tenantid": user.Tenantid,
"tenantname": resolveTenantName(user.Tenantid),
"profile": profile,
}) })
} }