refactor
This commit is contained in:
parent
b8caa43972
commit
4295bdcb8d
7 changed files with 109 additions and 36 deletions
|
@ -1,8 +1,9 @@
|
|||
use mongodb::bson::doc;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{
|
||||
cache::InventoryCache,
|
||||
cdb_col, collect_results, get_mongo,
|
||||
cdb_col, collect_results, get_mongo, id_of,
|
||||
transaction::{BatchTransaction, Price, Transaction},
|
||||
};
|
||||
|
||||
|
@ -103,10 +104,7 @@ impl Variant {
|
|||
|
||||
// check if supply transaction exists
|
||||
let supply_t = cdb_col!(db, "supply");
|
||||
supply_t
|
||||
.find_one(doc! { "_id": uuid}, None)
|
||||
.await
|
||||
.unwrap()?;
|
||||
supply_t.find_one(id_of!(uuid), None).await.unwrap()?;
|
||||
|
||||
// todo : demand batch
|
||||
|
||||
|
@ -183,6 +181,15 @@ impl Variant {
|
|||
ret_uuid
|
||||
}
|
||||
|
||||
pub fn api_json(&self) -> serde_json::Value {
|
||||
json!({
|
||||
"item": self.item,
|
||||
"variant": self.variant,
|
||||
"amount": self.amount as u32,
|
||||
"depends": self.depends
|
||||
})
|
||||
}
|
||||
|
||||
pub fn as_bson(&self) -> mongodb::bson::Document {
|
||||
mongodb::bson::doc! {
|
||||
"item": &self.item,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue