Skip to content

[SSF-211] promote volunteer to admin#187

Open
jxuistrying wants to merge 3 commits into
mainfrom
jx/SSF-211-promote-volunteer-to-admin
Open

[SSF-211] promote volunteer to admin#187
jxuistrying wants to merge 3 commits into
mainfrom
jx/SSF-211-promote-volunteer-to-admin

Conversation

@jxuistrying
Copy link
Copy Markdown

ℹ️ Issue

Closes [SSF-211]

📝 Description

  • added PATCH /api/users/:id/role endpoint for promotion
  • promotion updates role in DB, clears pantry assignments, and syncs Cognito groups
  • wrote service and controller tests
  • implemented column ui changes to promote to admin with confirmation modal
  • add alerts for success/error after promotion

✔️ Verification

used frontend to test promoting a volunteer to admin and checked the network tab to see user role updated to admin

🏕️ (Optional) Future Work / Notes

my yarn tests are failing currently but im not sure how to fix it yet.

@jxuistrying jxuistrying changed the title Jx/ssf 211 promote volunteer to admin [SSF-211] promote volunteer to admin May 31, 2026
@jiang-h-y jiang-h-y self-requested a review May 31, 2026 23:13
Copy link
Copy Markdown

@jiang-h-y jiang-h-y left a comment

Choose a reason for hiding this comment

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

Mostly lgtm, but could you move the promote button into a new column instead of putting it within "Actions" so it better matches the Figma design?

Like this:

Image

@jiang-h-y
Copy link
Copy Markdown

Also backend tests are passing for me so not sure why you're having issues.

@Yurika-Kan Yurika-Kan requested a review from dburkhart07 June 3, 2026 00:35
@dburkhart07 dburkhart07 self-assigned this Jun 3, 2026
Copy link
Copy Markdown

@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.

few questions pending yurika's clarification, but still some good things to work on. make sure all these updates you make you make to the tests too!

@Roles(Role.ADMIN)
async promoteToAdmin(
@Param('id', ParseIntPipe) id: number,
@Body() dto: UpdateUserRoleDto,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This may be a very rare case where we do not need a body. We know we are already promoting the volunteer to admin, so we shouldn't need to verify any other data. Can we delete this and the dto, and the check in the controller?

return this.usersService.update(id, dto);
}

@Patch('/:id/role')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: Can we rename this to something more descriptive, perhaps @Patch('/:id/promote-volunteer)

async promoteToAdmin(
@Param('id', ParseIntPipe) id: number,
@Body() dto: UpdateUserRoleDto,
): Promise<User> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Most of our patch api calls will return void you'll see, let's do the same here and update the service function and all tests.

[userId],
);

if (user.userCognitoSub) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a required field, it will aways exist

);
}

const queryRunner = this.dataSource.createQueryRunner();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think we need any of this queryRunner, and we should be able to just set the volunteers to [] and save that. I think that may have been missed in the ticket, so can you do that? Should just be able to do this.repo.save instead (like all our other service functions).

if (user.userCognitoSub) {
await this.authService.addUserToGroup(user.email, 'admin');
await this.authService.removeUserFromGroup(user.email, 'volunteer');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we wrap all 3 service calls in one single transaction? Look at many of our other service functions (one example would be the create function in the donations service) to understand how we go about using a transactionManager. The boilerplate code should be identical to that.

AdminCreateUserCommand,
} from '@aws-sdk/client-cognito-identity-provider';

import {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: include these imports in the same one as above

}
}

async addUserToGroup(username: string, groupName: string): Promise<void> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Yurika-Kan now that we have this function, should we be calling it for when we create a new volunteer as well? what about pantry and fm?

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.

3 participants