Skip to content

Commit ed4321f

Browse files
authored
Make all fields editable company identity contact (#392)
* identity * contacts * company
1 parent cbf8fd1 commit ed4321f

File tree

12 files changed

+344
-109
lines changed

12 files changed

+344
-109
lines changed

src/blockchain/company/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ pub struct CompanyUpdateBlockData {
9797
pub name: Option<String>,
9898
pub email: Option<String>,
9999
pub postal_address: OptionalPostalAddress,
100+
pub country_of_registration: Option<String>,
101+
pub city_of_registration: Option<String>,
102+
pub registration_number: Option<String>,
103+
pub registration_date: Option<String>,
100104
pub logo_file: Option<File>,
105+
pub proof_of_registration_file: Option<File>,
101106
}
102107

103108
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq)]
@@ -506,7 +511,12 @@ mod tests {
506511
name: Some("new_name".to_string()),
507512
email: None,
508513
postal_address: OptionalPostalAddress::new_empty(),
514+
country_of_registration: None,
515+
city_of_registration: None,
516+
registration_number: None,
517+
registration_date: None,
509518
logo_file: None,
519+
proof_of_registration_file: None,
510520
},
511521
&identity_keys,
512522
&company_keys,

src/blockchain/identity/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ pub struct IdentityUpdateBlockData {
7979
pub name: Option<String>,
8080
pub email: Option<String>,
8181
pub postal_address: OptionalPostalAddress,
82+
pub date_of_birth: Option<String>,
83+
pub country_of_birth: Option<String>,
84+
pub city_of_birth: Option<String>,
85+
pub identification_number: Option<String>,
8286
pub profile_picture_file: Option<File>,
87+
pub identity_document_file: Option<File>,
8388
}
8489

8590
#[derive(BorshSerialize, BorshDeserialize, Debug, Clone, PartialEq)]
@@ -410,7 +415,12 @@ mod tests {
410415
name: Some("newname".to_string()),
411416
email: None,
412417
postal_address: OptionalPostalAddress::new_empty(),
418+
date_of_birth: None,
419+
country_of_birth: None,
420+
city_of_birth: None,
421+
identification_number: None,
413422
profile_picture_file: None,
423+
identity_document_file: None,
414424
},
415425
&keys,
416426
1731593928,

src/persistence/db/company_chain.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ mod tests {
271271
name: None,
272272
email: None,
273273
postal_address: OptionalPostalAddress::new_empty(),
274+
country_of_registration: None,
275+
city_of_registration: None,
276+
registration_number: None,
277+
registration_date: None,
274278
logo_file: None,
279+
proof_of_registration_file: None,
275280
},
276281
&BcrKeys::new(),
277282
&get_company_keys(),

src/persistence/db/identity_chain.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ mod tests {
209209
name: None,
210210
email: None,
211211
postal_address: OptionalPostalAddress::new_empty(),
212+
date_of_birth: None,
213+
country_of_birth: None,
214+
city_of_birth: None,
215+
identification_number: None,
212216
profile_picture_file: None,
217+
identity_document_file: None,
213218
},
214219
&BcrKeys::new(),
215220
1731593928,

src/service/company_service.rs

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ pub trait CompanyServiceApi: Send + Sync {
6464
name: Option<String>,
6565
email: Option<String>,
6666
postal_address: OptionalPostalAddress,
67+
country_of_registration: Option<String>,
68+
city_of_registration: Option<String>,
69+
registration_number: Option<String>,
70+
registration_date: Option<String>,
6771
logo_file_upload_id: Option<String>,
72+
proof_of_registration_file_upload_id: Option<String>,
6873
timestamp: u64,
6974
) -> Result<()>;
7075

@@ -313,7 +318,12 @@ impl CompanyServiceApi for CompanyService {
313318
name: Option<String>,
314319
email: Option<String>,
315320
postal_address: OptionalPostalAddress,
321+
country_of_registration: Option<String>,
322+
city_of_registration: Option<String>,
323+
registration_number: Option<String>,
324+
registration_date: Option<String>,
316325
logo_file_upload_id: Option<String>,
326+
proof_of_registration_file_upload_id: Option<String>,
317327
timestamp: u64,
318328
) -> Result<()> {
319329
if !self.store.exists(id).await {
@@ -351,30 +361,45 @@ impl CompanyServiceApi for CompanyService {
351361
changed = true;
352362
}
353363

354-
match company.postal_address.zip {
355-
Some(_) => {
356-
if let Some(ref postal_address_zip_to_set) = postal_address.zip {
357-
company.postal_address.zip = Some(postal_address_zip_to_set.clone());
358-
changed = true;
359-
} else {
360-
company.postal_address.zip = None;
361-
changed = true;
362-
}
363-
}
364-
None => {
365-
if let Some(ref postal_address_zip_to_set) = postal_address.zip {
366-
company.postal_address.zip = Some(postal_address_zip_to_set.clone());
367-
changed = true;
368-
}
369-
}
370-
};
364+
util::update_optional_field(
365+
&mut company.postal_address.zip,
366+
&postal_address.zip,
367+
&mut changed,
368+
);
369+
370+
util::update_optional_field(
371+
&mut company.country_of_registration,
372+
&country_of_registration,
373+
&mut changed,
374+
);
375+
376+
util::update_optional_field(
377+
&mut company.city_of_registration,
378+
&city_of_registration,
379+
&mut changed,
380+
);
381+
382+
util::update_optional_field(
383+
&mut company.registration_date,
384+
&registration_date,
385+
&mut changed,
386+
);
387+
388+
util::update_optional_field(
389+
&mut company.registration_number,
390+
&registration_number,
391+
&mut changed,
392+
);
371393

372394
if let Some(ref postal_address_address_to_set) = postal_address.address {
373395
company.postal_address.address = postal_address_address_to_set.clone();
374396
changed = true;
375397
}
376398

377-
if !changed && logo_file_upload_id.is_none() {
399+
if !changed
400+
&& logo_file_upload_id.is_none()
401+
&& proof_of_registration_file_upload_id.is_none()
402+
{
378403
return Ok(());
379404
}
380405

@@ -389,6 +414,17 @@ impl CompanyServiceApi for CompanyService {
389414
if logo_file.is_some() {
390415
company.logo_file = logo_file.clone();
391416
}
417+
let proof_of_registration_file = self
418+
.process_upload_file(
419+
&proof_of_registration_file_upload_id,
420+
id,
421+
&full_identity.key_pair.get_public_key(),
422+
)
423+
.await?;
424+
// only override the document, if there is a new one
425+
if proof_of_registration_file.is_some() {
426+
company.proof_of_registration_file = proof_of_registration_file.clone();
427+
}
392428

393429
self.store.update(id, &company).await?;
394430

@@ -400,7 +436,12 @@ impl CompanyServiceApi for CompanyService {
400436
name,
401437
email,
402438
postal_address,
439+
country_of_registration,
440+
city_of_registration,
441+
registration_number,
442+
registration_date,
403443
logo_file,
444+
proof_of_registration_file,
404445
},
405446
&full_identity.key_pair,
406447
&company_keys,
@@ -1101,7 +1142,12 @@ pub mod tests {
11011142
Some("name".to_string()),
11021143
Some("[email protected]".to_string()),
11031144
OptionalPostalAddress::new_empty(),
1145+
None,
1146+
None,
1147+
None,
1148+
None,
11041149
Some("some_file_id".to_string()),
1150+
None,
11051151
1731593928,
11061152
)
11071153
.await;
@@ -1134,6 +1180,11 @@ pub mod tests {
11341180
Some("[email protected]".to_string()),
11351181
OptionalPostalAddress::new_empty(),
11361182
None,
1183+
None,
1184+
None,
1185+
None,
1186+
None,
1187+
None,
11371188
1731593928,
11381189
)
11391190
.await;
@@ -1178,6 +1229,11 @@ pub mod tests {
11781229
Some("[email protected]".to_string()),
11791230
OptionalPostalAddress::new_empty(),
11801231
None,
1232+
None,
1233+
None,
1234+
None,
1235+
None,
1236+
None,
11811237
1731593928,
11821238
)
11831239
.await;
@@ -1235,6 +1291,11 @@ pub mod tests {
12351291
Some("[email protected]".to_string()),
12361292
OptionalPostalAddress::new_empty(),
12371293
None,
1294+
None,
1295+
None,
1296+
None,
1297+
None,
1298+
None,
12381299
1731593928,
12391300
)
12401301
.await;

src/service/contact_service.rs

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ pub trait ContactServiceApi: Send + Sync {
4343
name: Option<String>,
4444
email: Option<String>,
4545
postal_address: OptionalPostalAddress,
46+
date_of_birth_or_registration: Option<String>,
47+
country_of_birth_or_registration: Option<String>,
48+
city_of_birth_or_registration: Option<String>,
49+
identification_number: Option<String>,
4650
avatar_file_upload_id: Option<String>,
51+
proof_document_file_upload_id: Option<String>,
4752
) -> Result<()>;
4853

4954
/// Adds a new contact
@@ -177,7 +182,12 @@ impl ContactServiceApi for ContactService {
177182
name: Option<String>,
178183
email: Option<String>,
179184
postal_address: OptionalPostalAddress,
185+
date_of_birth_or_registration: Option<String>,
186+
country_of_birth_or_registration: Option<String>,
187+
city_of_birth_or_registration: Option<String>,
188+
identification_number: Option<String>,
180189
avatar_file_upload_id: Option<String>,
190+
proof_document_file_upload_id: Option<String>,
181191
) -> Result<()> {
182192
let mut contact = match self.store.get(node_id).await? {
183193
Some(contact) => contact,
@@ -209,30 +219,42 @@ impl ContactServiceApi for ContactService {
209219
changed = true;
210220
}
211221

212-
match contact.postal_address.zip {
213-
Some(_) => {
214-
if let Some(ref postal_address_zip_to_set) = postal_address.zip {
215-
contact.postal_address.zip = Some(postal_address_zip_to_set.clone());
216-
changed = true;
217-
} else {
218-
contact.postal_address.zip = None;
219-
changed = true;
220-
}
221-
}
222-
None => {
223-
if let Some(ref postal_address_zip_to_set) = postal_address.zip {
224-
contact.postal_address.zip = Some(postal_address_zip_to_set.clone());
225-
changed = true;
226-
}
227-
}
228-
};
222+
util::update_optional_field(
223+
&mut contact.postal_address.zip,
224+
&postal_address.zip,
225+
&mut changed,
226+
);
229227

230228
if let Some(ref postal_address_address_to_set) = postal_address.address {
231229
contact.postal_address.address = postal_address_address_to_set.clone();
232230
changed = true;
233231
}
234232

235-
if !changed && avatar_file_upload_id.is_none() {
233+
util::update_optional_field(
234+
&mut contact.date_of_birth_or_registration,
235+
&date_of_birth_or_registration,
236+
&mut changed,
237+
);
238+
239+
util::update_optional_field(
240+
&mut contact.country_of_birth_or_registration,
241+
&country_of_birth_or_registration,
242+
&mut changed,
243+
);
244+
245+
util::update_optional_field(
246+
&mut contact.city_of_birth_or_registration,
247+
&city_of_birth_or_registration,
248+
&mut changed,
249+
);
250+
251+
util::update_optional_field(
252+
&mut contact.identification_number,
253+
&identification_number,
254+
&mut changed,
255+
);
256+
257+
if !changed && avatar_file_upload_id.is_none() && proof_document_file_upload_id.is_none() {
236258
return Ok(());
237259
}
238260

@@ -243,6 +265,17 @@ impl ContactServiceApi for ContactService {
243265
if avatar_file.is_some() {
244266
contact.avatar_file = avatar_file;
245267
}
268+
let proof_document_file = self
269+
.process_upload_file(
270+
&proof_document_file_upload_id,
271+
node_id,
272+
&identity_public_key,
273+
)
274+
.await?;
275+
// only override the document, if there is a new one
276+
if proof_document_file.is_some() {
277+
contact.proof_document_file = proof_document_file;
278+
}
246279

247280
self.store.update(node_id, contact).await?;
248281

@@ -612,6 +645,11 @@ pub mod tests {
612645
None,
613646
OptionalPostalAddress::new_empty(),
614647
None,
648+
None,
649+
None,
650+
None,
651+
None,
652+
None,
615653
)
616654
.await;
617655
assert!(result.is_ok());

0 commit comments

Comments
 (0)