From 820cd7d9e1c09e93134160046a36e5ec5434eb9b Mon Sep 17 00:00:00 2001 From: Dennis Kleber Date: Fri, 12 Jul 2024 14:14:29 +0200 Subject: [PATCH] update for date_of_taking --- dao/event.go | 7 +++++++ dao/taking.go | 5 ++++- dao/update_ticker.go | 12 ------------ dao/updates.go | 19 +++++++++++++++++++ dao/users.go | 1 - models/event.go | 11 ++++++----- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/dao/event.go b/dao/event.go index 28b5189..c8375dc 100644 --- a/dao/event.go +++ b/dao/event.go @@ -161,6 +161,13 @@ func EventUpdate(ctx context.Context, i *models.EventUpdate, token *vcapool.Acce if event.EventASPID != result.EventASPID && result.EventASPID != token.ID { EventASPNotification(ctx, result, "event_asp") } + if event.EndAt != i.EndAt { + updateTaking := bson.D{{Key: "date_of_taking", Value: i.EndAt}} + filterTaking := bson.D{{Key: "_id", Value: event.TakingID}} + if err = TakingCollection.UpdateOne(ctx, filterTaking, vmdb.UpdateSet(updateTaking), nil); err != nil { + return + } + } return } diff --git a/dao/taking.go b/dao/taking.go index d2828db..a251371 100644 --- a/dao/taking.go +++ b/dao/taking.go @@ -184,7 +184,10 @@ func TakingDeletetByID(ctx context.Context, param *vmod.IDParam, token *vcapool. return } if taking.Event.ID != "" { - return vcago.NewBadRequest("taking", "depending_in_event") + return vcago.NewBadRequest("taking", "depending_on_event") + } + if len(taking.DepositUnits) > 0 { + return vcago.NewBadRequest("taking", "depending_on_deposit") } err = TakingCollection.DeleteOne(ctx, filter) return diff --git a/dao/update_ticker.go b/dao/update_ticker.go index 6aa3b2b..79a0d93 100644 --- a/dao/update_ticker.go +++ b/dao/update_ticker.go @@ -36,23 +36,11 @@ func EventStateFinishTicker() { filter.EqualString("event_state.state", "published") filter.LteInt64("end_at", fmt.Sprint(time.Now().Unix())) update := bson.D{{Key: "event_state.state", Value: "finished"}} - events := new([]models.Event) - if err := EventCollection.Find(context.Background(), filter.Bson(), events); err != nil { - log.Print(err) - } if err := EventCollection.UpdateMany(context.Background(), filter.Bson(), vmdb.UpdateSet(update)); err != nil { if !vmdb.ErrNoDocuments(err) { log.Print(err) } } - for _, value := range *events { - filterTaking := bson.D{{Key: "_id", Value: value.TakingID}, {Key: "taking_id", Value: bson.D{{Key: "$ne", Value: ""}}}} - updateTaking := bson.D{{Key: "date_of_taking", Value: value.EndAt}} - if err := TakingCollection.UpdateOne(context.Background(), filterTaking, vmdb.UpdateSet(updateTaking), nil); err != nil { - log.Print(err) - } - } - } // EventStateClosed diff --git a/dao/updates.go b/dao/updates.go index 7d47f8a..aa4f578 100644 --- a/dao/updates.go +++ b/dao/updates.go @@ -74,6 +74,10 @@ func UpdateDatabase() { UpdateTakingCurrency(ctx) InsertUpdate(ctx, "currency_problem") } + if !CheckUpdated(ctx, "date_of_taking_1") { + UpdateDateOfTaking1(ctx) + InsertUpdate(ctx, "date_of_taking_1") + } } func UpdateCrewMaibox(ctx context.Context) { @@ -167,3 +171,18 @@ func UpdateEventCanceledNoIncome(ctx context.Context) { } } } + +func UpdateDateOfTaking1(ctx context.Context) { + eventList := []models.Event{} + if err := EventCollection.Find(ctx, bson.D{{}}, &eventList); err != nil { + log.Print(err) + } + for _, event := range eventList { + update := bson.D{{Key: "date_of_taking", Value: event.EndAt}} + filter := bson.D{{Key: "_id", Value: event.TakingID}} + if err := TakingCollection.UpdateOne(ctx, filter, vmdb.UpdateSet(update), nil); err != nil { + log.Print(err) + } + } + +} diff --git a/dao/users.go b/dao/users.go index 7d33a12..562e401 100644 --- a/dao/users.go +++ b/dao/users.go @@ -55,7 +55,6 @@ func UsersGet(i *models.UserQuery, token *vcapool.AccessToken) (result *[]models opts.SetSkip(i.Skip).SetLimit(i.Limit) } if cursor, cErr := UserViewCollection.Collection.CountDocuments(ctx, filter, opts); cErr != nil { - print(cErr) list_size = 0 } else { list_size = cursor diff --git a/models/event.go b/models/event.go index d69847a..a234d23 100644 --- a/models/event.go +++ b/models/event.go @@ -306,11 +306,12 @@ var EventCollection = "events" func (i *EventDatabase) TakingDatabase() *TakingDatabase { return &TakingDatabase{ - ID: uuid.NewString(), - Name: i.Name, - CrewID: i.CrewID, - Type: "automatically", - Modified: vmod.NewModified(), + ID: uuid.NewString(), + Name: i.Name, + CrewID: i.CrewID, + DateOfTaking: i.EndAt, + Type: "automatically", + Modified: vmod.NewModified(), } } func (i *EventCreate) EventDatabase(token *vcapool.AccessToken) *EventDatabase {