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)]
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ async fn rocket() -> _ {
|
|||
let locations: JSONStore<Location> = JSONStore::new("./locations");
|
||||
|
||||
for location in locations.deref() {
|
||||
location.1.insert_overwrite().await.unwrap();
|
||||
location.1.clone().add(location.0).await;
|
||||
}
|
||||
|
||||
rocket::build()
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue