Skip to content

Commit

Permalink
feat(be):
Browse files Browse the repository at this point in the history
- As decribed in FSADT1-999
  • Loading branch information
mamartinezmejia committed Nov 20, 2023
1 parent f029b3f commit 3f8b579
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
@With
public class ClientTypeCodeEntity extends ExpirableBaseEntity {

public static final String UNREGISTERED_SOLE_PROPRIETORSHIP = "USP";
public static final String REGISTERED_SOLE_PROPRIETORSHIP = "RSP";

@Id
@Column("client_type_code")
private String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ca.bc.gov.app.validator.client;

import static ca.bc.gov.app.util.ClientValidationUtils.fieldIsMissingErrorMessage;

import java.time.LocalDate;
import ca.bc.gov.app.dto.client.BusinessTypeEnum;
import ca.bc.gov.app.dto.client.ClientBusinessInformationDto;
import ca.bc.gov.app.dto.client.ClientLocationDto;
import ca.bc.gov.app.dto.client.ClientSubmissionDto;
import ca.bc.gov.app.entity.client.ClientTypeCodeEntity;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -59,6 +60,13 @@ else if (!EnumUtils.isValidEnum(BusinessTypeEnum.class, businessType)) {
errors.popNestedPath();
return;
}

String clientType = businessInformation.clientType();
if (!StringUtils.isAllBlank(clientType) &&
(ClientTypeCodeEntity.REGISTERED_SOLE_PROPRIETORSHIP.equals(clientType) ||
ClientTypeCodeEntity.UNREGISTERED_SOLE_PROPRIETORSHIP.equals(clientType))) {
validateBirthdate(businessInformation.birthdate(), errors);
}

errors.popNestedPath();

Expand All @@ -72,6 +80,19 @@ else if (!EnumUtils.isValidEnum(BusinessTypeEnum.class, businessType)) {
}
}

private void validateBirthdate(LocalDate birthdate, Errors errors) {
String dobFieldName = "birthdate";
if (birthdate == null) {
errors.rejectValue(dobFieldName, fieldIsMissingErrorMessage("Birthdate"));
}
else {
LocalDate minAgeDate = LocalDate.now().minusYears(18);
if (birthdate.isAfter(minAgeDate)) {
errors.rejectValue(dobFieldName, "Sole proprietorship must be at least 18 years old");
}
}
}

private void validateLocation(ClientLocationDto location, Errors errors) {

String locationField = "location";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/test/java/ca/bc/gov/app/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public class TestConstants {
"P",
"Y",
"GP",
null
LocalDate.now()
),
new ClientLocationDto(
List.of(
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/FormBCeIDPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ let formDataDto = ref<FormDataDto>({ ...newFormDataDto() });
//---- Form Data ----//
let formData = reactive<FormDataDto>({
...formDataDto.value,
businessInformation: {
...formDataDto.value.businessInformation,
birthdate: "",
},
location: {
addresses: formDataDto.value.location.addresses,
contacts: [submitterContact],
Expand Down

0 comments on commit 3f8b579

Please sign in to comment.