Refactor
This commit is contained in:
parent
9a04c8deb2
commit
b5d81243e0
19
webhook.go
19
webhook.go
@ -17,6 +17,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
|
||||
firefly3TransactionTypeWithdrawal := firefly3.WITHDRAWAL_TransactionTypeProperty
|
||||
firefly3TransactionTypeDeposit := firefly3.DEPOSIT_TransactionTypeProperty
|
||||
firefly3TransactionTypeTransfer := firefly3.TRANSFER_TransactionTypeProperty
|
||||
|
||||
// read request
|
||||
@ -80,15 +81,25 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
firefly3Transactions = append(firefly3Transactions, firefly3Transaction)
|
||||
} else {
|
||||
for _, row := range config.TransactionTypes {
|
||||
if slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc) {
|
||||
sum, _ := strconv.Atoi(firefly3Transaction.Amount)
|
||||
// check name & mcc
|
||||
if !(slices.Contains(row.Names, monobankTransaction.Data.StatementItem.Description) || slices.Contains(row.MccCodes, monobankTransaction.Data.StatementItem.Mcc)) {
|
||||
continue
|
||||
}
|
||||
|
||||
// check max sum
|
||||
if row.SumMax == 0 || sum <= row.SumMax {
|
||||
sum, _ := strconv.Atoi(firefly3Transaction.Amount)
|
||||
if row.SumMax > 0 && sum > row.SumMax {
|
||||
continue
|
||||
}
|
||||
|
||||
// make transaction
|
||||
switch row.Firefly3.Type {
|
||||
case "withdrawal":
|
||||
firefly3Transaction.Type_ = &firefly3TransactionTypeWithdrawal
|
||||
break
|
||||
case "deposit":
|
||||
firefly3Transaction.Type_ = &firefly3TransactionTypeDeposit
|
||||
break
|
||||
case "transfer":
|
||||
firefly3Transaction.Type_ = &firefly3TransactionTypeTransfer
|
||||
break
|
||||
@ -103,8 +114,6 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// record transfer fee
|
||||
if monobankTransaction.Data.StatementItem.CommissionRate > 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user