feat: exclude bank transaction

This commit is contained in:
Ahmed Bouhuolia
2024-06-21 11:33:03 +02:00
parent 738a84bb4b
commit ca403872b3
3 changed files with 12 additions and 31 deletions

View File

@@ -31,7 +31,6 @@ export default class GetCashflowAccounts extends BaseController {
query('search_keyword').optional({ nullable: true }).isString().trim(), query('search_keyword').optional({ nullable: true }).isString().trim(),
], ],
this.asyncMiddleware(this.getCashflowAccounts), this.asyncMiddleware(this.getCashflowAccounts),
this.catchServiceErrors
); );
return router; return router;
} }
@@ -67,22 +66,4 @@ export default class GetCashflowAccounts extends BaseController {
next(error); next(error);
} }
}; };
/**
* Catches the service errors.
* @param {Error} error - Error.
* @param {Request} req - Request.
* @param {Response} res - Response.
* @param {NextFunction} next -
*/
private catchServiceErrors(
error,
req: Request,
res: Response,
next: NextFunction
) {
if (error instanceof ServiceError) {
}
next(error);
}
} }

View File

@@ -19,20 +19,20 @@ export class ExcludeBankTransaction {
*/ */
public async excludeBankTransaction( public async excludeBankTransaction(
tenantId: number, tenantId: number,
bankTransactionId: number uncategorizedTransactionId: number
) { ) {
const { UncategorizeCashflowTransaction } = this.tenancy.models(tenantId); const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
const oldUncategorizedTransaction = const oldUncategorizedTransaction =
await UncategorizeCashflowTransaction.query() await UncategorizedCashflowTransaction.query()
.findById(bankTransactionId) .findById(uncategorizedTransactionId)
.throwIfNotFound(); .throwIfNotFound();
validateTransactionNotCategorized(oldUncategorizedTransaction); validateTransactionNotCategorized(oldUncategorizedTransaction);
return this.uow.withTransaction(tenantId, async (trx) => { return this.uow.withTransaction(tenantId, async (trx) => {
await UncategorizeCashflowTransaction.query(trx) await UncategorizedCashflowTransaction.query(trx)
.findById(bankTransactionId) .findById(uncategorizedTransactionId)
.patch({ .patch({
excluded: true, excluded: true,
}); });

View File

@@ -19,20 +19,20 @@ export class UnexcludeBankTransaction {
*/ */
public async unexcludeBankTransaction( public async unexcludeBankTransaction(
tenantId: number, tenantId: number,
bankTransactionId: number uncategorizedTransactionId: number
) { ) {
const { UncategorizeCashflowTransaction } = this.tenancy.models(tenantId); const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
const oldUncategorizedTransaction = const oldUncategorizedTransaction =
await UncategorizeCashflowTransaction.query() await UncategorizedCashflowTransaction.query()
.findById(bankTransactionId) .findById(uncategorizedTransactionId)
.throwIfNotFound(); .throwIfNotFound();
validateTransactionNotCategorized(oldUncategorizedTransaction); validateTransactionNotCategorized(oldUncategorizedTransaction);
return this.uow.withTransaction(tenantId, async (trx) => { return this.uow.withTransaction(tenantId, async (trx) => {
await UncategorizeCashflowTransaction.query(trx) await UncategorizedCashflowTransaction.query(trx)
.findById(bankTransactionId) .findById(uncategorizedTransactionId)
.patch({ .patch({
excluded: false, excluded: false,
}); });