Files
bigcapital/packages/server/src/services/ManualJournals/GetManualJournal.ts
Josh Soref b6d8766173 spelling: associate
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-06-27 09:34:47 -04:00

41 lines
1.1 KiB
TypeScript

import { Service, Inject } from 'typedi';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { ManualJournalTransfromer } from './ManualJournalTransformer';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
@Service()
export class GetManualJournal {
@Inject()
private tenancy: HasTenancyService;
@Inject()
private transformer: TransformerInjectable;
/**
* Retrieve manual journal details with associated journal transactions.
* @param {number} tenantId
* @param {number} manualJournalId
*/
public getManualJournal = async (
tenantId: number,
manualJournalId: number
) => {
const { ManualJournal } = this.tenancy.models(tenantId);
const manualJournal = await ManualJournal.query()
.findById(manualJournalId)
.withGraphFetched('entries.account')
.withGraphFetched('entries.contact')
.withGraphFetched('entries.branch')
.withGraphFetched('transactions')
.withGraphFetched('media')
.throwIfNotFound();
return this.transformer.transform(
tenantId,
manualJournal,
new ManualJournalTransfromer()
);
};
}