Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fulfill event for referred if referee scan passport #15

Merged
merged 2 commits into from
May 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions internal/service/handlers/verify_passport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"encoding/json"
"fmt"
"math/big"
"net/http"

Expand Down Expand Up @@ -87,11 +88,44 @@ func VerifyPassport(w http.ResponseWriter, r *http.Request) {
return
}

_, err = EventsQ(r).
FilterByID(event.ID).
Update(data.EventFulfilled, nil, nil)
var referralEvent = true
evType = EventTypes(r).Get(evtypes.TypeReferralSpecific, evtypes.FilterInactive)
if evType == nil {
Log(r).Debug("Referral event type is disabled or expired, not accruing points to referrer")
referralEvent = false
}

err = EventsQ(r).Transaction(func() (err error) {
if referralEvent {
// ReferredBy always valid because of the previous logic
referral, err := ReferralsQ(r).Get(balance.ReferredBy.String)
if err != nil {
return errors.Wrap(err, "failed to get referral by ID")
}

err = EventsQ(r).Insert(data.Event{
Nullifier: referral.Nullifier,
Type: evType.Name,
Status: data.EventFulfilled,
Meta: data.Jsonb(fmt.Sprintf(`{"nullifier": "%s"}`, nullifier)),
})
if err != nil {
return errors.Wrap(err, "add event for referrer")
}
}

_, err = EventsQ(r).
FilterByID(event.ID).
Update(data.EventFulfilled, nil, nil)
if err != nil {
return errors.Wrap(err, "failed to update passport scan event")
}

return nil
})

if err != nil {
Log(r).WithError(err).Error("Failed to update passport scan event")
Log(r).WithError(err).Error("Failed to add referal event and update verify passport event")
Zaptoss marked this conversation as resolved.
Show resolved Hide resolved
ape.RenderErr(w, problems.InternalError())
return
}
Expand Down
Loading