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

update for date_of_taking #204

Merged
merged 1 commit into from
Jul 12, 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
7 changes: 7 additions & 0 deletions dao/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 4 additions & 1 deletion dao/taking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions dao/update_ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions dao/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

}
1 change: 0 additions & 1 deletion dao/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading