mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
fix: transactions by reference report.
This commit is contained in:
@@ -3,7 +3,7 @@ import { Router, Request, Response, NextFunction } from 'express';
|
||||
import { query, ValidationChain } from 'express-validator';
|
||||
import BaseController from 'api/controllers/BaseController';
|
||||
import TransactionsByReferenceService from 'services/FinancialStatements/TransactionsByReference';
|
||||
|
||||
import { ITransactionsByReferenceTransaction } from 'interfaces';
|
||||
@Service()
|
||||
export default class TransactionsByReferenceController extends BaseController {
|
||||
@Inject()
|
||||
@@ -61,27 +61,30 @@ export default class TransactionsByReferenceController extends BaseController {
|
||||
const filter = this.matchedQueryData(req);
|
||||
|
||||
try {
|
||||
const transactions =
|
||||
const data =
|
||||
await this.transactionsByReferenceService.getTransactionsByReference(
|
||||
tenantId,
|
||||
filter
|
||||
);
|
||||
const accept = this.accepts(req);
|
||||
const acceptType = accept.types(['json']);
|
||||
|
||||
switch (acceptType) {
|
||||
case 'json':
|
||||
default:
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToJsonResponse(transactions));
|
||||
}
|
||||
return res
|
||||
.status(200)
|
||||
.send(this.transformToJsonResponse(data.transactions));
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
private transformToJsonResponse(transactions) {
|
||||
return transactions;
|
||||
/**
|
||||
* Transformes the given report transaction to json response.
|
||||
* @param transactions
|
||||
* @returns
|
||||
*/
|
||||
private transformToJsonResponse(
|
||||
transactions: ITransactionsByReferenceTransaction[]
|
||||
) {
|
||||
return {
|
||||
transactions: this.transfromToResponse(transactions),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ export default class TransactionsByReference extends FinancialSheet {
|
||||
transaction: IAccountTransaction
|
||||
): ITransactionsByReferenceTransaction => {
|
||||
return {
|
||||
date: this.getDateMeta(transaction.date),
|
||||
|
||||
credit: this.getAmountMeta(transaction.credit, { money: true }),
|
||||
debit: this.getAmountMeta(transaction.debit, { money: true }),
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export default class TransactionsByReferenceService {
|
||||
tenantId: number,
|
||||
query: ITransactionsByReferenceQuery
|
||||
): Promise<{
|
||||
data: ITransactionsByReferenceTransaction[];
|
||||
transactions: ITransactionsByReferenceTransaction[];
|
||||
}> {
|
||||
const filter = {
|
||||
...this.defaultQuery,
|
||||
@@ -71,7 +71,7 @@ export default class TransactionsByReferenceService {
|
||||
);
|
||||
|
||||
return {
|
||||
data: report.reportData(),
|
||||
transactions: report.reportData(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user