Skip to content

Commit

Permalink
solves #181
Browse files Browse the repository at this point in the history
  • Loading branch information
deinelieblings committed Jun 27, 2024
1 parent faa2b0a commit e814866
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
12 changes: 12 additions & 0 deletions dao/update_ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,21 @@ 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 {
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
55 changes: 30 additions & 25 deletions models/taking.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,32 @@ import (

type (
TakingCreate struct {
Name string `json:"name" bson:"name"`
CrewID string `json:"crew_id" bson:"crew_id"`
NewSource []SourceCreate `json:"new_sources"`
Comment string `json:"comment"`
Name string `json:"name" bson:"name"`
CrewID string `json:"crew_id" bson:"crew_id"`
NewSource []SourceCreate `json:"new_sources"`
DateOfTaking int64 `json:"date_of_taking" bson:"date_of_taking"`
Comment string `json:"comment"`
}
TakingUpdate struct {
ID string `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
CrewID string `json:"crew_id" bson:"crew_id"`
Sources []SourceUpdate `json:"sources" bson:"-"`
State TakingStateUpdate `json:"state" bson:"state"`
Comment string `json:"comment"`
ID string `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
CrewID string `json:"crew_id" bson:"crew_id"`
Sources []SourceUpdate `json:"sources" bson:"-"`
State TakingStateUpdate `json:"state" bson:"state"`
DateOfTaking int64 `json:"date_of_taking" bson:"date_of_taking"`
Comment string `json:"comment"`
}

TakingDatabase struct {
ID string `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
CrewID string `json:"crew_id" bson:"crew_id"`
Type string `json:"type" bson:"type"`
Comment string `json:"comment" bson:"comment"`
State TakingState `json:"state" bson:"state"`
Currency string `json:"-" bson:"currency"`
Modified vmod.Modified `json:"modified" bson:"modified"`
ID string `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
CrewID string `json:"crew_id" bson:"crew_id"`
Type string `json:"type" bson:"type"`
Comment string `json:"comment" bson:"comment"`
State TakingState `json:"state" bson:"state"`
Currency string `json:"-" bson:"currency"`
DateOfTaking int64 `json:"date_of_taking" bson:"date_of_taking"`
Modified vmod.Modified `json:"modified" bson:"modified"`
}
Taking struct {
ID string `json:"id" bson:"_id"`
Expand All @@ -46,6 +49,7 @@ type (
Event Event `json:"event" bson:"event"`
Source []Source `json:"sources" bson:"sources"`
State TakingState `json:"state" bson:"state"`
DateOfTaking int64 `json:"date_of_taking" bson:"date_of_taking"`
Comment string `json:"comment" bson:"comment"`
EditorID string `json:"editor_id" bson:"-"`
DepositUnits []DepositUnitTaking `json:"deposit_units" bson:"deposit_units"`
Expand Down Expand Up @@ -138,13 +142,14 @@ func TakingPipelineTicker() *vmdb.Pipeline {

func (i *TakingCreate) TakingDatabase() *TakingDatabase {
return &TakingDatabase{
ID: uuid.NewString(),
Name: i.Name,
CrewID: i.CrewID,
Type: "manually",
Currency: i.NewSource[0].Money.Currency,
Comment: i.Comment,
Modified: vmod.NewModified(),
ID: uuid.NewString(),
Name: i.Name,
CrewID: i.CrewID,
Type: "manually",
Currency: i.NewSource[0].Money.Currency,
DateOfTaking: i.DateOfTaking,
Comment: i.Comment,
Modified: vmod.NewModified(),
}
}

Expand Down

0 comments on commit e814866

Please sign in to comment.