Skip to content

Commit

Permalink
required for webapp issue
Browse files Browse the repository at this point in the history
  • Loading branch information
deinelieblings committed Sep 26, 2024
1 parent bab0df4 commit 55282f5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
6 changes: 6 additions & 0 deletions dao/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ func InitialDatabase() {
)
UpdateCollection = Database.Collection("updates").CreateIndex("name", true)
ReceiptFileCollection = Database.Collection(models.ReceiptFileCollection).CreateIndex("deposit_id", false)
Database.Database.CreateView(
context.Background(),
models.TakingDepositView,
models.TakingCollection,
models.TakingPipelineDeposit().Pipe,
)
}

func FixDatabase() {
Expand Down
21 changes: 20 additions & 1 deletion dao/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ func UpdateDatabase() {
if !CheckUpdated(ctx, "event_applications") {
UpdateEventApplications(ctx)
InsertUpdate(ctx, "event_applications")
}
}
if !CheckUpdated(ctx, "last_login_date_1") {
UpdateSetLastLoginDate(ctx)
InsertUpdate(ctx, "last_login_date_1")
}
if !CheckUpdated(ctx, "update_deposit_units_1") {
UpdateDepositUnitNorms(ctx)
InsertUpdate(ctx, "update_deposit_units_1")
}
}

func UpdateCrewMaibox(ctx context.Context) {
Expand Down Expand Up @@ -255,3 +259,18 @@ func UpdateSetLastLoginDate(ctx context.Context) {
log.Print(err)
}
}

func UpdateDepositUnitNorms(ctx context.Context) {
filterDonation := vmdb.NewFilter()
filterDonation.EqualStringList("value", []string{"unknown", "can", "box", "gl", "other"})
filterEco := vmdb.NewFilter()
filterEco.EqualStringList("value", []string{"merch", "other_ec"})
updateDonation := bson.D{{Key: "$set", Value: bson.D{{Key: "norms", Value: "donation"}}}}
updateEco := bson.D{{Key: "$set", Value: bson.D{{Key: "norms", Value: "economic"}}}}
if err := SourceCollection.UpdateMany(ctx, filterDonation.Bson(), updateDonation); err != nil {
log.Print(err)
}
if err := SourceCollection.UpdateMany(ctx, filterEco.Bson(), updateEco); err != nil {
log.Print(err)
}
}
18 changes: 9 additions & 9 deletions models/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ type (
Money vmod.Money `json:"money" bson:"money"`
}
DepositUnit struct {
ID string `json:"id" bson:"_id"`
TakingID string `json:"taking_id" bson:"taking_id"`
Taking TakingDatabase `json:"taking" bson:"taking"`
Money vmod.Money `json:"money" bson:"money"`
DepositID string `json:"deposit_id" bson:"deposit_id"`
Status string `json:"status" bson:"status"`
Modified vmod.Modified `json:"modified" bson:"modified"`
ID string `json:"id" bson:"_id"`
TakingID string `json:"taking_id" bson:"taking_id"`
Taking Taking `json:"taking" bson:"taking"`
Money vmod.Money `json:"money" bson:"money"`
DepositID string `json:"deposit_id" bson:"deposit_id"`
Status string `json:"status" bson:"status"`
Modified vmod.Modified `json:"modified" bson:"modified"`
}
DepositUnitTaking struct {
ID string `json:"id" bson:"_id"`
TakingID string `json:"taking_id" bson:"taking_id"`
Taking TakingDatabase `json:"taking" bson:"taking"`
Taking Taking `json:"taking" bson:"taking"`
Money vmod.Money `json:"money" bson:"money"`
DepositID string `json:"deposit_id" bson:"deposit_id"`
Deposit DepositDatabase `json:"deposit" bson:"deposit"`
Expand Down Expand Up @@ -128,7 +128,7 @@ func (i *DepositParam) DepositSyncPermission(token *vcapool.AccessToken) (err er
func DepositPipeline() *vmdb.Pipeline {
pipe := vmdb.NewPipeline()
pipe.LookupUnwind(DepositUnitCollection, "_id", "deposit_id", "deposit_units")
pipe.LookupUnwind(TakingCollection, "deposit_units.taking_id", "_id", "deposit_units.taking")
pipe.LookupUnwind(TakingDepositView, "deposit_units.taking_id", "_id", "deposit_units.taking")
pipe.Append(bson.D{
{Key: "$group", Value: bson.D{
{Key: "_id", Value: "$_id"}, {Key: "deposit_units", Value: bson.D{
Expand Down
8 changes: 8 additions & 0 deletions models/taking.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type (
)

var TakingCollection = "takings"
var TakingDepositView = "taking_deposit_view"

func TakingPermission(token *vcapool.AccessToken) (err error) {
if !(token.Roles.Validate("admin;employee") || token.PoolRoles.Validate("finance")) {
Expand Down Expand Up @@ -143,6 +144,13 @@ func TakingPipelineTicker() *vmdb.Pipeline {
return pipe
}

func TakingPipelineDeposit() *vmdb.Pipeline {
pipe := vmdb.NewPipeline()
pipe.LookupUnwind(EventCollection, "_id", "taking_id", "event")
pipe.Lookup(SourceCollection, "_id", "taking_id", "sources")
return pipe
}

func (i *TakingCreate) TakingDatabase() *TakingDatabase {
currency := "EUR"
if len(i.NewSource) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func NewUserUpdate(user *vmod.User) *UserUpdate {

func UserPipeline(user bool) (pipe *vmdb.Pipeline) {
pipe = vmdb.NewPipeline()
if user == true {
if user {
pipe.LookupUnwind(AddressesCollection, "_id", "user_id", "address")
} else {
pipe.LookupUnwind(AddressesCollection, "_id", "user_id", "address_data")
Expand Down

0 comments on commit 55282f5

Please sign in to comment.