fix: sale invoice relation with customer.

This commit is contained in:
Ahmed Bouhuolia
2020-10-26 16:45:49 +02:00
parent dea6cdd245
commit 7558f68fa0
3 changed files with 13 additions and 8 deletions

View File

@@ -202,7 +202,7 @@ export default class SaleInvoicesController extends BaseController{
const { tenantId } = req;
try {
const saleInvoice = await this.saleInvoiceService.getSaleInvoiceWithEntries(
const saleInvoice = await this.saleInvoiceService.getSaleInvoice(
tenantId, saleInvoiceId,
);
return res.status(200).send({ sale_invoice: saleInvoice });
@@ -255,7 +255,7 @@ export default class SaleInvoicesController extends BaseController{
const filter: ISalesInvoicesFilter = {
filterRoles: [],
sortOrder: 'asc',
columnSortBy: 'name',
columnSortBy: 'created_at',
...this.matchedQueryData(req),
};
if (filter.stringifiedFilterRoles) {

View File

@@ -85,7 +85,7 @@ export default class SaleInvoice extends TenantModel {
to: 'contacts.id',
},
filter(query) {
query.where('contact_type', 'Customer');
query.where('contact_service', 'Customer');
}
},

View File

@@ -301,13 +301,18 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
* @async
* @param {Number} saleInvoiceId
*/
public async getSaleInvoiceWithEntries(tenantId: number, saleInvoiceId: number) {
public async getSaleInvoice(tenantId: number, saleInvoiceId: number): Promise<ISaleInvoice> {
const { SaleInvoice } = this.tenancy.models(tenantId);
return SaleInvoice.query()
.where('id', saleInvoiceId)
const saleInvoice = await SaleInvoice.query()
.findById(saleInvoiceId)
.withGraphFetched('entries')
.withGraphFetched('customer')
.first();
.withGraphFetched('customer');
if (!saleInvoice) {
throw new ServiceError(ERRORS.SALE_INVOICE_NOT_FOUND);
}
return saleInvoice;
}
/**