Search...
updateBadge( )
Updates a badge.
Description
The updateBadge()
function returns a Promise that resolves to the updated badge.
Only the properties passed in the BadgeInfo
object will be updated. All other properties will remain the same.
Because the badge slug
is based on the badge title
, if you change title
, slug
is updated accordingly.
badgeId
must be an ID from your site's Members/Badges
collection. Typically, you retrieve the ID from the collection using a query or through a dataset.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function updateBadge(_id: string, badge: UpdateBadge): Promise<UpdateBadgeResponse>
updateBadge Parameters
NAME
TYPE
DESCRIPTION
_id
string
Badge ID.
badge
UpdateBadge
Returns
Return Type:
Promise<
UpdateBadgeResponse
>NAME
TYPE
DESCRIPTION
badge
Badge
Updated badge.
Was this helpful?
Update existing badge. (dashboard page code)
Copy Code
1import { badges } from 'wix-members.v2';23/* Sample _id value: '215be5d9-4b32-4861-9eb5-2152930dd0b4'4 *5 * Sample badge value:6 * {7 * backgroundColor: "#FED8B1",8 * description: "Contributed 5 posts this month",9 * icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",10 * textColor: "#000000",11 * title: "Rising Star"12 * }13 */1415export async function myUpdateBadgeFunction(_id, badge) {16 try {17 const updateBadge = await badges.updateBadge(_id, badge);1819 console.log('Updated badge:', updateBadge);20 return updateBadge;21 } catch (error) {22 console.error(error);23 // Handle the error24 }2526}2728/* Promise resolves to:29 * {30 * "_createdDate": "2024-01-18T10:27:14.878Z",31 * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",32 * "_updatedDate": "2024-01-18T14:50:36.174Z",33 * "backgroundColor": "#FED8B1",34 * "description": "Contributed 5 posts this month",35 * "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",36 * "permissionsEnabled": true,37 * "slug": "super-contributor",38 * "textColor": "#000000",39 * "title": "Rising Star"40 * }41 */42
Update existing badge. (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { badges } from 'wix-members.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '215be5d9-4b32-4861-9eb5-2152930dd0b4'6 *7 * Sample badge value:8 * {9 * backgroundColor: "#FED8B1",10 * description: "Contributed 5 posts this month",11 * icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",12 * textColor: "#000000",13 * title: "Rising Star"14 * }15 */1617export const myUpdateBadgeFunction = webMethod(Permissions.Anyone, async (_id, badge) => {18 try {19 const elevatedUpdateBadge = elevate(badges.updateBadge);20 const updateBadge = await elevatedUpdateBadge(_id, badge);2122 console.log('Updated badge:', updateBadge);23 return updateBadge;24 } catch (error) {25 console.error(error);26 // Handle the error27 }2829});3031/* Promise resolves to:32 * {33 * "_createdDate": "2024-01-18T10:27:14.878Z",34 * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",35 * "_updatedDate": "2024-01-18T14:50:36.174Z",36 * "backgroundColor": "#FED8B1",37 * "description": "Contributed 5 posts this month",38 * "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",39 * "permissionsEnabled": true,40 * "slug": "super-contributor",41 * "textColor": "#000000",42 * "title": "Rising Star"43 * }44 */45
Update existing badge. (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { badges } from 'wix-members.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '215be5d9-4b32-4861-9eb5-2152930dd0b4'6 *7 * Sample badge value:8 * {9 * backgroundColor: "#FED8B1",10 * description: "Contributed 5 posts this month",11 * icon: "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",12 * textColor: "#000000",13 * title: "Rising Star"14 * }15 */1617export const myUpdateBadgeFunction = webMethod(Permissions.Anyone, async (_id, badge) => {18 try {19 const elevatedUpdateBadge = elevate(badges.updateBadge);20 const updateBadge = await elevatedUpdateBadge(_id, badge);2122 console.log('Updated badge:', updateBadge);23 return updateBadge;24 } catch (error) {25 console.error(error);26 // Handle the error27 }2829});3031/* Promise resolves to:32 * {33 * "_createdDate": "2024-01-18T10:27:14.878Z",34 * "_id": "215be5d9-4b32-4861-9eb5-2152930dd0b4",35 * "_updatedDate": "2024-01-18T14:50:36.174Z",36 * "backgroundColor": "#FED8B1",37 * "description": "Contributed 5 posts this month",38 * "icon": "https://static.wixstatic.com/shapes/132b9a3d51884000acaf705eeeb0e296.svg",39 * "permissionsEnabled": true,40 * "slug": "super-contributor",41 * "textColor": "#000000",42 * "title": "Rising Star"43 * }44 */45