evergreen/common/
holdings.rs

1use crate as eg;
2use eg::Editor;
3use eg::EgResult;
4use eg::EgValue;
5
6/// Extract the copy status from either a potentially-fleshed copy object
7/// of from the in-database copy by ID.
8pub fn copy_status(
9    editor: &mut Editor,
10    copy_id: Option<i64>,
11    copy: Option<&EgValue>,
12) -> EgResult<i64> {
13    if let Some(copy) = copy {
14        if let Ok(id) = copy["status"].id() {
15            Ok(id)
16        } else {
17            copy["status"].int()
18        }
19    } else if let Some(id) = copy_id {
20        let copy = editor
21            .retrieve("acp", id)?
22            .ok_or_else(|| editor.die_event())?;
23
24        copy["status"].int()
25    } else {
26        Err("copy_status() requires a useful parameter".into())
27    }
28}