Skip to content

Commit 53038f8

Browse files
authored
fix: transaction filter for 'account' now correctly ORed in query (#562)
The OR must be applied only to the source and destination account ID, not to the whole query.
1 parent ed79e15 commit 53038f8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

pkg/controllers/transaction.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,15 @@ func (co Controller) GetTransactions(c *gin.Context) {
258258
return
259259
}
260260

261-
query = query.Where(&models.Transaction{
261+
query = query.Where(co.DB.Where(&models.Transaction{
262262
TransactionCreate: models.TransactionCreate{
263263
SourceAccountID: accountID,
264264
},
265265
}).Or(&models.Transaction{
266266
TransactionCreate: models.TransactionCreate{
267267
DestinationAccountID: accountID,
268268
},
269-
})
269+
}))
270270
}
271271

272272
if !filter.AmountLessOrEqual.IsZero() {

pkg/controllers/transaction_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func (suite *TestSuiteStandard) TestGetTransactionsFilter() {
190190
{"Amount more or equal to 100", "amountMoreOrEqual=100", 1},
191191
{"Amount more or equal to 100 and less than 10", "amountMoreOrEqual=100&amountLessOrEqual=10", 0},
192192
{"Amount more or equal to 1 and less than 3", "amountMoreOrEqual=1&amountLessOrEqual=3", 2},
193+
{"Regression - For 'account', query needs to be ORed between the accounts and ANDed with all other conditions", fmt.Sprintf("note=&account=%s", a2.Data.ID), 1},
193194
}
194195

195196
for _, tt := range tests {

0 commit comments

Comments
 (0)