This commit is contained in:
JMARyA 2024-09-12 13:11:44 +02:00
parent fb6a96ff55
commit 94459d5481
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
7 changed files with 90 additions and 14 deletions

View file

@ -82,20 +82,25 @@ pub async fn supply_log_route(
}
/// Returns current active Transactions for Item
#[get("/item/<item_id>/inventory")]
#[get("/item/<item_id>/inventory?<origin>")]
pub async fn inventory_route(
item_id: &str,
itemdb: &State<ItemDB>,
t: Token,
c: &State<Config>,
origin: Option<&str>,
) -> FallibleApiResponse {
check_auth!(t, c);
let variant = itemdb
let item = itemdb
.get_item(item_id)
.ok_or_else(item_does_not_exist_error)?;
let transactions = variant.inventory().await;
let transactions = if let Some(origin) = origin {
item.inventory_by_origin(origin).await
} else {
item.inventory().await
};
Ok(json!(mongod::vec_to_api(&transactions).await))
}