mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { GetPendingBankAccountTransactionTransformer } from './GetPendingBankAccountTransactionTransformer';
|
|
import { UncategorizedBankTransaction } from '../models/UncategorizedBankTransaction';
|
|
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
|
|
|
@Injectable()
|
|
export class GetPendingBankAccountTransactions {
|
|
constructor(
|
|
private readonly transformerService: TransformerInjectable,
|
|
|
|
@Inject(UncategorizedBankTransaction.name)
|
|
private readonly uncategorizedBankTransactionModel: typeof UncategorizedBankTransaction
|
|
) {}
|
|
|
|
/**
|
|
* Retrieves the given bank accounts pending transaction.
|
|
* @param {GetPendingTransactionsQuery} filter - Pending transactions query.
|
|
*/
|
|
async getPendingTransactions(filter?: GetPendingTransactionsQuery) {
|
|
const _filter = {
|
|
page: 1,
|
|
pageSize: 20,
|
|
...filter,
|
|
};
|
|
const { results, pagination } =
|
|
await this.uncategorizedBankTransactionModel.query()
|
|
.onBuild((q) => {
|
|
q.modify('pending');
|
|
|
|
if (_filter?.accountId) {
|
|
q.where('accountId', _filter.accountId);
|
|
}
|
|
})
|
|
.pagination(_filter.page - 1, _filter.pageSize);
|
|
|
|
const data = await this.transformerService.transform(
|
|
results,
|
|
new GetPendingBankAccountTransactionTransformer()
|
|
);
|
|
return { data, pagination };
|
|
}
|
|
}
|
|
|
|
interface GetPendingTransactionsQuery {
|
|
page?: number;
|
|
pageSize?: number;
|
|
accountId?: number;
|
|
}
|