working and no errors on front or back ends
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import {ColumnDef, EndpointDef, Filter} from "../systemGenService";
|
||||
import {BelongsToDef, ColumnDef, EndpointDef, Filter, ManyToManyDef, SystemDef, TableDef} from "../systemGenService";
|
||||
import {lowercaseFirstLetter} from "../helpers";
|
||||
import {buildMapperFunctionName} from "./mapper-creator";
|
||||
|
||||
@ -31,7 +31,7 @@ function buildServiceFunction(view: EndpointDef): string {
|
||||
return func;
|
||||
}
|
||||
|
||||
function getFuncParams(view: EndpointDef, addTypes=false): string[] {
|
||||
function getFuncParams(view: EndpointDef, addTypes=false, systemDef?: SystemDef): string[] {
|
||||
let filters = view.filters || [];
|
||||
let columnList: ParamDef[] = view.columns?.filter((column) => {return column.param;}).map((column) => {
|
||||
return {
|
||||
@ -49,8 +49,44 @@ function getFuncParams(view: EndpointDef, addTypes=false): string[] {
|
||||
};
|
||||
});
|
||||
|
||||
let relationsList: ParamDef[] = [];
|
||||
if (systemDef) {
|
||||
let storageTable: TableDef | undefined = systemDef.storage.tables.find((table: TableDef) => {
|
||||
return view.component === table.name;
|
||||
});
|
||||
if (storageTable) {
|
||||
relationsList = storageTable.relations.map((rel: BelongsToDef) => {
|
||||
return {
|
||||
param: rel.table + '_id',
|
||||
required: false,
|
||||
type: 'string'
|
||||
}
|
||||
});
|
||||
}
|
||||
relationsList = [...relationsList, ...systemDef.storage.relations.filter((rel: ManyToManyDef) => {
|
||||
if (rel.left === view.component || rel.right === view.component) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}).map((rel: ManyToManyDef) => {
|
||||
if (rel.left === view.component) {
|
||||
return {
|
||||
param: rel.right + '_id',
|
||||
required: false,
|
||||
type: 'string'
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
param: rel.left + '_id',
|
||||
required: false,
|
||||
type: 'string'
|
||||
};
|
||||
}
|
||||
})];
|
||||
}
|
||||
|
||||
// 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) => {
|
||||
let combinedList = relationsList.concat(columnList).concat(filterList).sort((a, b) => {
|
||||
if (a.required && b.required) {
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user