List Each Member's Badges

Hi,

I’m trying to create a list on a page that only admins have access to.

I’m wanting a sort-of list of members, with every badge that they have listed alongside their name and picture.

The aim is to be able to go down the list of members and see who has each badge and who is missing each badge.

Can anyone suggest any designs or code to achieve this please?

Many Thanks in advance!

Use this one on the backend…

import { badges } from 'wix-members-backend';

export function myListMembersFunction() {
  const badgeId = "571495e9-98af-4ec9-b854-16c0293c9312";

  return badges.listMembers(badgeId)
    .then((memberIds) => {
      const firstMember = memberIds[0];
      return memberIds;
    })
    .catch((error) => {
      console.error(error);
    });
}

/*
 * Promise resolves to:
 * [
 *   "28d35f86-6694-4455-9dff-aff5d450b482",
 *   "72751428-2743-4bda-acf5-4218a4279cd3",
 *   "8831eed6-928e-4f85-b80a-e1e48fb7c4fd"
 * ]
 */

…and get all MEMBER-IDs which are asigned to a specific badge.

Hi Velo Ninja,

Thank you very much for your help.

I was thinking something like the below but not sure how to get something like that using the data:

The shown API-function finds all members who is (are) assigned to a specific badge.

There is also a second one, which lists all the badges found for each of the users. Maybe it will be the better choice for your project…


import { badges } from 'wix-members-backend';

export function myListMemberBadgesFunction() {
  const memberIds = [
    "32cf071a-cc2f-450f-ad74-5a25db0b1b6a",
    "2cb1846f-0c7a-4c39-8736-349236cfab40",
    "69nh659a-ic2f-950f-ed74-14a25db9b1b6j"
  ];

  return badges.listMemberBadges(memberIds)
    .then((memberBadges) => {
      const firstMemberBadges = memberBadges[0].badgeIds;
      return memberBadges;
    })
    .catch((error) => {
      console.error(error);
    });
}

Will find all assigned badges for each of the users.


Example RESULTS:

[
 *   {
 *     "memberId": "32cf071a-cc2f-450f-ad74-5a25db0b1b6a",
 *     "badgeIds": [
 *       "0d37ea22-44b0-4a62-9818-ff660178c439",
 *       "c7d1a81d-485a-4eef-872f-4595ab2a15a2"
 *     ]
 *   },
 *   {
 *     "memberId": "2cb1846f-0c7a-4c39-8736-349236cfab40",
 *     "badgeIds": [
 *       "0d37ea22-44b0-4a62-9818-ff660178c439",
 *       "41dcda59-8b6d-4deb-bb1f-d283de044b85",
 *       "df9fc0e2-c2ba-40ba-a160-200a016c3507"
 *     ]
 *   },
 *   {
 *     "memberId": "69nh659a-ic2f-950f-ed74-14a25db9b1b6j",
 *     "badgeIds": [
 *       "df9fc0e2-c2ba-40ba-a160-200a016c3507"
 *     ]
 *   }
 * ]

How to get DATA of member …???

let mySearchResult = const firstMemberBadges = memberBadges[0].badgeIds;

How to get first badge of the found user…???

let mySearchResult = const firstMemberBadges = memberBadges[0].badgeIds[0];