mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
fix: sale invoice relation with customer.
This commit is contained in:
@@ -202,7 +202,7 @@ export default class SaleInvoicesController extends BaseController{
|
|||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const saleInvoice = await this.saleInvoiceService.getSaleInvoiceWithEntries(
|
const saleInvoice = await this.saleInvoiceService.getSaleInvoice(
|
||||||
tenantId, saleInvoiceId,
|
tenantId, saleInvoiceId,
|
||||||
);
|
);
|
||||||
return res.status(200).send({ sale_invoice: saleInvoice });
|
return res.status(200).send({ sale_invoice: saleInvoice });
|
||||||
@@ -255,7 +255,7 @@ export default class SaleInvoicesController extends BaseController{
|
|||||||
const filter: ISalesInvoicesFilter = {
|
const filter: ISalesInvoicesFilter = {
|
||||||
filterRoles: [],
|
filterRoles: [],
|
||||||
sortOrder: 'asc',
|
sortOrder: 'asc',
|
||||||
columnSortBy: 'name',
|
columnSortBy: 'created_at',
|
||||||
...this.matchedQueryData(req),
|
...this.matchedQueryData(req),
|
||||||
};
|
};
|
||||||
if (filter.stringifiedFilterRoles) {
|
if (filter.stringifiedFilterRoles) {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export default class SaleInvoice extends TenantModel {
|
|||||||
to: 'contacts.id',
|
to: 'contacts.id',
|
||||||
},
|
},
|
||||||
filter(query) {
|
filter(query) {
|
||||||
query.where('contact_type', 'Customer');
|
query.where('contact_service', 'Customer');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -301,13 +301,18 @@ export default class SaleInvoicesService extends SalesInvoicesCost {
|
|||||||
* @async
|
* @async
|
||||||
* @param {Number} saleInvoiceId
|
* @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);
|
const { SaleInvoice } = this.tenancy.models(tenantId);
|
||||||
return SaleInvoice.query()
|
|
||||||
.where('id', saleInvoiceId)
|
const saleInvoice = await SaleInvoice.query()
|
||||||
|
.findById(saleInvoiceId)
|
||||||
.withGraphFetched('entries')
|
.withGraphFetched('entries')
|
||||||
.withGraphFetched('customer')
|
.withGraphFetched('customer');
|
||||||
.first();
|
|
||||||
|
if (!saleInvoice) {
|
||||||
|
throw new ServiceError(ERRORS.SALE_INVOICE_NOT_FOUND);
|
||||||
|
}
|
||||||
|
return saleInvoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user