rider partner
This commit is contained in:
@@ -34,6 +34,7 @@ type TenantRepository interface {
|
||||
CreateTenantUser(data models.Tenants) (bool, error)
|
||||
GetUserByNo(cno string) models.UserInfo
|
||||
GetTenantByID(tid int, locationid int, userid int) (models.Tenantinfo, error)
|
||||
AssignPartner(tenantID, partnerID int) error
|
||||
GetTenantByKeyword(keyword string) ([]models.TenantSearch, error)
|
||||
}
|
||||
|
||||
@@ -956,3 +957,43 @@ func (r *tenantRepository) UpdateOwnProfile(userID, tenantID int, fields map[str
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AssignPartner sets which delivery partner supplies a merchant's riders.
|
||||
//
|
||||
// A route of its own rather than a field on `updatetenant`, and that is the
|
||||
// whole point. `partnerid` is deliberately absent from `editableTenantFields`:
|
||||
// a merchant who could set it would move themselves under another partner's
|
||||
// billing and pick up their riders. This is the platform's decision, so it gets
|
||||
// the platform's endpoint.
|
||||
//
|
||||
// `partnerid` 0 is meaningful and allowed — it takes the partner away, which a
|
||||
// merchant switching to their own riders needs. So the value is written rather
|
||||
// than skipped when zero, unlike everywhere else in this file.
|
||||
func (r *tenantRepository) AssignPartner(tenantID, partnerID int) error {
|
||||
if tenantID <= 0 {
|
||||
return errors.New("tenantid is required")
|
||||
}
|
||||
|
||||
// A partner that does not exist would silently orphan every rider lookup
|
||||
// the merchant makes afterwards — `getriders?partnerid=` would answer 200
|
||||
// with nothing, which reads as "no riders on duty".
|
||||
if partnerID > 0 {
|
||||
var found int64
|
||||
if err := r.db.Table("partnerinfo").Where("partnerid = ?", partnerID).Count(&found).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if found == 0 {
|
||||
return fmt.Errorf("no delivery partner with partnerid %d", partnerID)
|
||||
}
|
||||
}
|
||||
|
||||
res := r.db.Table("tenants").Where("tenantid = ?", tenantID).
|
||||
Updates(map[string]any{"partnerid": partnerID, "updated": gorm.Expr("NOW()")})
|
||||
if res.Error != nil {
|
||||
return res.Error
|
||||
}
|
||||
if res.RowsAffected == 0 {
|
||||
return fmt.Errorf("no business with tenantid %d", tenantID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user