This commit is contained in:
JMARyA 2024-09-21 18:58:24 +02:00
parent ad96e2938d
commit c68f871f4d
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 29 additions and 26 deletions

View file

@ -1,6 +1,6 @@
use std::collections::HashMap;
use mongod::{vec_to_api, ToAPI};
use mongod::{reference_of, vec_to_api, Model, ToAPI};
use rocket::{get, State};
use serde_json::json;
@ -109,6 +109,9 @@ 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

View file

@ -113,12 +113,12 @@ impl Transaction {
false
}
pub async fn in_location(l: &str) -> Vec<Self> {
pub async fn in_location(l: Reference) -> Vec<Self> {
Self::find(doc! { "location": l}, None, None).await.unwrap()
}
pub async fn in_location_recursive(l: &str) -> Vec<Self> {
let locations = Location::find(doc! { "parent": l}, None, None)
pub async fn in_location_recursive(l: Reference) -> Vec<Self> {
let locations = Location::find(doc! { "parent": &l}, None, None)
.await
.unwrap();
let mut transactions = Self::find(doc! { "location": l}, None, None).await.unwrap();