From a44a6c382f6d8232b0bbf001ddc3207e05be684b Mon Sep 17 00:00:00 2001 From: Up Date: Sun, 12 May 2024 08:30:46 +0200 Subject: [PATCH] save data when applying vouchers --- api/savedata/get.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/api/savedata/get.go b/api/savedata/get.go index 7c844a9..8c71797 100644 --- a/api/savedata/get.go +++ b/api/savedata/get.go @@ -38,13 +38,25 @@ func Get(uuid []byte, datatype, slot int) (any, error) { return nil, err } + // TODO this should be a transaction compensations, err := db.FetchAndClaimAccountCompensations(uuid) if err != nil { return nil, fmt.Errorf("failed to fetch compensations: %s", err) } + needsUpdate := false for compensationType, amount := range compensations { 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