feat: wip categorized transactions

This commit is contained in:
Ahmed Bouhuolia
2024-03-04 21:01:36 +02:00
parent f23e8d98f6
commit 68f2f4ee84
12 changed files with 115 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
/* eslint-disable global-require */
import TenantModel from 'models/TenantModel';
import { Model } from 'objection';
import Account from './Account';
export default class UncategorizedCashflowTransaction extends TenantModel {
amount: number;
@@ -80,4 +81,29 @@ export default class UncategorizedCashflowTransaction extends TenantModel {
},
};
}
/**
*
* @param queryContext
*/
public async $afterInsert(queryContext) {
await super.$afterInsert(queryContext);
// Increments the uncategorized transactions count of the associated account.
await Account.query(queryContext.transaction)
.findById(this.accountId)
.increment('uncategorized_transactions', 1);
}
/**
*
* @param queryContext
*/
public async $afterDelete(queryContext) {
await super.$afterDelete(queryContext);
await Account.query()
.findById(this.accountId)
.decrement('uncategorized_transactions', 1);
}
}