This commit is contained in:
JMARyA 2024-09-12 11:48:09 +02:00
parent 37475460e2
commit 02966c0605
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
9 changed files with 340 additions and 13 deletions

View file

@ -125,11 +125,11 @@ impl Variant {
ret
}
pub async fn demand(uuid: &str, price: Price, destination: &str) -> Option<()> {
pub async fn demand(uuid: &str, price: Price, destination: &str) -> Option<Transaction> {
// check if transaction exists
let mut t = Transaction::get(uuid).await?;
t.consume(price, destination).await;
Some(())
t = t.consume(price, destination).await;
Some(t)
}
/// Records a supply transaction in the database.
@ -147,12 +147,12 @@ impl Variant {
price: Price,
origin: Option<&str>,
location: Option<&str>,
) -> String {
) -> Transaction {
let t = Transaction::new(&self.item, &self.variant, price, origin, location).await;
t.insert().await.unwrap();
t._id
t
}
pub async fn get_all_transactions(&self) -> Vec<Transaction> {