Skip to content

Commit

Permalink
Merge pull request #148 from Viva-con-Agua/dk/pool_issues
Browse files Browse the repository at this point in the history
Dk/pool issues
  • Loading branch information
TobiKaestle authored Sep 22, 2023
2 parents a079da5 + 5572d03 commit 456df9d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 24 deletions.
3 changes: 2 additions & 1 deletion dao/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ func DepositGet(ctx context.Context, i *models.DepositQuery, token *vcapool.Acce
return
}
filter := i.PermittedFilter(token)
sort := i.Sort()
result = new([]models.Deposit)
if err = DepositCollection.Aggregate(
ctx,
models.DepositPipeline().Match(filter).Pipe,
models.DepositPipeline().SortFields(sort).Match(filter).Sort(sort).Pipe,
result,
); err != nil {
return
Expand Down
23 changes: 23 additions & 0 deletions dao/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ func EventUpdate(ctx context.Context, i *models.EventUpdate, token *vcapool.Acce
); err != nil {
return
}
if event.EventState.State != result.EventState.State {
if result.EventState.State == "canceled" {
EventParticipantsNotification(ctx, result, "event_cancel")
updateTaking := bson.D{{Key: "state.no_income", Value: true}}
filterTaking := bson.D{{Key: "_id", Value: event.Taking.ID}}
if err = TakingCollection.UpdateOne(ctx, filterTaking, vmdb.UpdateSet(updateTaking), nil); err != nil {
return
}
}
if result.EventState.State == "published" ||
result.EventState.State == "canceled" ||
(result.EventState.State == "requested" && result.EventState.CrewConfirmation == "") {
EventStateNotification(ctx, result, "event_state")
}
} else if event.StartAt != result.StartAt ||
event.EndAt != result.EndAt ||
event.Location.PlaceID != result.Location.PlaceID ||
event.EventASPID != result.EventASPID {
EventParticipantsNotification(ctx, result, "event_update")
}
if event.EventASPID != result.EventASPID && result.EventASPID != token.ID {
EventASPNotification(ctx, result, "event_asp")
}
return
}

Expand Down
19 changes: 19 additions & 0 deletions dao/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func UpdateDatabase() {
UpdateDepositUnitCurrency(ctx)
InsertUpdate(ctx, "deposit_unit_currency")
}
if !CheckUpdated(ctx, "taking_no_income_event_canceled") {
UpdateEventCanceledNoIncome(ctx)
InsertUpdate(ctx, "taking_no_income_event_canceled")
}
}

func UpdateCrewMaibox(ctx context.Context) {
Expand Down Expand Up @@ -139,3 +143,18 @@ func UpdateDepositUnitCurrency(ctx context.Context) {
return
}
}

func UpdateEventCanceledNoIncome(ctx context.Context) {
filterEvent := bson.D{{Key: "event_state.state", Value: "canceled"}}
eventResult := []models.Event{}
if err := EventCollection.Find(ctx, filterEvent, &eventResult); err != nil {
return
}
for _, value := range eventResult {
updateTaking := bson.D{{Key: "state.no_income", Value: true}}
filterTaking := bson.D{{Key: "_id", Value: value.TakingID}}
if err := TakingCollection.UpdateOne(ctx, filterTaking, vmdb.UpdateSet(updateTaking), nil); err != nil {
return
}
}
}
2 changes: 1 addition & 1 deletion handlers/token/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (i *DepositHandler) Get(cc echo.Context) (err error) {
if result, err = dao.DepositGet(c.Ctx(), body, token); err != nil {
return
}
return c.Selected(result)
return c.Listed(result, int64(len(*result)))
}

func (i *DepositHandler) GetByID(cc echo.Context) (err error) {
Expand Down
22 changes: 0 additions & 22 deletions handlers/token/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,10 @@ func (i *EventHandler) Update(cc echo.Context) (err error) {
if err = c.AccessToken(token); err != nil {
return
}
event := new(models.Event)
if event, err = dao.EventGetByID(c.Ctx(), &models.EventParam{ID: body.ID}, token); err != nil {
return
}
result := new(models.Event)
if result, err = dao.EventUpdate(c.Ctx(), body, token); err != nil {
return
}
if event.EventState.State != result.EventState.State {
if result.EventState.State == "canceled" {
dao.EventParticipantsNotification(c.Ctx(), result, "event_cancel")
}
if result.EventState.State == "published" ||
result.EventState.State == "canceled" ||
(result.EventState.State == "requested" && result.EventState.CrewConfirmation == "") {
dao.EventStateNotification(c.Ctx(), result, "event_state")
}
} else if event.StartAt != result.StartAt ||
event.EndAt != result.EndAt ||
event.Location.PlaceID != result.Location.PlaceID ||
event.EventASPID != result.EventASPID {
dao.EventParticipantsNotification(c.Ctx(), result, "event_update")
}
if event.EventASPID != result.EventASPID && result.EventASPID != token.ID {
dao.EventASPNotification(c.Ctx(), result, "event_asp")
}
result.EditorID = token.ID
go func() {
if err = dao.IDjango.Post(result, "/v1/pool/event/update/"); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions models/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ type (
UpdatedFrom string `query:"updated_from" qs:"updated_from"`
CreatedTo string `query:"created_to" qs:"created_to"`
CreatedFrom string `query:"created_from" qs:"created_from"`
SortField string `query:"sort"`
SortDirection string `query:"sort_dir"`
}
DepositParam struct {
ID string `param:"id"`
Expand Down Expand Up @@ -250,3 +252,9 @@ func (i *DepositParam) PermittedFilter(token *vcapool.AccessToken) bson.D {
}
return filter.Bson()
}

func (i *DepositQuery) Sort() bson.D {
sort := vmdb.NewSort()
sort.Add(i.SortField, i.SortDirection)
return sort.Bson()
}
1 change: 1 addition & 0 deletions models/taking.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func (i *TakingQuery) PermittedFilter(token *vcapool.AccessToken) bson.D {
{Key: "state.wait.amount", Value: 0},
{Key: "state.confirmed.amount", Value: 0},
{Key: "state.open.amount", Value: 0},
{Key: "state.no_income", Value: bson.D{{Key: "$ne", Value: true}}},
})
}
if i.StatusNoIncome {
Expand Down

0 comments on commit 456df9d

Please sign in to comment.