39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package storage
|
|
|
|
import "time"
|
|
|
|
const (
|
|
SubscriptionStatusAvailable = iota
|
|
SubscriptionStatusInitiated
|
|
SubscriptionStatusDeclined
|
|
)
|
|
|
|
type Incentive struct {
|
|
ID string
|
|
Name string
|
|
Start time.Time
|
|
AcceptedProofLevels []string // A, B, C
|
|
}
|
|
|
|
type IncentiveSubscription struct {
|
|
ID string `bson:"_id"`
|
|
IncentiveID string `bson:"incentive_id"`
|
|
UserID string `bson:"user_id"`
|
|
IdentityVerificationIDs []string `bson:"identity_verification_ids"` // identity checks to avoid multiple persons subscribing to similar incentives (OIDC subjects, passport/identity card numbers, ...)
|
|
Declined bool `bson:"declined"`
|
|
Data map[string]any `bson:"data"`
|
|
SubscriptionDatetime time.Time `bson:"subscription_datetime"`
|
|
}
|
|
|
|
func (i Incentive) SubscriptionStatus(incentiveSubscriptions []IncentiveSubscription) int {
|
|
for _, subscription := range incentiveSubscriptions {
|
|
if i.ID == subscription.IncentiveID {
|
|
if subscription.Declined {
|
|
return SubscriptionStatusDeclined
|
|
}
|
|
return SubscriptionStatusInitiated
|
|
}
|
|
}
|
|
return SubscriptionStatusAvailable
|
|
}
|