chore(thanos): strip down codebase to just API routes
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use crate::database::*;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
use revolt_quark::{EmptyResponse, Result};
|
||||
use crate::util::regex::RE_USERNAME;
|
||||
use mongodb::bson::doc;
|
||||
use rauth::entities::Account;
|
||||
@@ -19,45 +17,9 @@ pub struct Data {
|
||||
#[patch("/<_ignore_id>/username", data = "<data>")]
|
||||
pub async fn req(
|
||||
account: Account,
|
||||
user: User,
|
||||
//user: UserRef,
|
||||
data: Json<Data>,
|
||||
_ignore_id: String,
|
||||
) -> Result<EmptyResponse> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot)
|
||||
}
|
||||
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
account.verify_password(&data.password)
|
||||
.map_err(|_| Error::InvalidCredentials)?;
|
||||
|
||||
let mut set = doc! {};
|
||||
if let Some(username) = &data.username {
|
||||
if (username.to_lowercase() != user.username.to_lowercase()) && User::is_username_taken(&username).await? {
|
||||
return Err(Error::UsernameTaken);
|
||||
}
|
||||
|
||||
set.insert("username", username.clone());
|
||||
}
|
||||
|
||||
get_collection("users")
|
||||
.update_one(doc! { "_id": &user.id }, doc! { "$set": set }, None)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
ClientboundNotification::UserUpdate {
|
||||
id: user.id.clone(),
|
||||
data: json!({
|
||||
"username": data.username
|
||||
}),
|
||||
clear: None,
|
||||
}
|
||||
.publish_as_user(user.id.clone());
|
||||
|
||||
Ok(EmptyResponse {})
|
||||
todo!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user