feat: Categorize the bank synced transactions

This commit is contained in:
Ahmed Bouhuolia
2024-02-29 23:53:26 +02:00
parent 0833baabda
commit ea8c5458ff
31 changed files with 901 additions and 35 deletions

View File

@@ -0,0 +1,64 @@
/* eslint-disable global-require */
import TenantModel from 'models/TenantModel';
import { Model } from 'objection';
export default class UncategorizedCashflowTransaction extends TenantModel {
amount: number;
/**
* Table name.
*/
static get tableName() {
return 'uncategorized_cashflow_transactions';
}
/**
* Timestamps columns.
*/
static get timestamps() {
return ['createdAt', 'updatedAt'];
}
/**
* Retrieves the withdrawal amount.
* @returns {number}
*/
public withdrawal() {
return this.amount > 0 ? Math.abs(this.amount) : 0;
}
/**
* Retrieves the deposit amount.
* @returns {number}
*/
public deposit() {
return this.amount < 0 ? Math.abs(this.amount) : 0;
}
/**
* Virtual attributes.
*/
static get virtualAttributes() {
return ['withdrawal', 'deposit'];
}
/**
* Relationship mapping.
*/
static get relationMappings() {
const Account = require('models/Account');
return {
/**
* Transaction may has associated to account.
*/
account: {
relation: Model.BelongsToOneRelation,
modelClass: Account.default,
join: {
from: 'uncategorized_cashflow_transactions.accountId',
to: 'accounts.id',
},
},
};
}
}