postmasterlib/dto/
user_role.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use chrono::{NaiveDateTime, Utc};
use common::enums::r_status::RStatus;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UserRole {
    pub name: Option<String>,
    pub is_collaborator: Option<i32>,
    pub priority: i32,
    pub updt: Option<NaiveDateTime>,
    pub ver: i32,
    pub is_first_login: Option<bool>,
    pub need_help: Option<bool>,
    pub parent_type: Option<i32>,
    #[serde(rename = "id")]
    pub uuid: Uuid,
    pub updu: Option<Uuid>,
    #[serde(rename = "user")]
    pub user_t: Uuid,
    pub organization: Uuid,
    pub child: Option<Uuid>,
    pub school_class: Option<Uuid>,
    #[serde(rename = "role")]
    pub role_name: String,
    #[serde(rename = "status")]
    pub status_name: String,
    pub rstatus: Option<RStatus>,
}

impl UserRole {
    pub fn by_role_and_user(user_t: Uuid, role: String, updu: Uuid, org_id: Uuid) -> UserRole {
        UserRole {
            name: None,
            is_collaborator: None,
            priority: 0,
            updt: Option::from(Utc::now().naive_local()),
            ver: 0,
            is_first_login: Option::from(true),
            need_help: None,
            parent_type: None,
            uuid: Uuid::new_v4(),
            updu: Option::from(updu),
            user_t,
            organization: org_id,
            child: None,
            school_class: None,
            role_name: role,
            status_name: String::from("Confirmed"),
            rstatus: Option::from(RStatus::Active),
        }
    }
}