Really make sure MongoDB driver can't screw up.

This commit is contained in:
Paul
2021-05-03 21:02:12 +01:00
parent efc3794f3d
commit cf7bb832da
4 changed files with 23 additions and 19 deletions

View File

@@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
export version=0.4.1-alpha.7-patch.0 export version=0.4.1-alpha.7-patch.2
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs echo "pub const VERSION: &str = \"${version}\";" > src/version.rs

View File

@@ -26,7 +26,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
data.validate() data.validate()
.map_err(|error| Error::FailedValidation { error })?; .map_err(|error| Error::FailedValidation { error })?;
if data.name.is_none() || data.description.is_none() || data.icon.is_none() || data.remove.is_none() { if data.name.is_none() && data.description.is_none() && data.icon.is_none() && data.remove.is_none() {
return Ok(()) return Ok(())
} }
@@ -85,14 +85,16 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
operations.insert("$unset", unset); operations.insert("$unset", unset);
} }
get_collection("channels") if operations.len() > 0 {
.update_one( get_collection("channels")
doc! { "_id": &id }, .update_one(
operations, doc! { "_id": &id },
None operations,
) None
.await )
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "channel" })?; .await
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "channel" })?;
}
ClientboundNotification::ChannelUpdate { ClientboundNotification::ChannelUpdate {
id: id.clone(), id: id.clone(),

View File

@@ -35,7 +35,7 @@ pub async fn req(user: User, data: Json<Data>, _ignore_id: String) -> Result<()>
data.validate() data.validate()
.map_err(|error| Error::FailedValidation { error })?; .map_err(|error| Error::FailedValidation { error })?;
if data.status.is_none() || data.profile.is_none() || data.avatar.is_none() || data.remove.is_none() { if data.status.is_none() && data.profile.is_none() && data.avatar.is_none() && data.remove.is_none() {
return Ok(()) return Ok(())
} }
@@ -119,13 +119,15 @@ pub async fn req(user: User, data: Json<Data>, _ignore_id: String) -> Result<()>
operations.insert("$unset", unset); operations.insert("$unset", unset);
} }
get_collection("users") if operations.len() > 0 {
.update_one(doc! { "_id": &user.id }, operations, None) get_collection("users")
.await .update_one(doc! { "_id": &user.id }, operations, None)
.map_err(|_| Error::DatabaseError { .await
operation: "update_one", .map_err(|_| Error::DatabaseError {
with: "user", operation: "update_one",
})?; with: "user",
})?;
}
if let Some(status) = &data.status { if let Some(status) = &data.status {
ClientboundNotification::UserUpdate { ClientboundNotification::UserUpdate {

View File

@@ -1 +1 @@
pub const VERSION: &str = "0.4.1-alpha.7-patch.0"; pub const VERSION: &str = "0.4.1-alpha.7-patch.2";