mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix: database migrations FK relations.
fix: database columns indexing.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import TenantRepository from 'repositories/TenantRepository';
|
||||
import { IAccount } from 'interfaces';
|
||||
import { Account } from 'models';
|
||||
|
||||
export default class AccountRepository extends TenantRepository {
|
||||
models: any;
|
||||
@@ -57,7 +58,7 @@ export default class AccountRepository extends TenantRepository {
|
||||
|
||||
/**
|
||||
* Retrieve the account by the given id.
|
||||
* @param {number} id - Account id.
|
||||
* @param {number} id - Account id.
|
||||
* @return {IAccount}
|
||||
*/
|
||||
getById(id: number): IAccount {
|
||||
@@ -67,4 +68,63 @@ export default class AccountRepository extends TenantRepository {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve accounts by the given ids.
|
||||
* @param {number[]} ids -
|
||||
* @return {IAccount[]}
|
||||
*/
|
||||
findByIds(accountsIds: number[]) {
|
||||
const { Account } = this.models;
|
||||
return Account.query().whereIn('id', accountsIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate the given account.
|
||||
* @param {number} accountId -
|
||||
* @return {void}
|
||||
*/
|
||||
async activate(accountId: number): Promise<void> {
|
||||
const { Account } = this.models;
|
||||
await Account.query().findById(accountId).patch({ active: 1 })
|
||||
this.flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new accounts to the storage.
|
||||
* @param {IAccount} account
|
||||
*/
|
||||
async insert(account: IAccount): Promise<void> {
|
||||
const { Account } = this.models;
|
||||
await Account.query().insertAndFetch({ ...account });
|
||||
this.flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates account of the given account.
|
||||
* @param {number} accountId - Account id.
|
||||
* @param {IAccount} account
|
||||
* @return {void}
|
||||
*/
|
||||
async edit(accountId: number, account: IAccount): Promise<void> {
|
||||
const { Account } = this.models;
|
||||
await Account.query().findById(accountId).patch({ ...account });
|
||||
this.flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given account by id.
|
||||
* @param {number} accountId - Account id.
|
||||
*/
|
||||
async deleteById(accountId: number): Promise<void> {
|
||||
const { Account } = this.models;
|
||||
await Account.query().deleteById(accountId);
|
||||
this.flushCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush repository cache.
|
||||
*/
|
||||
flushCache(): void {
|
||||
this.cache.delStartWith('accounts');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user