qm_entity/
ctx.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// use crate::ids::OrganizationUnitId;

// use crate::ids::{CustomerResourceId, OrganizationResourceId};

// CustomerFilter is used when filtering from the perspective of a customer using no filter or from the perspective of
// an admin filtering for a specific customer
// #[derive(Default, Debug, Clone, InputObject, Serialize, Deserialize)]
// pub struct CustomerFilter {
//     pub customer: InfraId,
// }

// OrganizationFilter is used when filtering from the perspective of a organization using no filter, from the
// perspective of an admin or a customer filtering for a specific organization
// #[derive(Default, Debug, Clone, InputObject, Serialize, Deserialize)]
// pub struct OrganizationFilter {
//     pub customer: InfraId,
//     pub organization: InfraId,
// }

// impl From<CustomerResourceId> for OrganizationFilter {
//     fn from(value: CustomerResourceId) -> Self {
//         OrganizationFilter {
//             customer: value.cid,
//             organization: value.id,
//         }
//     }
// }

// impl From<OrganizationFilter> for CustomerResourceId {
//     fn from(value: OrganizationFilter) -> Self {
//         Self {
//             cid: value.customer,
//             id: value.organization,
//         }
//     }
// }

// OrganizationUnitFilter is used when filtering from the perspective of a organization using no filter, from the
// perspective of an admin or a customer filtering for a specific organization
// #[derive(Default, Debug, Clone, InputObject, Serialize, Deserialize)]
// pub struct OrganizationUnitFilter {
//     pub customer: InfraId,
//     pub organization: Option<InfraId>,
//     pub organization_unit: InfraId,
// }

// impl From<OrganizationUnitId> for OrganizationUnitFilter {
//     fn from(value: OrganizationUnitId) -> Self {
//         match value {
//             OrganizationUnitId::Customer(v) => OrganizationUnitFilter {
//                 customer: v.cid,
//                 organization: None,
//                 organization_unit: v.id,
//             },
//             OrganizationUnitId::Organization(v) => OrganizationUnitFilter {
//                 customer: v.cid,
//                 organization: Some(v.oid),
//                 organization_unit: v.id,
//             },
//         }
//     }
// }

// impl From<OrganizationUnitFilter> for OrganizationUnitId {
//     fn from(value: OrganizationUnitFilter) -> Self {
//         if let Some(organization) = value.organization {
//             OrganizationUnitId::Organization(OrganizationResourceId {
//                 cid: value.customer,
//                 oid: organization,
//                 id: value.organization_unit,
//             })
//         } else {
//             OrganizationUnitId::Customer(CustomerResourceId {
//                 cid: value.customer,
//                 id: value.organization_unit,
//             })
//         }
//     }
// }

// InstitutionFilter is used when filtering from the perspective of a institution using no filter, from the perspective
// of an admin, a customer or an organization filtering for a specific institution
// #[derive(Default, Debug, Clone, InputObject, Serialize, Deserialize)]
// pub struct InstitutionFilter {
//     pub customer: InfraId,
//     pub organization: InfraId,
//     pub institution: InfraId,
// }

// impl From<OrganizationResourceId> for InstitutionFilter {
//     fn from(value: OrganizationResourceId) -> Self {
//         InstitutionFilter {
//             customer: value.cid,
//             organization: value.oid,
//             institution: value.id,
//         }
//     }
// }

// impl From<InstitutionFilter> for OrganizationResourceId {
//     fn from(value: InstitutionFilter) -> Self {
//         Self {
//             cid: value.customer,
//             oid: value.organization,
//             id: value.institution,
//         }
//     }
// }

// #[derive(Debug, Clone, Serialize, Deserialize, OneofObject)]
// pub enum OrgOrInstFilter {
//     Organization(OrganizationFilter),
//     Institution(InstitutionFilter),
// }

// /// Oneof input object in GraphQL
// /// Oneof input objects requires have exactly one field
// #[derive(Debug, Clone, Serialize, Deserialize, OneofObject)]
// pub enum CustOrOrgFilter {
//     #[graphql(name = "customerFilter")]
//     Customer(CustomerFilter),
//     #[graphql(name = "organizationFilter")]
//     Organization(OrganizationFilter),
// }

// /// Oneof input object in GraphQL
// /// Oneof input objects requires have exactly one field
// #[derive(Debug, Clone, Serialize, Deserialize, OneofObject)]
// pub enum ContextFilterInput {
//     #[graphql(name = "customerFilter")]
//     Customer(CustomerFilter),
//     #[graphql(name = "organizationFilter")]
//     Organization(OrganizationFilter),
//     #[graphql(name = "organizationUnitFilter")]
//     OrganizationUnit(OrganizationUnitFilter),
//     #[graphql(name = "institutionFilter")]
//     Institution(InstitutionFilter),
// }

// impl From<CustOrOrgFilter> for ContextFilterInput {
//     fn from(value: CustOrOrgFilter) -> Self {
//         match value {
//             CustOrOrgFilter::Customer(v) => ContextFilterInput::Customer(v),
//             CustOrOrgFilter::Organization(v) => ContextFilterInput::Organization(v),
//         }
//     }
// }

// impl std::fmt::Display for ContextFilterInput {
//     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
//         match self {
//             Self::Customer(CustomerFilter { customer }) => write!(f, "{}", customer.to_hex()),
//             Self::Organization(OrganizationFilter {
//                 customer,
//                 organization,
//             }) => write!(f, "{}{}", customer.to_hex(), organization.to_hex()),
//             Self::OrganizationUnit(OrganizationUnitFilter {
//                 customer,
//                 organization: Some(organization),
//                 organization_unit,
//             }) => write!(
//                 f,
//                 "{}{}{}",
//                 customer.to_hex(),
//                 organization.to_hex(),
//                 organization_unit.to_hex()
//             ),
//             Self::OrganizationUnit(OrganizationUnitFilter {
//                 customer,
//                 organization: None,
//                 organization_unit,
//             }) => write!(f, "{}{}", customer.to_hex(), organization_unit.to_hex()),
//             Self::Institution(InstitutionFilter {
//                 customer,
//                 organization,
//                 institution,
//             }) => write!(
//                 f,
//                 "{}{}{}",
//                 customer.to_hex(),
//                 organization.to_hex(),
//                 institution.to_hex()
//             ),
//         }
//     }
// }

// impl ContextFilterInput {
//     pub fn cid(&self) -> &i64 {
//         match self {
//             ContextFilterInput::Customer(v) => v.customer.as_ref(),
//             ContextFilterInput::Organization(v) => v.customer.as_ref(),
//             ContextFilterInput::OrganizationUnit(v) => v.customer.as_ref(),
//             ContextFilterInput::Institution(v) => v.customer.as_ref(),
//         }
//     }
// }

// #[derive(Debug, Clone, Serialize, Deserialize)]
// pub enum MutationContext {
//     Customer(CustomerFilter),
//     Organization(OrganizationFilter),
//     OrganizationUnit(OrganizationUnitFilter),
//     Institution(InstitutionFilter),
// }

// impl Into<OwnerId> for CustomerFilter {
//     fn into(self) -> OwnerId {
//         OwnerId {
//             cid: Some(self.customer.into()),
//             ..Default::default()
//         }
//     }
// }

// impl Into<OwnerId> for OrganizationFilter {
//     fn into(self) -> OwnerId {
//         OwnerId {
//             cid: Some(self.customer.into()),
//             oid: Some(self.organization.into()),
//             ..Default::default()
//         }
//     }
// }

// impl Into<OwnerId> for OrganizationUnitFilter {
//     fn into(self) -> OwnerId {
//         OwnerId {
//             cid: Some(self.customer.into()),
//             oid: self.organization.map(Into::into),
//             uid: Some(self.organization_unit.into()),
//             ..Default::default()
//         }
//     }
// }

// impl Into<OwnerId> for InstitutionFilter {
//     fn into(self) -> OwnerId {
//         OwnerId {
//             cid: Some(self.customer.into()),
//             oid: Some(self.organization.into()),
//             iid: Some(self.institution.into()),
//             ..Default::default()
//         }
//     }
// }