Return the created location from CreateTenantLocation so its locationid is available immediately

The store/branch QR code the app scans is just {tenantid, locationid} JSON, but the
onboarding response previously discarded the DB-assigned locationid, so the frontend
had no way to render a store's QR right after onboarding without a separate lookup.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 11:08:57 +05:30
parent d4cbf92661
commit 7db81c0e68
2 changed files with 14 additions and 8 deletions

View File

@@ -25,7 +25,7 @@ type TenantRepository interface {
GetStaffs(tid int) ([]models.StaffInfo, error)
CreateStaff(user models.User) error
UpdateStaff(user models.User) error
CreateTenantLocation(data models.Tenantlocations) error
CreateTenantLocation(data models.Tenantlocations) (models.Tenantlocations, error)
UpdateTenantLocation(data models.Tenantlocations) error
CheckTenantByNo(cno string) int
CreateTenantUser(data models.Tenants) (bool, error)
@@ -346,7 +346,7 @@ func (r *tenantRepository) UpdateStaff(user models.User) error {
return nil
}
func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) error {
func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) (models.Tenantlocations, error) {
var user models.Tenantuser
tx := r.db.Begin()
@@ -360,10 +360,12 @@ func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) err
data.Status = "Active"
}
// Step 1: Insert into tenantlocations
// Step 1: Insert into tenantlocations. GORM writes the DB-assigned
// locationid back onto data, which callers need to build the store's
// QR code (payload is just {tenantid, locationid}) right after onboarding.
if err := tx.Create(&data).Error; err != nil {
tx.Rollback()
return err
return models.Tenantlocations{}, err
}
// Step 2: Insert into app_users
@@ -389,15 +391,15 @@ func (r *tenantRepository) CreateTenantLocation(data models.Tenantlocations) err
if err := tx.Table("app_users").Create(&user).Error; err != nil {
tx.Rollback()
return err
return models.Tenantlocations{}, err
}
// Commit
if err := tx.Commit().Error; err != nil {
return err
return models.Tenantlocations{}, err
}
return nil
return data, nil
}
func (r *tenantRepository) UpdateTenantLocation(input models.Tenantlocations) error {