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

@ -1,4 +1,4 @@
use mongod::Model;
use mongod::{Model, Sort};
use mongodb::bson::doc;
use serde::{Deserialize, Serialize};
use serde_json::json;
@ -76,6 +76,7 @@ impl Variant {
}
}
/// Returns the IDs of Transactions from this Item Variant.
pub async fn supply_log(&self) -> Vec<String> {
let filter = doc! {
"item": &self.item,
@ -95,6 +96,7 @@ impl Variant {
ret
}
/// Returns the active Transaction of this Item Variant which are not yet consumed.
pub async fn inventory(&self) -> Vec<Transaction> {
let filter = doc! {
"item": &self.item,
@ -105,11 +107,20 @@ impl Variant {
Transaction::find(filter, None, None).await.unwrap()
}
pub async fn demand_log(&self) -> Vec<String> {
let filter = doc! {
"item": &self.item,
"variant": &self.variant,
"consumed": { "$type": "object" }
/// Returns the IDs of the Transactions from this Item Variant which are consumed.
pub async fn demand_log(&self, destination: Option<&str>) -> Vec<String> {
let filter = if let Some(dest) = destination {
doc! {
"item": &self.item,
"variant": &self.variant,
"consumed": { "destination": dest }
}
} else {
doc! {
"item": &self.item,
"variant": &self.variant,
"consumed": { "$type": "object" }
}
};
let result = Transaction::find_partial(filter, json!({}), None, None)
@ -155,13 +166,16 @@ impl Variant {
t
}
/// Returns all Transactions of this Item Variant
pub async fn get_all_transactions(&self) -> Vec<Transaction> {
let filter = doc! {
"item": &self.item,
"variant": &self.variant
};
Transaction::find(filter, None, None).await.unwrap()
Transaction::find(filter, None, Some(doc! { "timestamp": Sort::Descending }))
.await
.unwrap()
}
pub async fn get_transaction_timeslice(&self, year: i32, month: u32) -> Vec<Transaction> {