Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong OpValValue value for $in operation in op_value_to_op_val_type for OpValValue #4

Open
1g0rkR opened this issue Jun 13, 2024 · 0 comments

Comments

@1g0rkR
Copy link

1g0rkR commented Jun 13, 2024

Hi there,
Wrong operator for $in function.

Correction:
... "$in", value) => OpValValue::In(into_values(value)?), ...

impl OpValueToOpValType for OpValValue {
		fn op_value_to_op_val_type(op: &str, value: Value) -> Result<Self>
		where
			Self: Sized,
		{
			fn into_values(value: Value) -> Result<Vec<Value>> {
				let mut values = Vec::new();

				let Value::Array(array) = value else {
					return Err(Error::JsonValArrayWrongType { actual_value: value });
				};

				for item in array.into_iter() {
					values.push(item)
				}

				Ok(values)
			}

			let ov = match (op, value) {
				("$eq", v) => OpValValue::Eq(v),
				("$in", value) => OpValValue::NotIn(into_values(value)?), <<<---- Should be OpValValue::In

				("$not", v) => OpValValue::Not(v),
				("$notIn", value) => OpValValue::NotIn(into_values(value)?),

				("$lt", v) => OpValValue::Lt(v),
				("$lte", v) => OpValValue::Lte(v),

				("$gt", v) => OpValValue::Gt(v),
				("$gte", v) => OpValValue::Gte(v),

				("$null", Value::Bool(v)) => OpValValue::Null(v),

				(_, v) => {
					return Err(Error::JsonOpValNotSupported {
						operator: op.to_string(),
						value: v,
					})
				}
			};
			Ok(ov)
		}
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant