fix: don't update the same field while trying to remove it

fixes #392
This commit is contained in:
IAmTomahawkx
2025-08-06 14:18:40 -07:00
parent 6048587d34
commit f4ee35fb09

View File

@@ -212,16 +212,34 @@ impl AbstractUsers for MongoDb {
partial: &PartialUser, partial: &PartialUser,
remove: Vec<FieldsUser>, remove: Vec<FieldsUser>,
) -> Result<()> { ) -> Result<()> {
query!( if remove.contains(&FieldsUser::StatusText) && partial.status.is_some() {
self, // stupid-ass workaround to fix mongo conflicting the same item
update_one_by_id, let _: Result<()> = query!(
COL, self,
id, update_one_by_id,
partial, COL,
remove.iter().map(|x| x as &dyn IntoDocumentPath).collect(), id,
None PartialUser {
) ..Default::default()
.map(|_| ()) },
remove.iter().map(|x| x as &dyn IntoDocumentPath).collect(),
None
)
.map(|_| ());
query!(self, update_one_by_id, COL, id, partial, vec![], None).map(|_| ())
} else {
query!(
self,
update_one_by_id,
COL,
id,
partial,
remove.iter().map(|x| x as &dyn IntoDocumentPath).collect(),
None
)
.map(|_| ())
}
} }
/// Set relationship with another user /// Set relationship with another user