Skip to content

Commit

Permalink
Merge pull request #60 from IliyanIlievPH/master
Browse files Browse the repository at this point in the history
Make partner contact fields optional
  • Loading branch information
IliyanIlievPH committed Jun 29, 2020
2 parents ee3abe9 + 3faabcc commit ad2a2d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ public async Task CreateLocationsContactPersonForPartnerAsync(Partner partner)

_log.Info("Location creating", context: $"location: {location.ToJson()}");

if(location.ContactPerson != null && !string.IsNullOrEmpty(location.ContactPerson.Email))
if (location.ContactPerson != null && (!string.IsNullOrEmpty(location.ContactPerson.Email) ||
!string.IsNullOrEmpty(location.ContactPerson.FirstName) ||
!string.IsNullOrEmpty(location.ContactPerson.LastName) ||
!string.IsNullOrEmpty(location.ContactPerson.PhoneNumber)))
{
customerProfileCreateActions.Add(CreateOrUpdatePartnerContact(location));
}
}

await Task.WhenAll(customerProfileCreateActions);
Expand Down Expand Up @@ -120,8 +125,14 @@ public async Task CreateLocationsContactPersonForPartnerAsync(Partner partner)
await SetCountryIso3Code(location);

_log.Info("Location updating", context: $"location: {location.ToJson()}");
if (location.ContactPerson != null && !string.IsNullOrEmpty(location.ContactPerson.Email))

if (location.ContactPerson != null && (!string.IsNullOrEmpty(location.ContactPerson.Email) ||
!string.IsNullOrEmpty(location.ContactPerson.FirstName) ||
!string.IsNullOrEmpty(location.ContactPerson.LastName) ||
!string.IsNullOrEmpty(location.ContactPerson.PhoneNumber)))
{
customerProfileUpdateActions.Add(CreateOrUpdatePartnerContact(location));
}
else
deleteActions.Add(_customerProfileClient.PartnerContact.DeleteIfExistAsync(location.Id.ToString()));
}
Expand All @@ -138,8 +149,13 @@ public async Task CreateLocationsContactPersonForPartnerAsync(Partner partner)

_log.Info("Location creating", context: $"location: {location.ToJson()}");

if (location.ContactPerson != null && !string.IsNullOrEmpty(location.ContactPerson.Email))
if (location.ContactPerson != null && (!string.IsNullOrEmpty(location.ContactPerson.Email) ||
!string.IsNullOrEmpty(location.ContactPerson.FirstName) ||
!string.IsNullOrEmpty(location.ContactPerson.LastName) ||
!string.IsNullOrEmpty(location.ContactPerson.PhoneNumber)))
{
customerProfileCreateActions.Add(CreateOrUpdatePartnerContact(location));
}
}
}

Expand Down Expand Up @@ -185,7 +201,7 @@ private async Task CreateOrUpdatePartnerContact(Location location)
LocationId = location.Id.ToString(),
FirstName = location.ContactPerson.FirstName,
LastName = location.ContactPerson.LastName,
Email = location.ContactPerson.Email.ToLower(),
Email = location.ContactPerson.Email?.ToLower(),
PhoneNumber = location.ContactPerson.PhoneNumber
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<PackageReference Include="geohash-dotnet" Version="1.0.4" />
<PackageReference Include="Lykke.RabbitMqBroker" Version="7.13.2" />
<PackageReference Include="MAVN.Service.Credentials.Client" Version="1.1.0" />
<PackageReference Include="MAVN.Service.CustomerProfile.Client" Version="2.0.0" />
<PackageReference Include="MAVN.Service.CustomerProfile.Client" Version="2.2.0" />
<PackageReference Include="MAVN.Service.PaymentManagement.Client" Version="1.18.0" />
<PackageReference Include="MAVN.Service.Referral.Client" Version="2.0.0" />
<PackageReference Include="MAVN.Service.Kyc.Client" Version="2.1.0" />
<PackageReference Include="MAVN.Service.Kyc.Client" Version="2.2.0" />
<PackageReference Include="MAVN.Service.Sessions.Client" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,31 @@ public class ContactPersonModelValidation : AbstractValidator<ContactPersonModel
public ContactPersonModelValidation()
{
RuleFor(p => p.FirstName)
.NotNull()
.NotEmpty()
.When(x => !string.IsNullOrEmpty(x.Email) || !string.IsNullOrEmpty(x.LastName) || !string.IsNullOrEmpty(x.PhoneNumber))
.MinimumLength(2)
.MaximumLength(50)
.WithMessage("The First Name should be present and within a range of 2 to 50 characters long.")
.Must(o => o != null && _onlyLettersRegex.IsMatch(o))
.WithMessage("First Name should contains only letters");
.WithMessage("First Name should contains only letters")
.When(x => !string.IsNullOrEmpty(x.FirstName));

RuleFor(p => p.LastName)
.NotNull()
.NotEmpty()
.When(x => !string.IsNullOrEmpty(x.Email) || !string.IsNullOrEmpty(x.FirstName) || !string.IsNullOrEmpty(x.PhoneNumber))
.MinimumLength(2)
.MaximumLength(50)
.WithMessage("The Last Name should be present and within a range of 2 to 50 characters long.")
.Must(o => o != null && _onlyLettersRegex.IsMatch(o))
.WithMessage("Last Name should contains only letters");
.WithMessage("Last Name should contains only letters")
.When(x => !string.IsNullOrEmpty(x.LastName));

RuleFor(p => p.Email)
.NotNull()
.NotEmpty()
.When(x => !string.IsNullOrEmpty(x.FirstName) || !string.IsNullOrEmpty(x.LastName) || !string.IsNullOrEmpty(x.PhoneNumber))
.EmailAddress()
.WithMessage("The Email should be present and within a valid email address.");
.WithMessage("The Email should be present and within a valid email address.")
.When(x => !string.IsNullOrEmpty(x.Email));

RuleFor(p => p.PhoneNumber)
.NotNull()
.NotEmpty()
.When(x => !string.IsNullOrEmpty(x.Email) || !string.IsNullOrEmpty(x.FirstName) || !string.IsNullOrEmpty(x.LastName))
.MinimumLength(3)
.MaximumLength(30)
.WithMessage("The Phone number should be present and within a range of 3 to 30 characters long.");
.WithMessage("The Phone number should be present and within a range of 3 to 30 characters long.")
.When(x => !string.IsNullOrEmpty(x.PhoneNumber));
}
}
}

0 comments on commit ad2a2d7

Please sign in to comment.