mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
32 lines
864 B
TypeScript
32 lines
864 B
TypeScript
|
import { singleValueOperators } from 'constants/operators';
|
||
|
import { IConstraint } from 'interfaces/strategy';
|
||
|
import { oneOf } from './one-of';
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
};
|