Skip to content

Commit

Permalink
Merge pull request #143 from Viva-con-Agua/stage
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
deinelieblings authored Sep 6, 2023
2 parents 3bd3b30 + 50dd088 commit 50768df
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions dao/taking.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dao

import (
"context"
"log"
"pool-backend/models"

"github.com/Viva-con-Agua/vcago/vmdb"
Expand Down Expand Up @@ -92,6 +93,67 @@ func TakingUpdate(ctx context.Context, i *models.TakingUpdate, token *vcapool.Ac
}
}
}
if !takingDatabase.State.NoIncome && i.State.NoIncome {
event := new(models.EventUpdate)
if err = EventCollection.FindOne(
ctx,
bson.D{{Key: "taking_id", Value: takingDatabase.ID}},
event,
); err != nil {
if !vmdb.ErrNoDocuments(err) {
return
}
err = nil
}

if event.ID != "" {
event.EventState.OldState = event.EventState.State
event.EventState.State = "closed"
e := new(models.Event)
if err = EventCollection.UpdateOneAggregate(
ctx,
event.Match(),
vmdb.UpdateSet(event),
e,
models.EventPipeline(token).Match(event.Match()).Pipe,
); err != nil {
return
}

// Add takings to CRM
var taking *models.Taking
if taking, err = TakingGetByID(ctx, &models.TakingParam{ID: takingDatabase.ID}, token); err != nil {
log.Print(err)
}

taking.EditorID = token.ID
if err = IDjango.Post(taking, "/v1/pool/taking/create/"); err != nil {
log.Print(err)
}

// Update CRM event
if err = IDjango.Post(e, "/v1/pool/event/update/"); err != nil {
log.Print(err)
}

// Add participations to event
participations := new([]models.Participation)

if err = ParticipationCollection.Aggregate(
ctx,
models.ParticipationPipeline().Match(bson.D{{Key: "event_id", Value: e.ID}}).Pipe,
participations,
); err != nil {
return
}

if err = IDjango.Post(participations, "/v1/pool/participations/create/"); err != nil {
log.Print(err)
err = nil
}

}
}
if err = ActivityCollection.InsertOne(ctx, TakingUpdatedActivity.New(token.ID, takingDatabase.ID)); err != nil {
return
}
Expand Down
1 change: 1 addition & 0 deletions models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type (
InternalConfirmation string `json:"internal_confirmation" bson:"internal_confirmation"`
TakingID string `json:"taking_id" bson:"taking_id"`
DepositID string `json:"deposit_id" bson:"deposit_id"`
OldState string `json:"-" bson:"old_state"`
}
EventStatePublic struct {
State string `json:"state" bson:"state"`
Expand Down

0 comments on commit 50768df

Please sign in to comment.