mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
feat: licenses administration basic authentication.
feat: accounts slug. feat: duplicate accounts_balance table and merge balance with accounts table. feat: refactoring customers and vendors. feat: system user soft deleting. feat: preventing build tenant database without any subscription. feat: remove 'password' property from 'req.user' object. feat: refactoring JournalPoster class. feat: delete duplicated directories and files.
This commit is contained in:
71
server/src/repositories/CustomerRepository.ts
Normal file
71
server/src/repositories/CustomerRepository.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import TenantRepository from "./TenantRepository";
|
||||
|
||||
export default class CustomerRepository extends TenantRepository {
|
||||
models: any;
|
||||
cache: any;
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {number} tenantId
|
||||
*/
|
||||
constructor(tenantId: number) {
|
||||
super(tenantId);
|
||||
|
||||
this.models = this.tenancy.models(tenantId);
|
||||
this.cache = this.tenancy.cache(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve customer details of the given id.
|
||||
* @param {number} customerId -
|
||||
*/
|
||||
getById(customerId: number) {
|
||||
const { Contact } = this.models;
|
||||
|
||||
return this.cache.get(`customers.id.${customerId}`, () => {
|
||||
return Contact.query().modifier('customer').findById(customerId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines the given customer exists.
|
||||
* @param {number} customerId
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isExists(customerId: number) {
|
||||
return !!this.getById(customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the sales invoices that assocaited to the given customer.
|
||||
* @param {number} customerId
|
||||
*/
|
||||
getSalesInvoices(customerId: number) {
|
||||
const { SaleInvoice } = this.models;
|
||||
|
||||
return this.cache.get(`customers.invoices.${customerId}`, () => {
|
||||
return SaleInvoice.query().where('customer_id', customerId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve customers details of the given ids.
|
||||
* @param {number[]} customersIds - Customers ids.
|
||||
* @return {IContact[]}
|
||||
*/
|
||||
customers(customersIds: number[]) {
|
||||
const { Contact } = this.models;
|
||||
return Contact.query().modifier('customer').whereIn('id', customersIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve customers of the given ids with associated sales invoices.
|
||||
* @param {number[]} customersIds - Customers ids.
|
||||
*/
|
||||
customersWithSalesInvoices(customersIds: number[]) {
|
||||
const { Contact } = this.models;
|
||||
return Contact.query().modify('customer')
|
||||
.whereIn('id', customersIds)
|
||||
.withGraphFetched('salesInvoices');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user