Skip to content

Commit

Permalink
Merge pull request #160 from Viva-con-Agua/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
deinelieblings authored Nov 17, 2023
2 parents 1668533 + b153fd5 commit 2b86391
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
8 changes: 8 additions & 0 deletions dao/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ func ParticipationUpdate(ctx context.Context, i *models.ParticipationUpdate, tok
); err != nil {
return
}
if event.Status != result.Status {
if result.Status == "confirmed" || result.Status == "rejected" {
ParticipationNotification(ctx, result)
}
if result.Status == "withdrawn" {
ParticipationWithdrawnNotification(ctx, result)
}
}
return
}

Expand Down
15 changes: 12 additions & 3 deletions dao/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func UpdateDatabase() {
UpdateEventCanceledNoIncome(ctx)
InsertUpdate(ctx, "taking_no_income_event_canceled")
}
if !CheckUpdated(ctx, "currency_problem") {
UpdateDepositCurrency(ctx)
UpdateDepositUnitCurrency(ctx)
UpdateTakingCurrency(ctx)
InsertUpdate(ctx, "currency_problem")
}
}

func UpdateCrewMaibox(ctx context.Context) {
Expand Down Expand Up @@ -125,21 +131,24 @@ func UpdateConfirmAdmin(ctx context.Context) {

func UpdateTakingCurrency(ctx context.Context) {
update := bson.D{{Key: "currency", Value: "EUR"}}
if _, err := TakingCollection.Collection.UpdateMany(ctx, bson.D{}, vmdb.UpdateSet(update)); err != nil {
filter := bson.D{{Key: "money.currency", Value: ""}}
if _, err := TakingCollection.Collection.UpdateMany(ctx, filter, vmdb.UpdateSet(update)); err != nil {
return
}
}

func UpdateDepositCurrency(ctx context.Context) {
update := bson.D{{Key: "money.currency", Value: "EUR"}}
if _, err := DepositCollection.Collection.UpdateMany(ctx, bson.D{}, vmdb.UpdateSet(update)); err != nil {
filter := bson.D{{Key: "money.currency", Value: ""}}
if _, err := DepositCollection.Collection.UpdateMany(ctx, filter, vmdb.UpdateSet(update)); err != nil {
return
}
}

func UpdateDepositUnitCurrency(ctx context.Context) {
update := bson.D{{Key: "money.currency", Value: "EUR"}}
if _, err := DepositUnitCollection.Collection.UpdateMany(ctx, bson.D{}, vmdb.UpdateSet(update)); err != nil {
filter := bson.D{{Key: "money.currency", Value: ""}}
if _, err := DepositUnitCollection.Collection.UpdateMany(ctx, filter, vmdb.UpdateSet(update)); err != nil {
return
}
}
Expand Down
6 changes: 0 additions & 6 deletions handlers/token/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ func (i *ParticipationHandler) Update(cc echo.Context) (err error) {
if result, err = dao.ParticipationUpdate(c.Ctx(), body, token); err != nil {
return
}
if result.Status == "confirmed" || result.Status == "rejected" {
dao.ParticipationNotification(c.Ctx(), result)
}
if result.Status == "withdrawn" {
dao.ParticipationWithdrawnNotification(c.Ctx(), result)
}
return c.Updated(result)
}

Expand Down
7 changes: 6 additions & 1 deletion models/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type (
HasExternal bool `json:"has_external" bson:"has_external"`
External External `json:"external" bson:"external"`
UpdateState string `json:"update_state" bson:"-"`
Money vmod.Money `json:"-" bson:"money"`
Money vmod.Money `json:"money" bson:"money"`
}
DepositDatabase struct {
ID string `json:"id" bson:"_id"`
Expand Down Expand Up @@ -223,8 +223,13 @@ func (i *DepositUpdate) DepositDatabase(current *Deposit) (r *DepositUpdate, cre
amount += value.Money.Amount
}
}
currency := "EUR"
if i.DepositUnit != nil {
currency = i.DepositUnit[0].Money.Currency
}
r = i
r.Money.Amount = amount
r.Money.Currency = currency
return
}

Expand Down

0 comments on commit 2b86391

Please sign in to comment.