save data when applying vouchers

pull/13/merge
Up 2024-05-12 08:30:46 +02:00
parent c06b1496a3
commit a44a6c382f
No known key found for this signature in database
GPG Key ID: 3B75CD7439FEB388
1 changed files with 12 additions and 0 deletions

View File

@ -38,13 +38,25 @@ func Get(uuid []byte, datatype, slot int) (any, error) {
return nil, err return nil, err
} }
// TODO this should be a transaction
compensations, err := db.FetchAndClaimAccountCompensations(uuid) compensations, err := db.FetchAndClaimAccountCompensations(uuid)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to fetch compensations: %s", err) return nil, fmt.Errorf("failed to fetch compensations: %s", err)
} }
needsUpdate := false
for compensationType, amount := range compensations { for compensationType, amount := range compensations {
system.VoucherCounts[strconv.Itoa(compensationType)] += amount system.VoucherCounts[strconv.Itoa(compensationType)] += amount
if amount > 0 {
needsUpdate = true
}
}
if needsUpdate {
err = db.StoreSystemSaveData(uuid, system)
if err != nil {
return nil, fmt.Errorf("failed to update system save data: %s", err)
}
} }
return system, nil return system, nil