forked from jmug/stoatchat
feat(safety): add API route for editing report
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::models::report::PartialReport;
|
||||
use crate::models::Report;
|
||||
use crate::{AbstractReport, Result};
|
||||
|
||||
@@ -10,6 +11,14 @@ impl AbstractReport for DummyDb {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_report(&self, _id: &str, _report: &PartialReport) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn fetch_report(&self, _report_id: &str) -> Result<Report> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
async fn fetch_reports(&self) -> Result<Vec<Report>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
@@ -27,3 +27,7 @@ pub mod users {
|
||||
pub mod user;
|
||||
pub mod user_settings;
|
||||
}
|
||||
|
||||
pub mod safety {
|
||||
pub mod report;
|
||||
}
|
||||
|
||||
9
crates/quark/src/impl/generic/safety/report.rs
Normal file
9
crates/quark/src/impl/generic/safety/report.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use crate::{models::report::PartialReport, models::Report, Database, Result};
|
||||
|
||||
impl Report {
|
||||
/// Update report data
|
||||
pub async fn update(&mut self, db: &Database, partial: PartialReport) -> Result<()> {
|
||||
self.apply_options(partial.clone());
|
||||
db.update_report(&self.id, &partial).await
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,14 @@ impl MongoDb {
|
||||
operation: "find",
|
||||
with: collection,
|
||||
})?
|
||||
.filter_map(|s| async { s.ok() })
|
||||
.filter_map(|s| async {
|
||||
if cfg!(debug_assertions) {
|
||||
// Hard fail on invalid documents
|
||||
Some(s.unwrap())
|
||||
} else {
|
||||
s.ok()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<T>>()
|
||||
.await)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::models::report::PartialReport;
|
||||
use crate::models::Report;
|
||||
use crate::{AbstractReport, Result};
|
||||
|
||||
@@ -11,6 +12,16 @@ impl AbstractReport for MongoDb {
|
||||
self.insert_one(COL, report).await.map(|_| ())
|
||||
}
|
||||
|
||||
async fn update_report(&self, id: &str, report: &PartialReport) -> Result<()> {
|
||||
self.update_one_by_id(COL, id, report, vec![], None)
|
||||
.await
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
async fn fetch_report(&self, report_id: &str) -> Result<Report> {
|
||||
self.find_one_by_id(COL, report_id).await
|
||||
}
|
||||
|
||||
async fn fetch_reports(&self) -> Result<Vec<Report>> {
|
||||
self.find(COL, doc! {}).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user