feat: wip attach attachments to resource models

This commit is contained in:
Ahmed Bouhuolia
2024-05-26 21:59:39 +02:00
parent 15dbc4137c
commit 2244cc6116
64 changed files with 2052 additions and 54 deletions

View File

@@ -123,6 +123,7 @@ export class CreateExpense {
tenantId,
expenseId: expense.id,
authorizedUser,
expenseDTO,
expense,
trx,
} as IExpenseCreatedPayload);

View File

@@ -54,7 +54,7 @@ export class ExpenseDTOTransformer {
const initialDTO = {
categories: [],
...omit(expenseDTO, ['publish']),
...omit(expenseDTO, ['publish', 'attachments']),
totalAmount,
landedCostAmount,
paymentDate: moment(expenseDTO.paymentDate).toMySqlDateTime(),

View File

@@ -2,6 +2,7 @@ import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from 'utils';
import { IExpense } from '@/interfaces';
import { ExpenseCategoryTransformer } from './ExpenseCategoryTransformer';
import { AttachmentTransformer } from '@/services/Attachments/AttachmentTransformer';
export class ExpenseTransfromer extends Transformer {
/**
@@ -15,6 +16,7 @@ export class ExpenseTransfromer extends Transformer {
'formattedAllocatedCostAmount',
'formattedDate',
'categories',
'attachments',
];
};
@@ -70,4 +72,13 @@ export class ExpenseTransfromer extends Transformer {
currencyCode: expense.currencyCode,
});
};
/**
* Retrieves the sale invoice attachments.
* @param {ISaleInvoice} invoice
* @returns
*/
protected attachments = (expense: IExpense) => {
return this.item(expense.attachments, new AttachmentTransformer());
};
}

View File

@@ -29,6 +29,7 @@ export class GetExpense {
.withGraphFetched('categories.expenseAccount')
.withGraphFetched('paymentAccount')
.withGraphFetched('branch')
.withGraphFetched('attachments')
.throwIfNotFound();
// Transformes expense model to POJO.