Skip to content

[SSF-171] update volunteers endpoint#138

Open
amywng wants to merge 1 commit intomainfrom
acw/SSF-171-update-volunteer-endpoint
Open

[SSF-171] update volunteers endpoint#138
amywng wants to merge 1 commit intomainfrom
acw/SSF-171-update-volunteer-endpoint

Conversation

@amywng
Copy link
Member

@amywng amywng commented Mar 25, 2026

ℹ️ Issue

Closes SSF-171

📝 Description

  • changed updatePantryVolunteers to patch and to take in add and remove id lists in pantries.controller.ts
  • updated service function to add and remove specified users from pantry volunteers, throwing if given id lists overlap at all, if any of the given ids are not volunteers or don't exist, or if the pantryId doesn't exist
  • updated controller and service tests

✔️ Verification

Checked with Postman that adding/removing worked and threw expected exceptions when needed. Verified written tests passed

Copy link

@dburkhart07 dburkhart07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some funny dsa adjustments! 🎱 🦀 📱 👑

allVolunteerIds.map((id) => this.usersService.findOne(id)),
);

if (users.length !== volunteerIds.length) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this check removed?

async updatePantryVolunteers(
@Param('pantryId', ParseIntPipe) pantryId: number,
@Body('volunteerIds') volunteerIds: number[],
@Body('addVolunteerIds') addVolunteerIds: number[],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these both be required? Thinking we only need 1 to execute this. Should adjust tests accordingly.

volunteerIds.forEach((id) => validateId(id, 'Volunteer'));

const overlap = addVolunteerIds.filter((id) =>
removeVolunteerIds.includes(id),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make removeVolunteerIds also a set for easier iteration? Both of these arrays are looped through a ton, so I think they should immediately be converted to sets, and have that used for every other check (this will reduce many computations below from O(n) -> O(1)). Hooray for Leetcode!!

pantryId: number,
volunteerIds: number[],
addVolunteerIds: number[],
removeVolunteerIds: number[],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are on the topic of sets, on conversion, we should validate at the start that there are no duplicates within our respective lists (cant remove a volunteer twice and cant add one twice), and add a test for this.

@@ -480,24 +495,32 @@ export class PantriesService {
}

const users = await Promise.all(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we actually change this to use findBy({ id: In(allVolunteerIds) }) so that we only need to do one query select?

throw new NotFoundException('One or more users not found');
}

const nonVolunteers = users.filter((user) => user.role !== Role.VOLUNTEER);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to check that the volunteer users being removed are volunteers (we already know they are), so we can just check the ones being added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants