Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class VolunteeringRelationship {
@Schema(description = "id of the organization with the relationship")
private UUID organizationId;

@NotNull
@Nullable
@Column(name = "start_date")
@TypeDef(type = DataType.DATE, converter = LocalDateConverter.class)
@Schema(description = "when the relationship started")
Expand All @@ -67,11 +67,11 @@ public class VolunteeringRelationship {
@Schema(description = "whether the Volunteering Relationship is active")
private boolean active = true;

public VolunteeringRelationship(UUID memberId, UUID organizationId, LocalDate startDate, @Nullable LocalDate endDate) {
public VolunteeringRelationship(UUID memberId, UUID organizationId, @Nullable LocalDate startDate, @Nullable LocalDate endDate) {
this(null, memberId, organizationId, startDate, endDate, true);
}

public VolunteeringRelationship(UUID memberId, UUID organizationId, LocalDate startDate, @Nullable LocalDate endDate, boolean active) {
public VolunteeringRelationship(UUID memberId, UUID organizationId, @Nullable LocalDate startDate, @Nullable LocalDate endDate, boolean active) {
this(null, memberId, organizationId, startDate, endDate, active);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class VolunteeringRelationshipDTO {
@Schema(description = "id of the organization with the relationship")
private UUID organizationId;

@NotNull
@Nullable
@Schema(description = "when the relationship started")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate startDate;
Expand All @@ -40,7 +40,7 @@ public class VolunteeringRelationshipDTO {
@Schema(description = "whether the Volunteering Relationship is active")
private Boolean active;

public VolunteeringRelationshipDTO(@NotNull UUID memberId, @NotNull UUID organizationId, @NotNull LocalDate startDate, @Nullable LocalDate endDate) {
public VolunteeringRelationshipDTO(@NotNull UUID memberId, @NotNull UUID organizationId, @Nullable LocalDate startDate, @Nullable LocalDate endDate) {
this(memberId, organizationId, startDate, endDate, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ JOIN volunteering_organization AS org USING(organization_id)
AND rel.member_id = :memberId
AND (rel.is_active = TRUE OR :includeDeactivated = TRUE)
AND (org.is_active = TRUE OR :includeDeactivated = TRUE)
ORDER BY rel.start_date, org.name""", nativeQuery = true)
ORDER BY org.name""", nativeQuery = true)
List<VolunteeringRelationship> findByMemberIdAndOrganizationId(UUID memberId, UUID organizationId, boolean includeDeactivated);

@Query(value = """
Expand All @@ -31,7 +31,7 @@ JOIN volunteering_organization AS org USING(organization_id)
WHERE rel.member_id = :memberId
AND (rel.is_active = TRUE OR :includeDeactivated = TRUE)
AND (org.is_active = TRUE OR :includeDeactivated = TRUE)
ORDER BY rel.start_date, org.name""", nativeQuery = true)
ORDER BY org.name""", nativeQuery = true)
List<VolunteeringRelationship> findByMemberId(UUID memberId, boolean includeDeactivated);

@Query(value = """
Expand All @@ -41,7 +41,7 @@ JOIN volunteering_organization AS org USING(organization_id)
WHERE rel.organization_id = :organizationId
AND (rel.is_active = TRUE OR :includeDeactivated = TRUE)
AND (org.is_active = TRUE OR :includeDeactivated = TRUE)
ORDER BY rel.start_date, org.name""", nativeQuery = true)
ORDER BY org.name""", nativeQuery = true)
List<VolunteeringRelationship> findByOrganizationId(UUID organizationId, boolean includeDeactivated);

@Query(value = """
Expand All @@ -50,7 +50,7 @@ JOIN volunteering_organization AS org USING(organization_id)
JOIN volunteering_organization AS org USING(organization_id)
WHERE (rel.is_active = TRUE OR :includeDeactivated = TRUE)
AND (org.is_active = TRUE OR :includeDeactivated = TRUE)
ORDER BY rel.start_date, org.name""", nativeQuery = true)
ORDER BY org.name""", nativeQuery = true)
List<VolunteeringRelationship> findAll(boolean includeDeactivated);

@Query(value = """
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE volunteering_relationship
ALTER COLUMN start_date DROP NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ void canListAndFilterRelationships() {
// Can find all relationships in correct order
List<VolunteeringRelationship> allRelationships = relationshipClient.list(memberAuth, null, null, null);
assertEquals(3, allRelationships.size());
assertEquals(List.of(sarahFoodbank.getId(), sarahLiftForLife.getId(), timLiftForLife.getId()), allRelationships.stream().map(VolunteeringRelationship::getId).toList());
assertEquals(List.of(sarahLiftForLife.getId(), timLiftForLife.getId(), sarahFoodbank.getId()),
allRelationships.stream().map(VolunteeringRelationship::getId).toList());

// Can include inactive relationships
List<VolunteeringRelationship> allWithInactiveRelationships = relationshipClient.list(memberAuth, null, null, true);
assertEquals(4, allWithInactiveRelationships.size());
assertEquals(List.of(sarahFoodbank.getId(), timFoodbankInactive.getId(), sarahLiftForLife.getId(), timLiftForLife.getId()), allWithInactiveRelationships.stream().map(VolunteeringRelationship::getId).toList());

// Can filter by memberId
List<VolunteeringRelationship> timRelationships = relationshipClient.list(memberAuth, tim.getId(), null, null);
Expand All @@ -253,18 +253,16 @@ void canListAndFilterRelationships() {
assertEquals(List.of(sarahFoodbank.getId()), foodRelationships.stream().map(VolunteeringRelationship::getId).toList());
foodRelationships = relationshipClient.list(memberAuth, null, foodbank.getId(), true);
assertEquals(2, foodRelationships.size());
assertEquals(List.of(sarahFoodbank.getId(), timFoodbankInactive.getId()), foodRelationships.stream().map(VolunteeringRelationship::getId).toList());

// Can filter by member and organization
List<VolunteeringRelationship> sarahLiftRelationships = relationshipClient.list(memberAuth, sarah.getId(), liftForLife.getId(), null);
assertEquals(1, sarahLiftRelationships.size());
assertEquals(List.of(sarahLiftForLife.getId()), sarahLiftRelationships.stream().map(VolunteeringRelationship::getId).toList());

// Can filter by member and organization and inactive
List<VolunteeringRelationship> timFood = relationshipClient.list(memberAuth, tim.getId(), foodbank.getId(), null);
assertEquals(0, timFood.size());
timFood = relationshipClient.list(memberAuth, tim.getId(), foodbank.getId(), true);
assertEquals(1, timFood.size());
assertEquals(List.of(timFoodbankInactive.getId()), timFood.stream().map(VolunteeringRelationship::getId).toList());
}
}

8 changes: 4 additions & 4 deletions web-ui/src/components/volunteer/VolunteerRelationships.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
setSelectedRelationship({
memberId: onlyMe ? currentUser.id : '',
organizationId: '',
startDate: null, // Ensure this is a valid date object
endDate: null // Ensure this is a valid date object
startDate: null,
endDate: null
});
setRelationshipDialogOpen(true);
}, [currentUser.id, onlyMe]);
Expand Down Expand Up @@ -175,7 +175,7 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
return;
}

const formattedStartDate = formatDate(new Date(startDate));
const formattedStartDate = startDate ? formatDate(new Date(startDate)) : null;
const formattedEndDate = endDate ? formatDate(new Date(endDate)) : null;

const res = await resolve({
Expand Down Expand Up @@ -362,7 +362,7 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
value={selectedRelationship?.organizationId || ''}
/>
<DatePickerField
date={selectedRelationship?.startDate}
date={selectedRelationship?.startDate || null}
label="Start Date"
setDate={date => setSelectedRelationship({ ...selectedRelationship, startDate: date })}
/>
Expand Down
Loading