From 838fe482242912e8c50876c07fa6c4536b7e5668 Mon Sep 17 00:00:00 2001 From: Zaptoss Date: Mon, 8 Jul 2024 14:51:52 +0300 Subject: [PATCH] Remove QR-code from event response. Fix adding events for user after create new event type. --- internal/data/evtypes/models/event_type.go | 1 - .../service/handlers/create_event_type.go | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/internal/data/evtypes/models/event_type.go b/internal/data/evtypes/models/event_type.go index 847507e..4b99958 100644 --- a/internal/data/evtypes/models/event_type.go +++ b/internal/data/evtypes/models/event_type.go @@ -70,7 +70,6 @@ func (e EventType) Resource() resources.EventStaticMeta { ActionUrl: e.ActionURL, Logo: e.Logo, Flag: e.Flag(), - QrCodeValue: e.QRCodeValue, } } diff --git a/internal/service/handlers/create_event_type.go b/internal/service/handlers/create_event_type.go index b8f9488..12173e8 100644 --- a/internal/service/handlers/create_event_type.go +++ b/internal/service/handlers/create_event_type.go @@ -4,6 +4,8 @@ import ( "net/http" "github.com/rarimo/geo-auth-svc/pkg/auth" + "github.com/rarimo/geo-points-svc/internal/data" + "github.com/rarimo/geo-points-svc/internal/data/evtypes" "github.com/rarimo/geo-points-svc/internal/data/evtypes/models" "github.com/rarimo/geo-points-svc/internal/service/requests" "gitlab.com/distributed_lab/ape" @@ -44,5 +46,30 @@ func CreateEventType(w http.ResponseWriter, r *http.Request) { } EventTypes(r).Push(typeModel) + if evtypes.FilterNotOpenable(typeModel) { + w.WriteHeader(http.StatusNoContent) + return + } + + balances, err := BalancesQ(r).FilterDisabled().Select() + if err != nil { + Log(r).WithError(err).Error("Failed to select balances") + ape.RenderErr(w, problems.InternalError()) + return + } + + eventsToInsert := make([]data.Event, 0, len(balances)) + for _, b := range balances { + eventsToInsert = append(eventsToInsert, data.Event{ + Nullifier: b.Nullifier, + Status: data.EventOpen, + Type: typeModel.Name, + }) + } + if err = EventsQ(r).Insert(eventsToInsert...); err != nil { + Log(r).WithError(err).Error("Failed to insert qr-code events") + ape.RenderErr(w, problems.InternalError()) + return + } w.WriteHeader(http.StatusNoContent) }