diff --git a/src/location.rs b/src/location.rs index 677ca57..aca348f 100644 --- a/src/location.rs +++ b/src/location.rs @@ -10,6 +10,7 @@ use serde_json::json; #[derive(Debug, Clone, Serialize, Deserialize, Model, Referencable)] pub struct Location { /// UUID + #[serde(default)] pub _id: String, /// Name pub name: String, @@ -43,28 +44,8 @@ impl ToAPI for Location { } impl Location { - pub async fn add(id: &str, o: serde_json::Value) { - let l = Location { - _id: id.to_string(), - name: o - .as_object() - .unwrap() - .get("name") - .unwrap() - .as_str() - .unwrap() - .to_string(), - parent: o - .as_object() - .unwrap() - .get("parent") - .map(|x| x.as_str().unwrap().to_string()), - conditions: serde_json::from_value( - o.as_object().unwrap().get("conditions").unwrap().clone(), - ) - .unwrap(), - }; - - l.insert_overwrite().await.unwrap(); + pub async fn add(&mut self, id: &str) { + self._id = id.to_string(); + self.insert_overwrite().await.unwrap(); } } diff --git a/src/main.rs b/src/main.rs index b615d98..d7694ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +51,7 @@ async fn rocket() -> _ { let locations: JSONStore = JSONStore::new("./locations"); for location in locations.deref() { - location.1.insert_overwrite().await.unwrap(); + location.1.clone().add(location.0).await; } rocket::build() diff --git a/src/transaction.rs b/src/transaction.rs index 2c4e283..e0dc75d 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -67,7 +67,7 @@ impl Transaction { consumed: None, origin: origin.map(std::string::ToString::to_string), location: if let Some(location) = location { - reference_of!(Location, location).await + reference_of!(Location, location) } else { None },