Skip to content

Commit

Permalink
set taking state.no_income true in the case an event was canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
deinelieblings committed Sep 21, 2023
1 parent a3142e9 commit c0c3471
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
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
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

0 comments on commit c0c3471

Please sign in to comment.