Create
/api/v2/badge/create
Post
badges
profiles
notifications
Purpose
To allow the admin to create a badge.
Body Content [input]
{
secret: string,
name: string,
description: string,
icon_type: string,
membersID: string[]
}
Returns if valid [output]
{
badgeID: string,
error: 0
}
What the API does
- Checks if the value of the
secret
field passed is valid [401]. - Checks that
membersID
is not empty [400] and loops through each of its values to ensure that there is a correponding record in theprofiles
collection with these values [404]. - Generates a unique
badgeID
. - Adds and saves a document in the
badges
collection using thename
,description
,icon_type
andmembersID
fields passed, as well as the generatedbadgeID
. - Loops through each value present in the
membersID
field passed and generates a newnotificationID
and atimestamp
corresponding to the current date and time, and creates a new object in thenotifications
collection with the following data :{ uid: loop_value, notificationID: notificationID, content: `You have obtained a new badge! badge.${badge.icon_type}`, profileID: '_system', type: "new_badge", created_on: timestamp, read: false, redirect: `/profile/${loop_value}` }