feat: conditional schema based on column map instead of column field (#1978)
* feat: wip conditional schema based on column map instead of column field * feat: conditionalSchema columnMap and singular plural * fix: remove uuid fix * feat: add name and label (singular/plural) drop old tableColumnName
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
import isEmpty from 'lodash.isempty';
|
||||
|
||||
import { FieldMetadata } from 'src/metadata/field-metadata/field-metadata.entity';
|
||||
|
||||
export const convertArguments = (args: any, fields: FieldMetadata[]): any => {
|
||||
const fieldsMap = new Map(
|
||||
// TODO: Handle plural for fields when we add relations
|
||||
fields.map((metadata) => [metadata.nameSingular, metadata]),
|
||||
);
|
||||
|
||||
if (Array.isArray(args)) {
|
||||
return args.map((arg) => convertArguments(arg, fields));
|
||||
}
|
||||
|
||||
const newArgs = {};
|
||||
|
||||
for (const [key, value] of Object.entries(args)) {
|
||||
if (fieldsMap.has(key)) {
|
||||
const fieldMetadata = fieldsMap.get(key)!;
|
||||
|
||||
if (typeof value === 'object' && value !== null && !isEmpty(value)) {
|
||||
for (const [subKey, subValue] of Object.entries(value)) {
|
||||
if (fieldMetadata.targetColumnMap[subKey]) {
|
||||
newArgs[fieldMetadata.targetColumnMap[subKey]] = subValue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fieldMetadata.targetColumnMap.value) {
|
||||
newArgs[fieldMetadata.targetColumnMap.value] = value;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newArgs[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return newArgs;
|
||||
};
|
||||
Reference in New Issue
Block a user