1
//! The user's zone, which report dates are read in.
2

            
3
use server::command::CmdResult;
4
use server::command::config::GetTimezone;
5
use server::timezone::Tz;
6
use uuid::Uuid;
7

            
8
use super::Failure;
9

            
10
const CTX: &str = "report";
11

            
12
/// The zone of `user_id`'s reports; UTC when they set none.
13
///
14
/// # Errors
15
/// A refusal when the stored value is not a zone, an internal failure otherwise.
16
34768
pub async fn user_zone(user_id: Uuid) -> Result<Tz, Failure> {
17
34768
    match GetTimezone::new()
18
34768
        .user_id(user_id)
19
34768
        .run()
20
34768
        .await
21
641
        .map_err(|err| Failure::from_command(CTX, err))?
22
    {
23
34127
        Some(CmdResult::Timezone(zone)) => Ok(zone),
24
        _ => Err(Failure::Internal(wasmtime::Error::msg(
25
            "get-timezone: unexpected result",
26
        ))),
27
    }
28
34768
}