fix
This commit is contained in:
parent
c68f871f4d
commit
bfd4c1c0b9
3 changed files with 44 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use mongod::{reference_of, vec_to_api, Model, ToAPI};
|
||||
use mongod::{vec_to_api, ToAPI};
|
||||
use rocket::{get, State};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -109,16 +109,23 @@ pub async fn location_inventory(
|
|||
) -> FallibleApiResponse {
|
||||
check_auth!(t, c);
|
||||
|
||||
let location =
|
||||
reference_of!(Location, location).ok_or_else(|| api_error("No such location"))?;
|
||||
|
||||
if let Some("true" | "yes" | "1") = recursive {
|
||||
return Ok(json!(
|
||||
vec_to_api(&Transaction::in_location_recursive(location).await).await
|
||||
vec_to_api(
|
||||
&Transaction::in_location_recursive(location)
|
||||
.await
|
||||
.ok_or_else(|| api_error("No such location"))?
|
||||
)
|
||||
.await
|
||||
));
|
||||
}
|
||||
|
||||
Ok(json!(
|
||||
vec_to_api(&Transaction::in_location(location).await).await
|
||||
vec_to_api(
|
||||
&Transaction::in_location(location)
|
||||
.await
|
||||
.ok_or_else(|| api_error("No such location"))?
|
||||
)
|
||||
.await
|
||||
))
|
||||
}
|
||||
|
|
|
@ -113,25 +113,28 @@ impl Transaction {
|
|||
false
|
||||
}
|
||||
|
||||
pub async fn in_location(l: Reference) -> Vec<Self> {
|
||||
Self::find(doc! { "location": l}, None, None).await.unwrap()
|
||||
pub async fn in_location(l: &str) -> Option<Vec<Self>> {
|
||||
let l = reference_of!(Location, l)?;
|
||||
Some(Self::find(doc! { "location": l}, None, None).await.unwrap())
|
||||
}
|
||||
|
||||
pub async fn in_location_recursive(l: Reference) -> Vec<Self> {
|
||||
let locations = Location::find(doc! { "parent": &l}, None, None)
|
||||
pub async fn in_location_recursive(l: &str) -> Option<Vec<Self>> {
|
||||
let locations = Location::find(doc! { "parent": l}, None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let l = reference_of!(Location, l)?;
|
||||
let mut transactions = Self::find(doc! { "location": l}, None, None).await.unwrap();
|
||||
|
||||
for loc in locations {
|
||||
transactions.extend(
|
||||
Self::find(doc! { "location": loc.id() }, None, None)
|
||||
Self::find(doc! { "location": loc.reference() }, None, None)
|
||||
.await
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
transactions
|
||||
Some(transactions)
|
||||
}
|
||||
|
||||
/// Get all Transactions which are not consumed and are expired
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue