import { Inject, Service } from 'typedi'; import { ITransactionsByCustomersFilter, ITransactionsByCustomersTable } from '@/interfaces'; import { TransactionsByCustomersSheet } from './TransactionsByCustomersService'; import HasTenancyService from '@/services/Tenancy/TenancyService'; import { TransactionsByCustomersTable } from './TransactionsByCustomersTable'; @Service() export class TransactionsByCustomersTableInjectable { @Inject() private transactionsByCustomerService: TransactionsByCustomersSheet; @Inject() private tenancy: HasTenancyService; /** * Retrieves the transactions by customers sheet in table format. * @param {number} tenantId * @param {ITransactionsByCustomersFilter} filter * @returns {Promise} */ public async table( tenantId: number, filter: ITransactionsByCustomersFilter ): Promise { const i18n = this.tenancy.i18n(tenantId); const customersTransactions = await this.transactionsByCustomerService.transactionsByCustomers( tenantId, filter ); const table = new TransactionsByCustomersTable( customersTransactions.data, i18n ); return { table: { rows: table.tableRows(), columns: table.tableColumns(), }, query: customersTransactions.query, }; } }