2022-03-04 17:29:51 +01:00
|
|
|
import { singleValueOperators } from 'constants/operators';
|
|
|
|
import { IConstraint } from 'interfaces/strategy';
|
2022-03-25 12:34:20 +01:00
|
|
|
import { oneOf } from 'utils/oneOf';
|
2022-03-04 17:29:51 +01:00
|
|
|
|
|
|
|
const VALUES = 'values';
|
|
|
|
const VALUE = 'value';
|
|
|
|
|
|
|
|
export const cleanConstraint = (
|
|
|
|
constraint: Readonly<IConstraint>
|
|
|
|
): IConstraint => {
|
|
|
|
const constraintCopy: IConstraint = {
|
|
|
|
contextName: '',
|
|
|
|
operator: 'IN',
|
|
|
|
};
|
|
|
|
|
|
|
|
if (oneOf(singleValueOperators, constraint.operator)) {
|
|
|
|
for (const [key, value] of Object.entries(constraint)) {
|
|
|
|
if (key !== VALUES) {
|
|
|
|
constraintCopy[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return constraintCopy;
|
|
|
|
} else {
|
|
|
|
for (const [key, value] of Object.entries(constraint)) {
|
|
|
|
if (key !== VALUE) {
|
|
|
|
constraintCopy[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return constraintCopy;
|
|
|
|
}
|
|
|
|
};
|