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:
@@ -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 {
|
||||
|
||||
@@ -107,7 +107,7 @@ func (s *tenantService) UpdateStaff(user models.User) error {
|
||||
}
|
||||
|
||||
func (s *tenantService) CreateTenantLocation(data models.Tenantlocations) map[string]interface{} {
|
||||
err := s.repo.CreateTenantLocation(data)
|
||||
created, err := s.repo.CreateTenantLocation(data)
|
||||
if err != nil {
|
||||
return map[string]interface{}{
|
||||
"code": http.StatusConflict,
|
||||
@@ -116,10 +116,14 @@ func (s *tenantService) CreateTenantLocation(data models.Tenantlocations) map[st
|
||||
}
|
||||
}
|
||||
|
||||
// "details" carries back the DB-assigned locationid so the frontend can
|
||||
// build the store's QR code (tenantid+locationid) immediately after
|
||||
// onboarding, instead of having to look the new location up separately.
|
||||
return map[string]interface{}{
|
||||
"code": http.StatusCreated,
|
||||
"message": "Tenant Location Successfully Created",
|
||||
"status": true,
|
||||
"details": created,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user