fix
This commit is contained in:
parent
e3128d7214
commit
9468629302
2 changed files with 26 additions and 18 deletions
36
src/flow.rs
36
src/flow.rs
|
@ -164,27 +164,27 @@ impl Flow {
|
|||
|
||||
for prod in produced {
|
||||
let t = Item::get(&prod.item)
|
||||
.await
|
||||
.ok_or_else(item_does_not_exist_error)?
|
||||
.variant(&prod.variant)
|
||||
.ok_or_else(variant_does_not_exist_error)?;
|
||||
.await
|
||||
.ok_or_else(item_does_not_exist_error)?
|
||||
.variant(&prod.variant)
|
||||
.ok_or_else(variant_does_not_exist_error)?;
|
||||
|
||||
t_create.push((t, prod));
|
||||
}
|
||||
t_create.push((t, prod));
|
||||
}
|
||||
|
||||
for (item, info) in t_create {
|
||||
let t = item
|
||||
.supply(
|
||||
Price::zero(),
|
||||
Some(&format!("flow::{}::{}", self.kind.id(), self._id)),
|
||||
info.location.as_ref().map(|x| x.as_str()),
|
||||
info.note.as_ref().map(|x| x.as_str()),
|
||||
)
|
||||
.await;
|
||||
ret.entry(item.item_variant_id().clone())
|
||||
.or_insert(Vec::new())
|
||||
.push(t._id.clone());
|
||||
produced_ref.push(t.reference());
|
||||
let t = item
|
||||
.supply(
|
||||
Price::zero(),
|
||||
Some(&format!("flow::{}::{}", self.kind.id(), self._id)),
|
||||
info.location.as_ref().map(|x| x.as_str()),
|
||||
info.note.as_ref().map(|x| x.as_str()),
|
||||
)
|
||||
.await;
|
||||
ret.entry(item.item_variant_id().clone())
|
||||
.or_insert(Vec::new())
|
||||
.push(t._id.clone());
|
||||
produced_ref.push(t.reference());
|
||||
}
|
||||
|
||||
self.change()
|
||||
|
|
|
@ -156,6 +156,10 @@ pub async fn end_flow_route(id: &str, form: Json<EndFlow>) -> FallibleApiRespons
|
|||
.await
|
||||
.ok_or_else(|| api_error("Flow not found"))?;
|
||||
|
||||
if flow.done.is_some() {
|
||||
return Err(api_error("Flow already ended"));
|
||||
}
|
||||
|
||||
if let Some(produced) = &form.produced {
|
||||
let prod = flow.end_with_produce(produced).await?;
|
||||
Ok(json!({"produced": prod}))
|
||||
|
@ -175,6 +179,10 @@ pub async fn continue_flow_route(
|
|||
.await
|
||||
.ok_or_else(|| api_error("Flow not found"))?;
|
||||
|
||||
if this_flow.done.is_some() {
|
||||
return Err(api_error("Flow already ended"));
|
||||
}
|
||||
|
||||
// create next flow
|
||||
let next_kind = flows
|
||||
.get(this_flow.kind.id())
|
||||
|
|
Loading…
Add table
Reference in a new issue