forked from jmug/stoatchat
chore(thanos): strip down codebase to just API routes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use revolt_quark::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use mongodb::options::FindOneOptions;
|
||||
@@ -12,35 +11,6 @@ pub struct Options {
|
||||
}
|
||||
|
||||
#[post("/settings/fetch", data = "<options>")]
|
||||
pub async fn req(user: User, options: Json<Options>) -> Result<Value> {
|
||||
if user.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
}
|
||||
|
||||
let options = options.into_inner();
|
||||
let mut projection = doc! {
|
||||
"_id": 0,
|
||||
};
|
||||
|
||||
for key in options.keys {
|
||||
projection.insert(key, 1);
|
||||
}
|
||||
|
||||
if let Some(doc) = get_collection("user_settings")
|
||||
.find_one(
|
||||
doc! {
|
||||
"_id": user.id
|
||||
},
|
||||
FindOneOptions::builder().projection(projection).build(),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find_one",
|
||||
with: "user_settings",
|
||||
})?
|
||||
{
|
||||
Ok(json!(doc))
|
||||
} else {
|
||||
Ok(json!({}))
|
||||
}
|
||||
pub async fn req(/*user: UserRef,*/ options: Json<Options>) -> Result<Value> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user