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

Configured default referral name. #145

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ auth/email-link:
appName: Tenant
teamName: Tenant
users: &users
defaultReferralName: bogus
kyc:
kyc-step1-reset-url: https://localhost:443/v1w/face-auth/
disableConsumer: false
Expand Down
2 changes: 1 addition & 1 deletion users/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ALTER TABLE users ADD COLUMN IF NOT EXISTS kyc_step_blocked smallint NOT NULL DE
ALTER TABLE users ADD COLUMN IF NOT EXISTS kyc_steps_last_updated_at timestamp[];
ALTER TABLE users ADD COLUMN IF NOT EXISTS kyc_steps_created_at timestamp[];
INSERT INTO users (created_at,updated_at,phone_number,phone_number_hash,email,id,username,profile_picture_name,referred_by,city,country,mining_blockchain_account_address,blockchain_account_address, lookup)
VALUES (current_timestamp,current_timestamp,'bogus','bogus','bogus','bogus','bogus','bogus.jpg','bogus','bogus','RO','bogus','bogus',to_tsvector('bogus')),
VALUES (current_timestamp,current_timestamp,'%[1]v','%[1]v','%[1]v','%[1]v','%[1]v','%[1]v.jpg','%[1]v','%[1]v','RO','%[1]v','%[1]v',to_tsvector('%[1]v')),
(current_timestamp,current_timestamp,'icenetwork','icenetwork','icenetwork','icenetwork','icenetwork','icenetwork.jpg','icenetwork','icenetwork','RO','icenetwork','icenetwork',to_tsvector('icenetwork'))
ON CONFLICT DO NOTHING;
CREATE INDEX IF NOT EXISTS users_referred_by_ix ON users (referred_by);
Expand Down
1 change: 1 addition & 0 deletions users/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ type (
}
// | config holds the configuration of this package mounted from `application.yaml`.
config struct {
DefaultReferralName string `yaml:"defaultReferralName"`
messagebroker.Config `mapstructure:",squash"` //nolint:tagliatelle // Nope.
GlobalAggregationInterval struct {
MinMiningSessionDuration stdlibtime.Duration `yaml:"minMiningSessionDuration"`
Expand Down
6 changes: 4 additions & 2 deletions users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ func New(ctx context.Context, _ context.CancelFunc) Repository {
var cfg config
appcfg.MustLoadFromKey(applicationYamlKey, &cfg)

db := storage.MustConnect(ctx, ddl, applicationYamlKey)
ddlWithParams := fmt.Sprintf(ddl, cfg.DefaultReferralName)
db := storage.MustConnect(ctx, ddlWithParams, applicationYamlKey)

return &repository{
cfg: &cfg,
Expand All @@ -47,7 +48,8 @@ func StartProcessor(ctx context.Context, cancel context.CancelFunc) Processor {
appcfg.MustLoadFromKey(applicationYamlKey, &cfg)

var mbConsumer messagebroker.Client
db := storage.MustConnect(ctx, ddl, applicationYamlKey)
ddlWithParams := fmt.Sprintf(ddl, cfg.DefaultReferralName)
db := storage.MustConnect(ctx, ddlWithParams, applicationYamlKey)
mbProducer := messagebroker.MustConnect(ctx, applicationYamlKey)
prc := &processor{repository: &repository{
cfg: &cfg,
Expand Down
7 changes: 4 additions & 3 deletions users/users_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package users

import (
"context"
"fmt"
"sync"

"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -93,10 +94,10 @@ func (r *repository) updateReferredByForAllT1Referrals(ctx context.Context, user
if ctx.Err() != nil {
return errors.Wrap(ctx.Err(), "context failed")
}
sql := `
sql := fmt.Sprintf(`
WITH randomized AS (
SELECT id, referred_by, created_at, hash_code FROM users
WHERE id != 'bogus'
WHERE id != '%[1]v'
AND id != 'icenetwork'
AND username != id
AND referred_by != id
Expand Down Expand Up @@ -125,7 +126,7 @@ func (r *repository) updateReferredByForAllT1Referrals(ctx context.Context, user
u.ID as id
FROM users u
WHERE u.referred_by = $1
AND u.id != $1`
AND u.id != $1`, r.cfg.DefaultReferralName)
type resp struct {
NewReferredBy UserID
ID UserID `db:"id"`
Expand Down
Loading