Link Search Menu Expand Document

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 the profiles collection with these values [404].
  • Generates a unique badgeID.
  • Adds and saves a document in the badges collection using the name, description, icon_type and membersID fields passed, as well as the generated badgeID.
  • Loops through each value present in the membersID field passed and generates a new notificationID and a timestamp corresponding to the current date and time, and creates a new object in the notifications 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}`
    }