Amaresh: Add POST /badge/assign endpoint for multi-user badge assignment - #2334
Open
amaresh2001 wants to merge 2 commits into
Open
Amaresh: Add POST /badge/assign endpoint for multi-user badge assignment#2334amaresh2001 wants to merge 2 commits into
amaresh2001 wants to merge 2 commits into
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
The Badge Assignment feature on the frontend lets an admin select multiple users and multiple badges and assign them in one action. The frontend action
assignBadgesToMultipleUserIDsendsPOST /api/badge/assignwith{ userIds, selectedBadges }, but that route never existed on the backend; only the single-userPUT /api/badge/assign/:userIddid. Every bulk assignment hit a 404, and the UI showed "Oops, something went wrong while assigning badges!".This PR adds the missing endpoint.
Fixes the badge-assignment failure reported on frontend PR #4734
Related PRS (if any):
Paired with frontend PR OneCommunityGlobal/HighestGoodNetworkApp#4734 (branch
Amalesh-3940-bugfix).To test this backend PR you need to check out the #4734 frontend branch and run it against this backend branch.
Main changes explained:
src/controllers/badgeController.js: addassignBadgesToMultipleUsers:assignBadgespermission (403 otherwise)userIdsandselectedBadgesare non-empty arrays (400 otherwise)countand pushes a newearnedDateif the user already has that badge; otherwise, adds a newbadgeCollectionentry withcount: 1andfeatured: false; bumpsbadgeCountbyselectedBadges.length; clears that user's cache200with a per-user results array, and400only if every user failedsrc/routes/badgeRouter.js: wirePOST /badge/assigntocontroller.assignBadgesToMultipleUsers(added alongside the existingPUT /badge/assign/:userId)How to test:
amaresh/badge-assign-multiple-users) inHGNRest, runnpm install, thennpm run dev(backend onhttp://localhost:4500)HighestGoodNetworkApp, check outAmalesh-3940-bugfix, runnpm install, thennpm run start:local(frontend onhttp://localhost:5173)assignBadgespermission)/badgemanagement→ Badge Assignment tabN user(s) selectedN badge(s) selectedassignBadgesgets a 403.Screenshots or videos of changes:
Note: