mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
- feat: Sales estimates APIs.
- feat: Sales invoices APIs. - feat: Sales receipts APIs. - WIP: Sales payment receipts. - WIP: Purchases bills. - WIP: Purchases payments made.
This commit is contained in:
75
server/src/services/DynamicListing/DynamicListing.js
Normal file
75
server/src/services/DynamicListing/DynamicListing.js
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
import {
|
||||
DynamicFilter,
|
||||
DynamicFilterSortBy,
|
||||
DynamicFilterViews,
|
||||
DynamicFilterFilterRoles,
|
||||
} from '@/lib/DynamicFilter';
|
||||
import {
|
||||
mapViewRolesToConditionals,
|
||||
mapFilterRolesToDynamicFilter,
|
||||
} from '@/lib/ViewRolesBuilder';
|
||||
|
||||
export const DYNAMIC_LISTING_ERRORS = {
|
||||
LOGIC_INVALID: 'VIEW.LOGIC.EXPRESSION.INVALID',
|
||||
RESOURCE_HAS_NO_FIELDS: 'RESOURCE.HAS.NO.GIVEN.FIELDS',
|
||||
};
|
||||
|
||||
export default class DynamicListing {
|
||||
|
||||
/**
|
||||
* Constructor method.
|
||||
* @param {DynamicListingBuilder} dynamicListingBuilder
|
||||
* @return {DynamicListing|Error}
|
||||
*/
|
||||
constructor(dynamicListingBuilder) {
|
||||
this.listingBuilder = dynamicListingBuilder;
|
||||
this.dynamicFilter = new DynamicFilter(this.listingBuilder.modelClass.tableName);
|
||||
return this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the dynamic listing.
|
||||
*/
|
||||
init() {
|
||||
// Initialize the column sort by.
|
||||
if (this.listingBuilder.columnSortBy) {
|
||||
const sortByFilter = new DynamicFilterSortBy(
|
||||
filter.column_sort_by,
|
||||
filter.sort_order
|
||||
);
|
||||
this.dynamicFilter.setFilter(sortByFilter);
|
||||
}
|
||||
// Initialize the view filter roles.
|
||||
if (this.listingBuilder.view && this.listingBuilder.view.roles.length > 0) {
|
||||
const viewFilter = new DynamicFilterViews(
|
||||
mapViewRolesToConditionals(this.listingBuilder.view.roles),
|
||||
this.listingBuilder.view.rolesLogicExpression
|
||||
);
|
||||
if (!viewFilter.validateFilterRoles()) {
|
||||
return new Error(DYNAMIC_LISTING_ERRORS.LOGIC_INVALID);
|
||||
}
|
||||
this.dynamicFilter.setFilter(viewFilter);
|
||||
}
|
||||
// Initialize the dynamic filter roles.
|
||||
if (this.listingBuilder.filterRoles.length > 0) {
|
||||
const filterRoles = new DynamicFilterFilterRoles(
|
||||
mapFilterRolesToDynamicFilter(filter.filter_roles),
|
||||
accountsResource.fields
|
||||
);
|
||||
this.dynamicFilter.setFilter(filterRoles);
|
||||
|
||||
if (filterRoles.validateFilterRoles().length > 0) {
|
||||
return new Error(DYNAMIC_LISTING_ERRORS.RESOURCE_HAS_NO_FIELDS);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build query.
|
||||
*/
|
||||
buildQuery(){
|
||||
return this.dynamicFilter.buildQuery();
|
||||
}
|
||||
}
|
||||
25
server/src/services/DynamicListing/DynamicListingBuilder.js
Normal file
25
server/src/services/DynamicListing/DynamicListingBuilder.js
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
export default class DynamicListingBuilder {
|
||||
|
||||
addModelClass(modelClass) {
|
||||
this.modelClass = modelClass;
|
||||
}
|
||||
|
||||
addCustomViewId(customViewId) {
|
||||
this.customViewId = customViewId;
|
||||
}
|
||||
|
||||
addFilterRoles (filterRoles) {
|
||||
this.filterRoles = filterRoles;
|
||||
}
|
||||
|
||||
addSortBy(sortBy, sortOrder) {
|
||||
this.sortBy = sortBy;
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
addView(view) {
|
||||
this.view = view;
|
||||
}
|
||||
}
|
||||
22
server/src/services/DynamicListing/HasDynamicListing.js
Normal file
22
server/src/services/DynamicListing/HasDynamicListing.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { DYNAMIC_LISTING_ERRORS } from '@/services/DynamicListing/DynamicListing';
|
||||
|
||||
export const dynamicListingErrorsToResponse = (error) => {
|
||||
let _errors;
|
||||
|
||||
if (error.message === DYNAMIC_LISTING_ERRORS.LOGIC_INVALID) {
|
||||
_errors.push({
|
||||
type: DYNAMIC_LISTING_ERRORS.LOGIC_INVALID,
|
||||
code: 200,
|
||||
});
|
||||
}
|
||||
if (
|
||||
error.message ===
|
||||
DYNAMIC_LISTING_ERRORS.RESOURCE_HAS_NO_FIELDS
|
||||
) {
|
||||
_errors.push({
|
||||
type: DYNAMIC_LISTING_ERRORS.RESOURCE_HAS_NO_FIELDS,
|
||||
code: 300,
|
||||
});
|
||||
}
|
||||
return _errors;
|
||||
};
|
||||
Reference in New Issue
Block a user