fix
This commit is contained in:
parent
2a7e963869
commit
f7fac9aec8
3 changed files with 6 additions and 25 deletions
|
@ -10,6 +10,7 @@ use serde_json::json;
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Model, Referencable)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Model, Referencable)]
|
||||||
pub struct Location {
|
pub struct Location {
|
||||||
/// UUID
|
/// UUID
|
||||||
|
#[serde(default)]
|
||||||
pub _id: String,
|
pub _id: String,
|
||||||
/// Name
|
/// Name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -43,28 +44,8 @@ impl ToAPI for Location {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Location {
|
impl Location {
|
||||||
pub async fn add(id: &str, o: serde_json::Value) {
|
pub async fn add(&mut self, id: &str) {
|
||||||
let l = Location {
|
self._id = id.to_string();
|
||||||
_id: id.to_string(),
|
self.insert_overwrite().await.unwrap();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ async fn rocket() -> _ {
|
||||||
let locations: JSONStore<Location> = JSONStore::new("./locations");
|
let locations: JSONStore<Location> = JSONStore::new("./locations");
|
||||||
|
|
||||||
for location in locations.deref() {
|
for location in locations.deref() {
|
||||||
location.1.insert_overwrite().await.unwrap();
|
location.1.clone().add(location.0).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
rocket::build()
|
rocket::build()
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl Transaction {
|
||||||
consumed: None,
|
consumed: None,
|
||||||
origin: origin.map(std::string::ToString::to_string),
|
origin: origin.map(std::string::ToString::to_string),
|
||||||
location: if let Some(location) = location {
|
location: if let Some(location) = location {
|
||||||
reference_of!(Location, location).await
|
reference_of!(Location, location)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue