78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
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('/', this.getRecognizedTransactions.bind(this));
|
|
router.get(
|
|
'/transactions/:uncategorizedTransactionId',
|
|
this.getRecognizedTransaction.bind(this)
|
|
);
|
|
|
|
return router;
|
|
}
|
|
|
|
/**
|
|
* 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 filter = this.matchedQueryData(req);
|
|
const { tenantId } = req;
|
|
|
|
try {
|
|
const data = await this.cashflowApplication.getRecognizedTransactions(
|
|
tenantId,
|
|
filter
|
|
);
|
|
return res.status(200).send(data);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retrieves the recognized transaction of the ginen uncategorized transaction.
|
|
* @param {Request} req
|
|
* @param {Response} res
|
|
* @param {NextFunction} next
|
|
* @returns {Promise<Response|null>}
|
|
*/
|
|
async getRecognizedTransaction(
|
|
req: Request<{ uncategorizedTransactionId: number }>,
|
|
res: Response,
|
|
next: NextFunction
|
|
) {
|
|
const { tenantId } = req;
|
|
const { uncategorizedTransactionId } = req.params;
|
|
|
|
try {
|
|
const data = await this.cashflowApplication.getRecognizedTransaction(
|
|
tenantId,
|
|
uncategorizedTransactionId
|
|
);
|
|
return res.status(200).send({ data });
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
}
|
|
}
|