refactor: expense GL to Nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-30 22:08:50 +02:00
parent 3191076762
commit 4938db704e
20 changed files with 1344 additions and 274 deletions

View File

@@ -1,42 +1,44 @@
// import { Knex } from 'knex';
// import { ExpenseGL } from './ExpenseGL';
// import { Inject, Injectable } from '@nestjs/common';
// import { Expense } from '../models/Expense.model';
import { Knex } from 'knex';
import { ExpenseGL } from './ExpenseGL';
import { Inject, Injectable } from '@nestjs/common';
import { Expense } from '../models/Expense.model';
import { ILedger } from '@/modules/Ledger/types/Ledger.types';
// @Injectable()
// export class ExpenseGLEntries {
// constructor(
// @Inject(Expense.name)
// private readonly expense: typeof Expense,
// ) {}
// /**
// * Retrieves the expense G/L of the given id.
// * @param {number} expenseId
// * @param {Knex.Transaction} trx
// * @returns {Promise<ILedger>}
// */
// public getExpenseLedgerById = async (
// expenseId: number,
// trx?: Knex.Transaction,
// ): Promise<ILedger> => {
// const expense = await this.expense
// .query(trx)
// .findById(expenseId)
// .withGraphFetched('categories')
// .withGraphFetched('paymentAccount')
// .throwIfNotFound();
@Injectable()
export class ExpenseGLEntriesService {
constructor(
@Inject(Expense.name)
private readonly expense: typeof Expense,
) {}
// return this.getExpenseLedger(expense);
// };
/**
* Retrieves the expense G/L of the given id.
* @param {number} expenseId
* @param {Knex.Transaction} trx
* @returns {Promise<ILedger>}
*/
public getExpenseLedgerById = async (
expenseId: number,
trx?: Knex.Transaction,
): Promise<ILedger> => {
const expense = await this.expense
.query(trx)
.findById(expenseId)
.withGraphFetched('categories')
.withGraphFetched('paymentAccount')
.throwIfNotFound();
// /**
// * Retrieves the given expense ledger.
// * @param {IExpense} expense
// * @returns {ILedger}
// */
// public getExpenseLedger = (expense: Expense): ILedger => {
// const expenseGL = new ExpenseGL(expense);
return this.getExpenseLedger(expense);
};
// return expenseGL.getExpenseLedger();
// };
// }
/**
* Retrieves the given expense ledger.
* @param {IExpense} expense
* @returns {ILedger}
*/
public getExpenseLedger = (expense: Expense): ILedger => {
const expenseGL = new ExpenseGL(expense);
return expenseGL.getExpenseLedger();
};
}