add funcParam builder with sorting by required
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import {EndpointDef} from "../systemGenService";
|
||||
import {ColumnDef, EndpointDef, Filter} from "../systemGenService";
|
||||
import {lowercaseFirstLetter} from "./helpers";
|
||||
import {buildMapperFunctionName} from "./mapper-creator";
|
||||
|
||||
@ -12,9 +12,7 @@ function buildServiceFunction(view: EndpointDef): string {
|
||||
let func: string = '';
|
||||
let isListOrSearch: boolean = view.type === 'list' || view.type === 'search';
|
||||
let funcName: string = buildServiceFunctionName(view);
|
||||
// there should never be an 'undefined' item in funcParams but the compiler complained that it was possible
|
||||
// TODO: funcParams should be sorted by 'required' so the optional params can come last and be left off when calling
|
||||
let funcParams: (string | undefined)[] = (view.columns?.filter(column => column.param).map(column => column.param) || []).concat(view.filters?.filter(filter => filter.param).map(filter => filter.param) || []);
|
||||
let funcParams: string[] = getFuncParams(view);
|
||||
let columnParams: string[] = view.columns?.filter(column => column.param).map(column => { return '\n ' + column.param + ': ' + column.param; });
|
||||
let filterParams: string[] = view.filters?.filter(filter => filter.param).map(filter => { return '\n ' + filter.param + ': ' + filter.param; }) || [];
|
||||
|
||||
@ -33,6 +31,41 @@ function buildServiceFunction(view: EndpointDef): string {
|
||||
return func;
|
||||
}
|
||||
|
||||
function getFuncParams(view: EndpointDef): string[] {
|
||||
let filters = view.filters || [];
|
||||
let columnList: ParamDef[] = view.columns?.filter((column) => {return column.param;}).map((column) => {
|
||||
return {
|
||||
param: column.param,
|
||||
required: column.required
|
||||
};
|
||||
});
|
||||
|
||||
let filterList: ParamDef[] = filters.filter((column) => {return column.param;}).map((filter) => {
|
||||
return {
|
||||
param: filter.param,
|
||||
required: filter.required
|
||||
};
|
||||
});
|
||||
|
||||
// funcParams should be sorted by 'required' so the optional params can come last and be left off when calling
|
||||
let combinedList = columnList.concat(filterList).sort((a, b) => {
|
||||
if (a.required && b.required) {
|
||||
return 0;
|
||||
}
|
||||
if (a.required) {
|
||||
return -1;
|
||||
}
|
||||
if (b.required) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return combinedList.map((param) => {
|
||||
return param.param || '';
|
||||
});
|
||||
}
|
||||
|
||||
function buildServiceFunctionName(view: EndpointDef): string {
|
||||
return buildMapperFunctionName(view); // the functions should have the same name... I'm pretty sure...
|
||||
}
|
||||
@ -41,6 +74,11 @@ function mapperInstance(view: EndpointDef): string {
|
||||
return `${lowercaseFirstLetter(view.component)}Mapper`;
|
||||
}
|
||||
|
||||
interface ParamDef {
|
||||
param?: string;
|
||||
required?: boolean;
|
||||
}
|
||||
|
||||
export {
|
||||
createServiceFunc
|
||||
}
|
@ -47,6 +47,7 @@ function createComponent(component: ComponentDef, systemDef: SystemDef) {
|
||||
componentResolve();
|
||||
});
|
||||
}
|
||||
// TODO: remove {{component}} folder that hasn't been used
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user