mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
feat: endpoint to get recognized transactions
This commit is contained in:
@@ -4,13 +4,14 @@ import BaseController from '@/api/controllers/BaseController';
|
|||||||
import { PlaidBankingController } from './PlaidBankingController';
|
import { PlaidBankingController } from './PlaidBankingController';
|
||||||
import { BankingRulesController } from './BankingRulesController';
|
import { BankingRulesController } from './BankingRulesController';
|
||||||
import { BankTransactionsMatchingController } from './BankTransactionsMatchingController';
|
import { BankTransactionsMatchingController } from './BankTransactionsMatchingController';
|
||||||
|
import { RecognizedTransactionsController } from './RecognizedTransactionsController';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class BankingController extends BaseController {
|
export class BankingController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
*/
|
*/
|
||||||
router() {
|
public router() {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.use('/plaid', Container.get(PlaidBankingController).router());
|
router.use('/plaid', Container.get(PlaidBankingController).router());
|
||||||
@@ -19,6 +20,10 @@ export class BankingController extends BaseController {
|
|||||||
'/matches',
|
'/matches',
|
||||||
Container.get(BankTransactionsMatchingController).router()
|
Container.get(BankTransactionsMatchingController).router()
|
||||||
);
|
);
|
||||||
|
router.use(
|
||||||
|
'/recognized',
|
||||||
|
Container.get(RecognizedTransactionsController).router()
|
||||||
|
);
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { NextFunction, Request, Response, Router } from 'express';
|
||||||
|
import BaseController from '@/api/controllers/BaseController';
|
||||||
|
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class RecognizedTransactionsController extends BaseController {
|
||||||
|
@Inject()
|
||||||
|
private cashflowApplication: CashflowApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Router constructor.
|
||||||
|
*/
|
||||||
|
router() {
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/accounts/:accountId',
|
||||||
|
this.getRecognizedTransactions.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
return router;
|
||||||
|
}
|
||||||
|
k;
|
||||||
|
/**
|
||||||
|
* Retrieves the recognized bank transactions.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
* @returns {Promise<Response|null>}
|
||||||
|
*/
|
||||||
|
async getRecognizedTransactions(
|
||||||
|
req: Request<{ accountId: number }>,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
const { accountId } = req.params;
|
||||||
|
const { tenantId } = req;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.cashflowApplication.getRecognizedTransactions(
|
||||||
|
tenantId,
|
||||||
|
accountId
|
||||||
|
);
|
||||||
|
return res.status(200).send({ data });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import TenantModel from 'models/TenantModel';
|
import TenantModel from 'models/TenantModel';
|
||||||
|
import { Model } from 'objection';
|
||||||
|
|
||||||
export class RecognizedBankTransaction extends TenantModel {
|
export class RecognizedBankTransaction extends TenantModel {
|
||||||
/**
|
/**
|
||||||
@@ -21,4 +22,38 @@ export class RecognizedBankTransaction extends TenantModel {
|
|||||||
static get virtualAttributes() {
|
static get virtualAttributes() {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relationship mapping.
|
||||||
|
*/
|
||||||
|
static get relationMappings() {
|
||||||
|
const UncategorizedCashflowTransaction = require('./UncategorizedCashflowTransaction');
|
||||||
|
const Account = require('./Account');
|
||||||
|
|
||||||
|
return {
|
||||||
|
/**
|
||||||
|
* Recognized bank transaction may belongs to uncategorized transactions.
|
||||||
|
*/
|
||||||
|
uncategorizedTransactions: {
|
||||||
|
relation: Model.HasManyRelation,
|
||||||
|
modelClass: UncategorizedCashflowTransaction.default,
|
||||||
|
join: {
|
||||||
|
from: 'recognized_bank_transactions.uncategorizedTransactionId',
|
||||||
|
to: 'uncategorized_cashflow_transactions.id',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recognized bank transaction may belongs to assign account.
|
||||||
|
*/
|
||||||
|
assignAccount: {
|
||||||
|
relation: Model.BelongsToOneRelation,
|
||||||
|
modelClass: Account.default,
|
||||||
|
join: {
|
||||||
|
from: 'recognized_bank_transactions.assignedAccountId',
|
||||||
|
to: 'accounts.id',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user