mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
refactor: split the services to multiple service classes (#202)
This commit is contained in:
32
packages/server/src/services/Purchases/Bills/GetDueBills.ts
Normal file
32
packages/server/src/services/Purchases/Bills/GetDueBills.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import UnitOfWork from '@/services/UnitOfWork';
|
||||
import { IBill } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export class GetDueBills {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Retrieve all due bills or for specific given vendor id.
|
||||
* @param {number} tenantId -
|
||||
* @param {number} vendorId -
|
||||
*/
|
||||
public async getDueBills(
|
||||
tenantId: number,
|
||||
vendorId?: number
|
||||
): Promise<IBill[]> {
|
||||
const { Bill } = this.tenancy.models(tenantId);
|
||||
|
||||
const dueBills = await Bill.query().onBuild((query) => {
|
||||
query.orderBy('bill_date', 'DESC');
|
||||
query.modify('dueBills');
|
||||
|
||||
if (vendorId) {
|
||||
query.where('vendor_id', vendorId);
|
||||
}
|
||||
});
|
||||
return dueBills;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user