Skip to content

Commit b0e8c88

Browse files
authored
fix company optional fields and edit file overrides (#391)
1 parent 7eee05e commit b0e8c88

File tree

8 files changed

+68
-59
lines changed

8 files changed

+68
-59
lines changed

src/blockchain/company/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ pub struct CompanyBlock {
6363
pub struct CompanyCreateBlockData {
6464
pub id: String,
6565
pub name: String,
66-
pub country_of_registration: String,
67-
pub city_of_registration: String,
66+
pub country_of_registration: Option<String>,
67+
pub city_of_registration: Option<String>,
6868
pub postal_address: PostalAddress,
6969
pub email: String,
70-
pub registration_number: String,
71-
pub registration_date: String,
70+
pub registration_number: Option<String>,
71+
pub registration_date: Option<String>,
7272
pub proof_of_registration_file: Option<File>,
7373
pub logo_file: Option<File>,
7474
pub signatories: Vec<String>,

src/dht/client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,12 +1517,12 @@ mod tests {
15171517
Company {
15181518
id: id.to_string(),
15191519
name: "some_name".to_string(),
1520-
country_of_registration: "AT".to_string(),
1521-
city_of_registration: "Vienna".to_string(),
1520+
country_of_registration: Some("AT".to_string()),
1521+
city_of_registration: Some("Vienna".to_string()),
15221522
postal_address: PostalAddress::new_empty(),
15231523
email: "[email protected]".to_string(),
1524-
registration_number: "some_number".to_string(),
1525-
registration_date: "2012-01-01".to_string(),
1524+
registration_number: Some("some_number".to_string()),
1525+
registration_date: Some("2012-01-01".to_string()),
15261526
proof_of_registration_file: None,
15271527
logo_file: None,
15281528
signatories: vec![],

src/persistence/db/company.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ impl CompanyStoreApi for SurrealCompanyStore {
119119
pub struct CompanyDb {
120120
pub id: Thing,
121121
pub name: String,
122-
pub country_of_registration: String,
123-
pub city_of_registration: String,
122+
pub country_of_registration: Option<String>,
123+
pub city_of_registration: Option<String>,
124124
pub postal_address: PostalAddressDb,
125125
pub email: String,
126-
pub registration_number: String,
127-
pub registration_date: String,
126+
pub registration_number: Option<String>,
127+
pub registration_date: Option<String>,
128128
pub proof_of_registration_file: Option<FileDb>,
129129
pub logo_file: Option<FileDb>,
130130
pub signatories: Vec<String>,
@@ -217,12 +217,12 @@ mod tests {
217217
Company {
218218
id: TEST_PUB_KEY_SECP.to_owned(),
219219
name: "some_name".to_string(),
220-
country_of_registration: "AT".to_string(),
221-
city_of_registration: "Vienna".to_string(),
220+
country_of_registration: Some("AT".to_string()),
221+
city_of_registration: Some("Vienna".to_string()),
222222
postal_address: PostalAddress::new_empty(),
223223
email: "[email protected]".to_string(),
224-
registration_number: "some_number".to_string(),
225-
registration_date: "2012-01-01".to_string(),
224+
registration_number: Some("some_number".to_string()),
225+
registration_date: Some("2012-01-01".to_string()),
226226
proof_of_registration_file: None,
227227
logo_file: None,
228228
signatories: vec!["1234".to_string()],

src/persistence/db/company_chain.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ mod tests {
243243
&CompanyToReturn {
244244
id: "some_id".to_string(),
245245
name: "Hayek Ltd".to_string(),
246-
country_of_registration: "AT".to_string(),
247-
city_of_registration: "Vienna".to_string(),
246+
country_of_registration: Some("AT".to_string()),
247+
city_of_registration: Some("Vienna".to_string()),
248248
postal_address: PostalAddress::new_empty(),
249249
email: "[email protected]".to_string(),
250-
registration_number: "123124123".to_string(),
251-
registration_date: "2024-01-01".to_string(),
250+
registration_number: Some("123124123".to_string()),
251+
registration_date: Some("2024-01-01".to_string()),
252252
proof_of_registration_file: None,
253253
logo_file: None,
254254
signatories: vec!["self".to_string()],
@@ -293,12 +293,12 @@ mod tests {
293293
&CompanyToReturn {
294294
id: "some_id".to_string(),
295295
name: "Hayek Ltd".to_string(),
296-
country_of_registration: "AT".to_string(),
297-
city_of_registration: "Vienna".to_string(),
296+
country_of_registration: Some("AT".to_string()),
297+
city_of_registration: Some("Vienna".to_string()),
298298
postal_address: PostalAddress::new_empty(),
299299
email: "[email protected]".to_string(),
300-
registration_number: "123124123".to_string(),
301-
registration_date: "2024-01-01".to_string(),
300+
registration_number: Some("123124123".to_string()),
301+
registration_date: Some("2024-01-01".to_string()),
302302
proof_of_registration_file: None,
303303
logo_file: None,
304304
signatories: vec!["self".to_string()],

src/service/company_service.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ pub trait CompanyServiceApi: Send + Sync {
4646
async fn create_company(
4747
&self,
4848
name: String,
49-
country_of_registration: String,
50-
city_of_registration: String,
49+
country_of_registration: Option<String>,
50+
city_of_registration: Option<String>,
5151
postal_address: PostalAddress,
5252
email: String,
53-
registration_number: String,
54-
registration_date: String,
53+
registration_number: Option<String>,
54+
registration_date: Option<String>,
5555
proof_of_registration_file_upload_id: Option<String>,
5656
logo_file_upload_id: Option<String>,
5757
timestamp: u64,
@@ -209,12 +209,12 @@ impl CompanyServiceApi for CompanyService {
209209
async fn create_company(
210210
&self,
211211
name: String,
212-
country_of_registration: String,
213-
city_of_registration: String,
212+
country_of_registration: Option<String>,
213+
city_of_registration: Option<String>,
214214
postal_address: PostalAddress,
215215
email: String,
216-
registration_number: String,
217-
registration_date: String,
216+
registration_number: Option<String>,
217+
registration_date: Option<String>,
218218
proof_of_registration_file_upload_id: Option<String>,
219219
logo_file_upload_id: Option<String>,
220220
timestamp: u64,
@@ -385,7 +385,10 @@ impl CompanyServiceApi for CompanyService {
385385
&full_identity.key_pair.get_public_key(),
386386
)
387387
.await?;
388-
company.logo_file = logo_file.clone();
388+
// only override the picture, if there is a new one
389+
if logo_file.is_some() {
390+
company.logo_file = logo_file.clone();
391+
}
389392

390393
self.store.update(id, &company).await?;
391394

@@ -603,13 +606,13 @@ impl CompanyServiceApi for CompanyService {
603606
pub struct CompanyToReturn {
604607
pub id: String,
605608
pub name: String,
606-
pub country_of_registration: String,
607-
pub city_of_registration: String,
609+
pub country_of_registration: Option<String>,
610+
pub city_of_registration: Option<String>,
608611
#[serde(flatten)]
609612
pub postal_address: PostalAddress,
610613
pub email: String,
611-
pub registration_number: String,
612-
pub registration_date: String,
614+
pub registration_number: Option<String>,
615+
pub registration_date: Option<String>,
613616
pub proof_of_registration_file: Option<File>,
614617
pub logo_file: Option<File>,
615618
pub signatories: Vec<String>,
@@ -637,12 +640,12 @@ impl CompanyToReturn {
637640
pub struct Company {
638641
pub id: String,
639642
pub name: String,
640-
pub country_of_registration: String,
641-
pub city_of_registration: String,
643+
pub country_of_registration: Option<String>,
644+
pub city_of_registration: Option<String>,
642645
pub postal_address: PostalAddress,
643646
pub email: String,
644-
pub registration_number: String,
645-
pub registration_date: String,
647+
pub registration_number: Option<String>,
648+
pub registration_date: Option<String>,
646649
pub proof_of_registration_file: Option<File>,
647650
pub logo_file: Option<File>,
648651
pub signatories: Vec<String>,
@@ -717,12 +720,12 @@ pub mod tests {
717720
Company {
718721
id: TEST_PUB_KEY_SECP.to_owned(),
719722
name: "some_name".to_string(),
720-
country_of_registration: "AT".to_string(),
721-
city_of_registration: "Vienna".to_string(),
723+
country_of_registration: Some("AT".to_string()),
724+
city_of_registration: Some("Vienna".to_string()),
722725
postal_address: PostalAddress::new_empty(),
723726
email: "[email protected]".to_string(),
724-
registration_number: "some_number".to_string(),
725-
registration_date: "2012-01-01".to_string(),
727+
registration_number: Some("some_number".to_string()),
728+
registration_date: Some("2012-01-01".to_string()),
726729
proof_of_registration_file: None,
727730
logo_file: None,
728731
signatories: vec![TEST_PUB_KEY_SECP.to_string()],
@@ -955,12 +958,12 @@ pub mod tests {
955958
let res = service
956959
.create_company(
957960
"name".to_string(),
958-
"AT".to_string(),
959-
"Vienna".to_string(),
961+
Some("AT".to_string()),
962+
Some("Vienna".to_string()),
960963
PostalAddress::new_empty(),
961964
"[email protected]".to_string(),
962-
"some_number".to_string(),
963-
"2012-01-01".to_string(),
965+
Some("some_number".to_string()),
966+
Some("2012-01-01".to_string()),
964967
Some("some_file_id".to_string()),
965968
Some("some_other_file_id".to_string()),
966969
1731593928,
@@ -1019,12 +1022,12 @@ pub mod tests {
10191022
let res = service
10201023
.create_company(
10211024
"name".to_string(),
1022-
"AT".to_string(),
1023-
"Vienna".to_string(),
1025+
Some("AT".to_string()),
1026+
Some("Vienna".to_string()),
10241027
PostalAddress::new_empty(),
10251028
"[email protected]".to_string(),
1026-
"some_number".to_string(),
1027-
"2012-01-01".to_string(),
1029+
Some("some_number".to_string()),
1030+
Some("2012-01-01".to_string()),
10281031
None,
10291032
None,
10301033
1731593928,

src/service/contact_service.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ impl ContactServiceApi for ContactService {
239239
let avatar_file = self
240240
.process_upload_file(&avatar_file_upload_id, node_id, &identity_public_key)
241241
.await?;
242-
contact.avatar_file = avatar_file;
242+
// only override the picture, if there is a new one
243+
if avatar_file.is_some() {
244+
contact.avatar_file = avatar_file;
245+
}
243246

244247
self.store.update(node_id, contact).await?;
245248

src/service/identity_service.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ impl IdentityServiceApi for IdentityService {
271271
&keys.get_public_key(),
272272
)
273273
.await?;
274-
identity.profile_picture_file = profile_picture_file.clone();
274+
// only override the picture, if there is a new one
275+
if profile_picture_file.is_some() {
276+
identity.profile_picture_file = profile_picture_file.clone();
277+
}
275278

276279
let previous_block = self.blockchain_store.get_latest_block().await?;
277280
let new_block = IdentityBlock::create_block_for_update(

src/web/data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ pub struct SeedPhrase {
467467
#[derive(Debug, Serialize, Deserialize, Clone)]
468468
pub struct CreateCompanyPayload {
469469
pub name: String,
470-
pub country_of_registration: String,
471-
pub city_of_registration: String,
470+
pub country_of_registration: Option<String>,
471+
pub city_of_registration: Option<String>,
472472
#[serde(flatten)]
473473
pub postal_address: PostalAddress,
474474
pub email: String,
475-
pub registration_number: String,
476-
pub registration_date: String,
475+
pub registration_number: Option<String>,
476+
pub registration_date: Option<String>,
477477
pub proof_of_registration_file_upload_id: Option<String>,
478478
pub logo_file_upload_id: Option<String>,
479479
}

0 commit comments

Comments
 (0)