mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
refactoring: bills service.
refactoring: bills payments made service.
This commit is contained in:
@@ -70,13 +70,24 @@ export default class AccountTypeRepository extends TenantRepository {
|
||||
* @param {string} rootType
|
||||
* @return {IAccountType[]}
|
||||
*/
|
||||
getByRootType(rootType: string): IAccountType[] {
|
||||
getByRootType(rootType: string): Promise<IAccountType[]> {
|
||||
const { AccountType } = this.models;
|
||||
return this.cache.get(`accountType.rootType.${rootType}`, () => {
|
||||
return AccountType.query().where('root_type', rootType);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve accounts types of the given child type.
|
||||
* @param {string} childType
|
||||
*/
|
||||
getByChildType(childType: string): Promise<IAccountType[]> {
|
||||
const { AccountType } = this.models;
|
||||
return this.cache.get(`accountType.childType.${childType}`, () => {
|
||||
return AccountType.query().where('child_type', childType);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush repository cache.
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import TenantRepository from 'repositories/TenantRepository';
|
||||
import { IContact } from 'interfaces';
|
||||
import Contact from 'models/Contact';
|
||||
|
||||
export default class ContactRepository extends TenantRepository {
|
||||
cache: any;
|
||||
@@ -45,9 +44,11 @@ export default class ContactRepository extends TenantRepository {
|
||||
* Inserts a new contact model.
|
||||
* @param contact
|
||||
*/
|
||||
async insert(contact) {
|
||||
await Contact.query().insert({ ...contact })
|
||||
async insert(contactInput: IContact) {
|
||||
const { Contact } = this.models;
|
||||
const contact = await Contact.query().insert({ ...contactInput })
|
||||
this.flushCache();
|
||||
return contact;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,6 +57,7 @@ export default class ContactRepository extends TenantRepository {
|
||||
* @param {IContact} contact - Contact input.
|
||||
*/
|
||||
async update(contactId: number, contact: IContact) {
|
||||
const { Contact } = this.models;
|
||||
await Contact.query().findById(contactId).patch({ ...contact });
|
||||
this.flushCache();
|
||||
}
|
||||
@@ -66,6 +68,7 @@ export default class ContactRepository extends TenantRepository {
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
async deleteById(contactId: number): Promise<void> {
|
||||
const { Contact } = this.models;
|
||||
await Contact.query().where('id', contactId).delete();
|
||||
this.flushCache();
|
||||
}
|
||||
@@ -75,6 +78,7 @@ export default class ContactRepository extends TenantRepository {
|
||||
* @param {number[]} contactsIds
|
||||
*/
|
||||
async bulkDelete(contactsIds: number[]) {
|
||||
const { Contact } = this.models;
|
||||
await Contact.query().whereIn('id', contactsIds);
|
||||
this.flushCache();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,15 @@ export default class VendorRepository extends TenantRepository {
|
||||
this.cache = this.tenancy.cache(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve vendor details of the given id.
|
||||
* @param {number} vendorId - Vendor id.
|
||||
*/
|
||||
findById(vendorId: number) {
|
||||
const { Contact } = this.models;
|
||||
return Contact.query().findById(vendorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the bill that associated to the given vendor id.
|
||||
* @param {number} vendorId - Vendor id.
|
||||
@@ -49,4 +58,23 @@ export default class VendorRepository extends TenantRepository {
|
||||
.whereIn('id', vendorIds)
|
||||
.withGraphFetched('bills');
|
||||
}
|
||||
|
||||
changeBalance(vendorId: number, amount: number) {
|
||||
const { Contact } = this.models;
|
||||
const changeMethod = (amount > 0) ? 'increment' : 'decrement';
|
||||
|
||||
return Contact.query()
|
||||
.where('id', vendorId)
|
||||
[changeMethod]('balance', Math.abs(amount));
|
||||
}
|
||||
|
||||
|
||||
changeDiffBalance(
|
||||
vendorId: number,
|
||||
amount: number,
|
||||
oldAmount: number,
|
||||
oldVendorId?: number,
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user