feat: universal search.

This commit is contained in:
a.bouhuolia
2021-08-21 18:59:49 +02:00
parent a7b0f1a8d2
commit 79c1b2ab67
82 changed files with 2497 additions and 317 deletions

View File

@@ -19,14 +19,16 @@ export default class VendorsController extends ContactsController {
router() {
const router = Router();
router.post('/', [
...this.contactDTOSchema,
...this.contactNewDTOSchema,
...this.vendorDTOSchema,
],
router.post(
'/',
[
...this.contactDTOSchema,
...this.contactNewDTOSchema,
...this.vendorDTOSchema,
],
this.validationResult,
asyncMiddleware(this.newVendor.bind(this)),
this.handlerServiceErrors,
this.handlerServiceErrors
);
router.post(
'/:id/opening_balance',
@@ -37,36 +39,38 @@ export default class VendorsController extends ContactsController {
],
this.validationResult,
asyncMiddleware(this.editOpeningBalanceVendor.bind(this)),
this.handlerServiceErrors,
this.handlerServiceErrors
);
router.post('/:id', [
...this.contactDTOSchema,
...this.contactEditDTOSchema,
...this.vendorDTOSchema,
],
router.post(
'/:id',
[
...this.contactDTOSchema,
...this.contactEditDTOSchema,
...this.vendorDTOSchema,
],
this.validationResult,
asyncMiddleware(this.editVendor.bind(this)),
this.handlerServiceErrors,
this.handlerServiceErrors
);
router.delete('/:id', [
...this.specificContactSchema,
],
router.delete(
'/:id',
[...this.specificContactSchema],
this.validationResult,
asyncMiddleware(this.deleteVendor.bind(this)),
this.handlerServiceErrors,
this.handlerServiceErrors
);
router.get('/:id', [
...this.specificContactSchema,
],
router.get(
'/:id',
[...this.specificContactSchema],
this.validationResult,
asyncMiddleware(this.getVendor.bind(this)),
this.handlerServiceErrors,
this.handlerServiceErrors
);
router.get('/', [
...this.vendorsListSchema,
],
router.get(
'/',
[...this.vendorsListSchema],
this.validationResult,
asyncMiddleware(this.getVendorsList.bind(this)),
asyncMiddleware(this.getVendorsList.bind(this))
);
return router;
}
@@ -102,22 +106,26 @@ export default class VendorsController extends ContactsController {
query('page_size').optional().isNumeric().toInt(),
query('inactive_mode').optional().isBoolean().toBoolean(),
query('search_keyword').optional({ nullable: true }).isString().trim()
query('search_keyword').optional({ nullable: true }).isString().trim(),
];
}
/**
* Creates a new vendor.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async newVendor(req: Request, res: Response, next: NextFunction) {
const contactDTO: IVendorNewDTO = this.matchedBodyData(req);
const { tenantId, user } = req;
try {
const vendor = await this.vendorsService.newVendor(tenantId, contactDTO, user);
const vendor = await this.vendorsService.newVendor(
tenantId,
contactDTO,
user
);
return res.status(200).send({
id: vendor.id,
@@ -130,9 +138,9 @@ export default class VendorsController extends ContactsController {
/**
* Edits the given vendor details.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async editVendor(req: Request, res: Response, next: NextFunction) {
const contactDTO: IVendorEditDTO = this.matchedBodyData(req);
@@ -140,7 +148,12 @@ export default class VendorsController extends ContactsController {
const { id: contactId } = req.params;
try {
await this.vendorsService.editVendor(tenantId, contactId, contactDTO, user);
await this.vendorsService.editVendor(
tenantId,
contactId,
contactDTO,
user
);
return res.status(200).send({
id: contactId,
@@ -157,24 +170,26 @@ export default class VendorsController extends ContactsController {
* @param {Response} res -
* @param {NextFunction} next -
*/
async editOpeningBalanceVendor(req: Request, res: Response, next: NextFunction) {
async editOpeningBalanceVendor(
req: Request,
res: Response,
next: NextFunction
) {
const { tenantId, user } = req;
const { id: vendorId } = req.params;
const {
openingBalance,
openingBalanceAt,
} = this.matchedBodyData(req);
const { openingBalance, openingBalanceAt } = this.matchedBodyData(req);
try {
await this.vendorsService.changeOpeningBalance(
tenantId,
vendorId,
openingBalance,
openingBalanceAt,
openingBalanceAt
);
return res.status(200).send({
id: vendorId,
message: 'The opening balance of the given vendor has been changed successfully.',
message:
'The opening balance of the given vendor has been changed successfully.',
});
} catch (error) {
next(error);
@@ -183,16 +198,16 @@ export default class VendorsController extends ContactsController {
/**
* Deletes the given vendor from the storage.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async deleteVendor(req: Request, res: Response, next: NextFunction) {
const { tenantId, user } = req;
const { id: contactId } = req.params;
try {
await this.vendorsService.deleteVendor(tenantId, contactId, user)
await this.vendorsService.deleteVendor(tenantId, contactId, user);
return res.status(200).send({
id: contactId,
@@ -205,18 +220,21 @@ export default class VendorsController extends ContactsController {
/**
* Retrieve details of the given vendor id.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async getVendor(req: Request, res: Response, next: NextFunction) {
const { tenantId, user } = req;
const { id: vendorId } = req.params;
try {
const vendor = await this.vendorsService.getVendor(tenantId, vendorId, user)
return res.status(200).send({ vendor });
const vendor = await this.vendorsService.getVendor(
tenantId,
vendorId,
user
);
return res.status(200).send(this.transfromToResponse({ vendor }));
} catch (error) {
next(error);
}
@@ -224,9 +242,9 @@ export default class VendorsController extends ContactsController {
/**
* Retrieve vendors datatable list.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async getVendorsList(req: Request, res: Response, next: NextFunction) {
const { tenantId } = req;
@@ -241,14 +259,11 @@ export default class VendorsController extends ContactsController {
};
try {
const {
vendors,
pagination,
filterMeta,
} = await this.vendorsService.getVendorsList(tenantId, vendorsFilter);
const { vendors, pagination, filterMeta } =
await this.vendorsService.getVendorsList(tenantId, vendorsFilter);
return res.status(200).send({
vendors,
vendors: this.transfromToResponse(vendors),
pagination: this.transfromToResponse(pagination),
filter_meta: this.transfromToResponse(filterMeta),
});
@@ -259,7 +274,7 @@ export default class VendorsController extends ContactsController {
/**
* Handle service errors.
* @param {Error} error -
* @param {Error} error -
* @param {Request} req -
* @param {Response} res -
* @param {NextFunction} next -
@@ -289,4 +304,4 @@ export default class VendorsController extends ContactsController {
}
next(error);
}
}
}

View File

@@ -8,6 +8,7 @@ import { IExpenseDTO } from 'interfaces';
import { ServiceError } from 'exceptions';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import { DATATYPES_LENGTH } from 'data/DataTypes';
import HasItemEntries from 'services/Sales/HasItemsEntries';
@Service()
export default class ExpensesController extends BaseController {
@@ -304,7 +305,7 @@ export default class ExpensesController extends BaseController {
await this.expensesService.getExpensesList(tenantId, filter);
return res.status(200).send({
expenses,
expenses: this.transfromToResponse(expenses),
pagination: this.transfromToResponse(pagination),
filter_meta: this.transfromToResponse(filterMeta),
});
@@ -328,7 +329,7 @@ export default class ExpensesController extends BaseController {
tenantId,
expenseId
);
return res.status(200).send({ expense });
return res.status(200).send(this.transfromToResponse({ expense }));
} catch (error) {
next(error);
}

View File

@@ -173,7 +173,7 @@ export default class ItemsController extends BaseController {
}
/**
* Validate list query schema
* Validate list query schema.
*/
get validateListQuerySchema() {
return [

View File

@@ -221,7 +221,7 @@ export default class ManualJournalsController extends BaseController {
manualJournalId
);
return res.status(200).send({
manual_journal: manualJournal,
manual_journal: this.transfromToResponse(manualJournal),
});
} catch (error) {
next(error);
@@ -301,7 +301,7 @@ export default class ManualJournalsController extends BaseController {
} = await this.manualJournalsService.getManualJournals(tenantId, filter);
return res.status(200).send({
manual_journals: manualJournals,
manual_journals: this.transfromToResponse(manualJournals),
pagination: this.transfromToResponse(pagination),
filter_meta: this.transfromToResponse(filterMeta),
});

View File

@@ -264,7 +264,7 @@ export default class BillsController extends BaseController {
try {
const bill = await this.billsService.getBill(tenantId, billId);
return res.status(200).send({ bill });
return res.status(200).send(this.transfromToResponse({ bill }));
} catch (error) {
next(error);
}
@@ -312,7 +312,7 @@ export default class BillsController extends BaseController {
await this.billsService.getBills(tenantId, filter);
return res.status(200).send({
bills,
bills: this.transfromToResponse(bills),
pagination: this.transfromToResponse(pagination),
filter_meta: this.transfromToResponse(filterMeta),
});

View File

@@ -335,7 +335,7 @@ export default class BillsPayments extends BaseController {
);
return res.status(200).send({
bill_payments: billPayments,
bill_payments: this.transfromToResponse(billPayments),
pagination: this.transfromToResponse(pagination),
filter_meta: this.transfromToResponse(filterMeta),
});

View File

@@ -302,6 +302,10 @@ export default class SalesEstimatesController extends BaseController {
);
// Response formatter.
res.format({
// JSON content type.
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
return res.status(200).send(this.transfromToResponse({ estimate }));
},
// PDF content type.
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
const pdfContent = await this.saleEstimatesPdf.saleEstimatePdf(
@@ -314,10 +318,6 @@ export default class SalesEstimatesController extends BaseController {
});
res.send(pdfContent);
},
// JSON content type.
default: () => {
return res.status(200).send(this.transfromToResponse({ estimate }));
},
});
} catch (error) {
next(error);

View File

@@ -277,6 +277,10 @@ export default class SaleInvoicesController extends BaseController {
);
// Response formatter.
res.format({
// JSON content type.
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
return res.status(200).send(this.transfromToResponse({ saleInvoice }));
},
// PDF content type.
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
const pdfContent = await this.saleInvoicePdf.saleInvoicePdf(
@@ -289,10 +293,6 @@ export default class SaleInvoicesController extends BaseController {
});
res.send(pdfContent);
},
// JSON content type.
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
return res.status(200).send(this.transfromToResponse({ saleInvoice }));
},
});
} catch (error) {
next(error);

View File

@@ -243,11 +243,13 @@ export default class SalesReceiptsController extends BaseController {
};
try {
const { salesReceipts, pagination, filterMeta } =
const { data, pagination, filterMeta } =
await this.saleReceiptService.salesReceiptsList(tenantId, filter);
const response = this.transfromToResponse({
salesReceipts, pagination, filterMeta
data,
pagination,
filterMeta,
});
return res.status(200).send(response);
} catch (error) {
@@ -272,6 +274,11 @@ export default class SalesReceiptsController extends BaseController {
);
res.format({
'application/json': () => {
return res
.status(200)
.send(this.transfromToResponse({ saleReceipt }));
},
'application/pdf': async () => {
const pdfContent = await this.saleReceiptsPdf.saleReceiptPdf(
tenantId,
@@ -283,10 +290,7 @@ export default class SalesReceiptsController extends BaseController {
});
res.send(pdfContent);
},
'application/json': () => {
return res.status(200).send(this.transfromToResponse({ saleReceipt }));
}
})
});
} catch (error) {
next(error);
}

View File

@@ -0,0 +1,28 @@
import { Service } from 'typedi';
import { IAccount } from 'interfaces';
import { Transformer } from 'lib/Transformer/Transformer';
import { formatNumber } from 'utils';
@Service()
export default class AccountTransformer extends Transformer {
/**
* Include these attributes to sale invoice object.
* @returns {Array}
*/
protected includeAttributes = (): string[] => {
return [
'formattedAmount',
];
};
/**
* Retrieve formatted account amount.
* @param {IAccount} invoice
* @returns {string}
*/
protected formattedAmount = (account: IAccount): string => {
return formatNumber(account.amount, {
currencyCode: account.currencyCode,
});
};
}

View File

@@ -23,6 +23,7 @@ import AccountTypesUtils from 'lib/AccountTypes';
import { ERRORS } from './constants';
import { flatToNestedArray } from 'utils';
import I18nService from 'services/I18n/I18nService';
import AccountTransformer from './AccountTransform';
@Service()
export default class AccountsService {
@@ -41,6 +42,9 @@ export default class AccountsService {
@Inject()
i18nService: I18nService;
@Inject()
accountTransformer: AccountTransformer;
/**
* Retrieve account type or throws service error.
* @param {number} tenantId -
@@ -326,7 +330,10 @@ export default class AccountsService {
*/
public async getAccount(tenantId: number, accountId: number) {
const account = await this.getAccountOrThrowError(tenantId, accountId);
return this.transformAccountResponse(tenantId, account);
return this.accountTransformer.transform(
this.transformAccountResponse(tenantId, account)
);
}
/**
@@ -609,13 +616,11 @@ export default class AccountsService {
/**
* Parsees accounts list filter DTO.
* @param filterDTO
* @returns
* @param filterDTO
* @returns
*/
private parseListFilterDTO(filterDTO) {
return R.compose(
this.dynamicListService.parseStringifiedFilter
)(filterDTO);
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
}
/**
@@ -735,10 +740,12 @@ export default class AccountsService {
key: 'base_currency',
});
const _accounts = accounts.map((account) => ({
...account.toJSON(),
currencyCode: baseCurrency,
}));
const _accounts = this.accountTransformer.transform(
accounts.map((account) => ({
...account.toJSON(),
currencyCode: baseCurrency,
}))
);
return flatToNestedArray(
this.i18nService.i18nMapper(_accounts, ['account_type_label'], tenantId),
{

View File

@@ -0,0 +1,43 @@
import { Service, Container } from 'typedi';
import { isNull } from 'lodash';
import { Transformer } from 'lib/Transformer/Transformer';
import { formatNumber } from 'utils';
import { IContact } from 'interfaces';
@Service()
export default class ContactTransfromer extends Transformer {
/**
* Retrieve formatted expense amount.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedBalance = (contact: IContact): string => {
return formatNumber(contact.balance, {
currencyCode: contact.currencyCode,
});
};
/**
* Retrieve formatted expense landed cost amount.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedOpeningBalance = (contact: IContact): string => {
return !isNull(contact.openingBalance)
? formatNumber(contact.openingBalance, {
currencyCode: contact.currencyCode,
})
: '';
};
/**
* Retriecve fromatted date.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedOpeningBalanceAt = (contact: IContact): string => {
return !isNull(contact.openingBalanceAt)
? this.formatDate(contact.openingBalanceAt)
: '';
};
}

View File

@@ -0,0 +1,17 @@
import { Service } from 'typedi';
import ContactTransfromer from '../ContactTransformer';
@Service()
export default class CustomerTransfromer extends ContactTransfromer {
/**
* Include these attributes to expense object.
* @returns {Array}
*/
protected includeAttributes = (): string[] => {
return [
'formattedBalance',
'formattedOpeningBalance',
'formattedOpeningBalanceAt'
];
};
}

View File

@@ -28,6 +28,7 @@ import { ServiceError } from 'exceptions';
import TenancyService from 'services/Tenancy/TenancyService';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import events from 'subscribers/events';
import CustomerTransfromer from './Customers/CustomerTransformer';
const ERRORS = {
CUSTOMER_HAS_TRANSACTIONS: 'CUSTOMER_HAS_TRANSACTIONS',
@@ -61,6 +62,9 @@ export default class CustomersService {
@Inject('SalesEstimates')
estimatesService: ISalesEstimatesService;
@Inject()
customerTransformer: CustomerTransfromer;
/**
* Converts customer to contact DTO.
* @param {ICustomerNewDTO|ICustomerEditDTO} customerDTO
@@ -262,7 +266,10 @@ export default class CustomersService {
customerId,
'customer'
);
return this.transformContactToCustomer(contact);
return R.compose(
this.customerTransformer.transform,
this.transformContactToCustomer,
)(contact);
}
/**

View File

@@ -0,0 +1,17 @@
import { Service } from 'typedi';
import ContactTransfromer from '../ContactTransformer';
@Service()
export default class VendorTransfromer extends ContactTransfromer {
/**
* Include these attributes to expense object.
* @returns {Array}
*/
protected includeAttributes = (): string[] => {
return [
'formattedBalance',
'formattedOpeningBalance',
'formattedOpeningBalanceAt'
];
};
}

View File

@@ -23,6 +23,7 @@ import { ServiceError } from 'exceptions';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import TenancyService from 'services/Tenancy/TenancyService';
import events from 'subscribers/events';
import VendorTransfromer from './Vendors/VendorTransformer';
const ERRORS = {
VENDOR_HAS_TRANSACTIONS: 'VENDOR_HAS_TRANSACTIONS',
@@ -51,6 +52,9 @@ export default class VendorsService {
@Inject('BillPayments')
billPaymentsService: IBillPaymentsService;
@Inject()
vendorTransformer: VendorTransfromer;
/**
* Converts vendor to contact DTO.
* @param {IVendorNewDTO|IVendorEditDTO} vendorDTO
@@ -139,8 +143,8 @@ export default class VendorsService {
/**
* Validate the given vendor has no associated transactions.
* @param {number} tenantId
* @param {number} vendorId
* @param {number} tenantId
* @param {number} vendorId
*/
private async validateAssociatedTransactions(
tenantId: number,
@@ -151,8 +155,10 @@ export default class VendorsService {
await this.billsService.validateVendorHasNoBills(tenantId, vendorId);
// Validate vendor has no paymentys.
await this.billPaymentsService.validateVendorHasNoPayments(tenantId, vendorId);
await this.billPaymentsService.validateVendorHasNoPayments(
tenantId,
vendorId
);
} catch (error) {
throw new ServiceError(ERRORS.VENDOR_HAS_TRANSACTIONS);
}
@@ -196,7 +202,9 @@ export default class VendorsService {
* @param {number} vendorId
*/
public async getVendor(tenantId: number, vendorId: number) {
return this.contactService.getContact(tenantId, vendorId, 'vendor');
const vendor = this.contactService.getContact(tenantId, vendorId, 'vendor');
return this.vendorTransformer.transform(vendor);
}
/**
@@ -257,9 +265,7 @@ export default class VendorsService {
}
private parseVendorsListFilterDTO(filterDTO) {
return R.compose(
this.dynamicListService.parseStringifiedFilter
)(filterDTO);
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
}
/**
@@ -297,7 +303,7 @@ export default class VendorsService {
.pagination(filter.page - 1, filter.pageSize);
return {
vendors: results,
vendors: this.vendorTransformer.transform(results),
pagination,
filterMeta: dynamicList.getResponseMeta(),
};

View File

@@ -0,0 +1,62 @@
import { Service, Container } from 'typedi';
import { Transformer } from 'lib/Transformer/Transformer';
import { formatNumber } from 'utils';
import { IExpense } from 'interfaces';
@Service()
export default class ExpenseTransfromer extends Transformer {
/**
* Include these attributes to expense object.
* @returns {Array}
*/
protected includeAttributes = (): string[] => {
return [
'formattedAmount',
'formattedLandedCostAmount',
'formattedAllocatedCostAmount',
'formattedDate'
];
};
/**
* Retrieve formatted expense amount.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedAmount = (expense: IExpense): string => {
return formatNumber(expense.totalAmount, {
currencyCode: expense.currencyCode,
});
};
/**
* Retrieve formatted expense landed cost amount.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedLandedCostAmount = (expense: IExpense): string => {
return formatNumber(expense.landedCostAmount, {
currencyCode: expense.currencyCode,
});
};
/**
* Retrieve formatted allocated cost amount.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedAllocatedCostAmount = (expense: IExpense): string => {
return formatNumber(expense.allocatedCostAmount, {
currencyCode: expense.currencyCode,
});
};
/**
* Retriecve fromatted date.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedDate = (expense: IExpense): string => {
return this.formatDate(expense.paymentDate);
}
}

View File

@@ -25,6 +25,7 @@ import events from 'subscribers/events';
import ContactsService from 'services/Contacts/ContactsService';
import { ACCOUNT_PARENT_TYPE, ACCOUNT_ROOT_TYPE } from 'data/AccountTypes';
import EntriesService from 'services/Entries';
import ExpenseTransfromer from './ExpenseTransformer';
const ERRORS = {
EXPENSE_NOT_FOUND: 'expense_not_found',
@@ -58,6 +59,9 @@ export default class ExpensesService implements IExpensesService {
@Inject()
entriesService: EntriesService;
@Inject()
expenseTransfromer: ExpenseTransfromer;
/**
* Retrieve the payment account details or returns not found server error in case the
* given account not found on the storage.
@@ -681,7 +685,7 @@ export default class ExpensesService implements IExpensesService {
.pagination(filter.page - 1, filter.pageSize);
return {
expenses: results,
expenses: this.expenseTransfromer.transform(results),
pagination,
filterMeta: dynamicList.getResponseMeta(),
};
@@ -706,7 +710,7 @@ export default class ExpensesService implements IExpensesService {
if (!expense) {
throw new ServiceError(ERRORS.EXPENSE_NOT_FOUND);
}
return expense;
return this.expenseTransfromer.transform(expense);
}
/**

View File

@@ -0,0 +1,44 @@
import { IManualJournal } from 'interfaces';
import { Transformer } from 'lib/Transformer/Transformer';
import { Service } from 'typedi';
import { formatNumber } from 'utils';
@Service()
export default class ManualJournalTransfromer extends Transformer {
/**
* Include these attributes to expense object.
* @returns {Array}
*/
protected includeAttributes = (): string[] => {
return ['formattedAmount', 'formattedDate', 'formattedPublishedAt'];
};
/**
* Retrieve formatted journal amount.
* @param {IManualJournal} manualJournal
* @returns {string}
*/
protected formattedAmount = (manualJorunal: IManualJournal): string => {
return formatNumber(manualJorunal.amount, {
currencyCode: manualJorunal.currencyCode,
});
};
/**
* Retrieve formatted date.
* @param {IManualJournal} manualJournal
* @returns {string}
*/
protected formattedDate = (manualJorunal: IManualJournal): string => {
return this.formatDate(manualJorunal.date);
};
/**
* Retrieve formatted published at date.
* @param {IManualJournal} manualJournal
* @returns {string}
*/
protected formattedPublishedAt = (manualJorunal: IManualJournal): string => {
return this.formatDate(manualJorunal.publishedAt);
};
}

View File

@@ -24,6 +24,7 @@ import JournalCommands from 'services/Accounting/JournalCommands';
import JournalPosterService from 'services/Sales/JournalPosterService';
import AutoIncrementOrdersService from 'services/Sales/AutoIncrementOrdersService';
import { ERRORS } from './constants';
import ManualJournalTransfromer from './ManualJournalTransformer';
@Service()
export default class ManualJournalsService implements IManualJournalsService {
@@ -45,6 +46,9 @@ export default class ManualJournalsService implements IManualJournalsService {
@Inject()
autoIncrementOrdersService: AutoIncrementOrdersService;
@Inject()
manualJournalTransformer: ManualJournalTransfromer;
/**
* Validates the manual journal existance.
* @param {number} tenantId
@@ -815,7 +819,7 @@ export default class ManualJournalsService implements IManualJournalsService {
.pagination(filter.page - 1, filter.pageSize);
return {
manualJournals: results,
manualJournals: this.manualJournalTransformer.transform(results),
pagination,
filterMeta: dynamicService.getResponseMeta(),
};
@@ -842,7 +846,7 @@ export default class ManualJournalsService implements IManualJournalsService {
.withGraphFetched('transactions')
.withGraphFetched('media');
return manualJournal;
return this.manualJournalTransformer.transform(manualJournal);
}
/**

View File

@@ -10,10 +10,7 @@ export default class PaymentReceiveTransfromer extends Transformer {
* @returns {Array}
*/
protected includeAttributes = (): string[] => {
return [
'formattedPaymentDate',
'formattedAmount',
];
return ['formattedPaymentDate', 'formattedAmount'];
};
/**

View File

@@ -421,7 +421,7 @@ export default class SalesReceiptService implements ISalesReceiptsService {
tenantId: number,
filterDTO: ISaleReceiptFilter
): Promise<{
salesReceipts: ISaleReceipt[];
data: ISaleReceipt[];
pagination: IPaginationMeta;
filterMeta: IFilterMeta;
}> {
@@ -451,7 +451,7 @@ export default class SalesReceiptService implements ISalesReceiptsService {
.pagination(filter.page - 1, filter.pageSize);
return {
salesReceipts: this.saleReceiptTransformer.transform(results),
data: this.saleReceiptTransformer.transform(results),
pagination,
filterMeta: dynamicFilter.getResponseMeta(),
};