This commit is contained in:
JMARyA 2024-09-21 19:18:08 +02:00
parent c68f871f4d
commit bfd4c1c0b9
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 44 additions and 34 deletions

44
Cargo.lock generated
View file

@ -225,9 +225,9 @@ dependencies = [
[[package]]
name = "bson"
version = "2.13.0"
version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "068208f2b6fcfa27a7f1ee37488d2bb8ba2640f68f5475d08e1d9130696aba59"
checksum = "80cf6f7806607bd58ad490bab34bf60e25455ea4aaf995f897a13324d41ea580"
dependencies = [
"ahash",
"base64 0.13.1",
@ -264,9 +264,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.7.2"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
[[package]]
name = "case"
@ -276,9 +276,9 @@ checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c"
[[package]]
name = "cc"
version = "1.1.21"
version = "1.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0"
checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
dependencies = [
"shlex",
]
@ -328,18 +328,18 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.18"
version = "4.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3"
checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.18"
version = "4.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b"
checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73"
dependencies = [
"anstream",
"anstyle",
@ -1006,9 +1006,9 @@ dependencies = [
[[package]]
name = "iana-time-zone"
version = "0.1.61"
version = "0.1.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
dependencies = [
"android_system_properties",
"core-foundation-sys",
@ -2038,9 +2038,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
version = "2.12.0"
version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6"
checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf"
dependencies = [
"core-foundation-sys",
"libc",
@ -2565,9 +2565,9 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.21"
version = "0.22.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf"
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
dependencies = [
"indexmap",
"serde",
@ -2763,9 +2763,9 @@ checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]]
name = "unicode-normalization"
version = "0.1.24"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
dependencies = [
"tinyvec",
]
@ -2778,15 +2778,15 @@ checksum = "52ea75f83c0137a9b98608359a5f1af8144876eb67bcb1ce837368e906a9f524"
[[package]]
name = "unicode-width"
version = "0.1.14"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d"
[[package]]
name = "unicode-xid"
version = "0.2.6"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
checksum = "229730647fbc343e3a80e463c1db7f78f3855d3f3739bee0dda773c9a037c90a"
[[package]]
name = "unsafe-libyaml"

View file

@ -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
))
}

View file

@ -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