Skip to content

Commit 76f32f0

Browse files
committed
Update all users without office when creating first office
1 parent 4613280 commit 76f32f0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

data/office.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ func AddOffice(office models.Office) error {
1313
return err
1414
}
1515

16-
// Prepare statement for inserting data
1716
res, err := tx.Exec("INSERT INTO office (name, is_active, is_global) VALUES (?, ?, ?)", office.Name, office.IsActive, office.IsGlobal)
1817
if err != nil {
1918
tx.Rollback()
@@ -24,6 +23,12 @@ func AddOffice(office models.Office) error {
2423
tx.Rollback()
2524
return err
2625
}
26+
// Add all existing players to this office if there are any not connected to a office
27+
_, err = tx.Exec("UPDATE player SET office_id = ? WHERE office_id IS NULL", officeID)
28+
if err != nil {
29+
tx.Rollback()
30+
return err
31+
}
2732
log.Printf("Created new office (%d) %s", officeID, office.Name)
2833
tx.Commit()
2934
return nil

0 commit comments

Comments
 (0)