2022-03-04 17:29:51 +01:00
|
|
|
import { singleValueOperators } from 'constants/operators';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { IConstraint } from 'interfaces/strategy';
|
2022-03-25 12:34:20 +01:00
|
|
|
import { oneOf } from 'utils/oneOf';
|
2022-05-04 15:16:34 +02:00
|
|
|
import produce from 'immer';
|
2022-03-04 17:29:51 +01:00
|
|
|
|
|
|
|
export const cleanConstraint = (
|
2023-10-02 14:25:46 +02:00
|
|
|
constraint: Readonly<IConstraint>,
|
2022-03-04 17:29:51 +01:00
|
|
|
): IConstraint => {
|
2023-10-02 14:25:46 +02:00
|
|
|
return produce(constraint, (draft) => {
|
2022-05-04 15:16:34 +02:00
|
|
|
if (oneOf(singleValueOperators, constraint.operator)) {
|
|
|
|
delete draft.values;
|
|
|
|
} else {
|
|
|
|
delete draft.value;
|
2022-03-04 17:29:51 +01:00
|
|
|
}
|
2022-05-04 15:16:34 +02:00
|
|
|
});
|
2022-03-04 17:29:51 +01:00
|
|
|
};
|