mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat: rewrite repositories with base entity repository class.
feat: sales and purchases status. feat: sales and purchases auto-increment number. fix: settings find query with extra columns.
This commit is contained in:
@@ -1,60 +1,19 @@
|
||||
import { IView } from 'interfaces';
|
||||
import { View } from 'models';
|
||||
import TenantRepository from 'repositories/TenantRepository';
|
||||
|
||||
export default class ViewRepository extends TenantRepository {
|
||||
|
||||
/**
|
||||
* Retrieve view model by the given id.
|
||||
* @param {number} id -
|
||||
* Constructor method.
|
||||
*/
|
||||
getById(id: number) {
|
||||
const { View } = this.models;
|
||||
return this.cache.get(`customView.id.${id}`, () => {
|
||||
return View.query().findById(id)
|
||||
.withGraphFetched('columns')
|
||||
.withGraphFetched('roles');
|
||||
});
|
||||
constructor(knex, cache) {
|
||||
super(knex, cache);
|
||||
this.model = View;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all views of the given resource id.
|
||||
*/
|
||||
allByResource(resourceModel: string) {
|
||||
const { View } = this.models;
|
||||
return this.cache.get(`customView.resourceModel.${resourceModel}`, () => {
|
||||
return View.query().where('resource_model', resourceModel)
|
||||
.withGraphFetched('columns')
|
||||
.withGraphFetched('roles');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new view to the storage.
|
||||
* @param {IView} view
|
||||
*/
|
||||
async insert(view: IView): Promise<IView> {
|
||||
const { View } = this.models;
|
||||
const insertedView = await View.query().insertGraph({ ...view });
|
||||
this.flushCache();
|
||||
|
||||
return insertedView;
|
||||
}
|
||||
|
||||
async update(viewId: number, view: IView): Promise<IView> {
|
||||
const { View } = this.models;
|
||||
const updatedView = await View.query().upsertGraph({
|
||||
id: viewId,
|
||||
...view
|
||||
});
|
||||
this.flushCache();
|
||||
|
||||
return updatedView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes repository cache.
|
||||
*/
|
||||
flushCache() {
|
||||
this.cache.delStartWith('customView');
|
||||
allByResource(resourceModel: string, withRelations?) {
|
||||
return super.find({ resource_mode: resourceModel }, withRelations);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user