Link Search Menu Expand Document

Admin

/api/v2/group/admin

Post

groups

profiles

notifications

jwt


Purpose

To allow a user that is the administrator of a group to remove, add or promote (to being an admin) other users, or to block one from being able to join.

Body Content [input]

{
    uid: string,
    groupID: string,
    membersID: string[],
    operation: string
}

Returns if valid [output]

{
    message: string,
    error: 0
}

What the API does

  • Finds the group being referenced by the groupID passed [404].
  • Ensures that uid corresponds to a record in the members field with a status of accepted and which has a value of true for the is_admin field [403].
  • Loops through each value named profileID in the membersID field and does the following.
  • Checks that uid and profileID are not the same value [400].
  • Ensures that operation has a value of either add, remove, promote or block [400].
  • Ensures that profileID does not already correspond to a record in the members field if operation is set to add [403].
  • Ensures that profileID corresponds to a record in the members field if operation is set to remove, promote or block [403].
  • Ensures that profileID does not correspond to a record in the members field with a value of true for the is_admin field if operation is set to remove, promote or block [403].
  • Saves a new invite in the group_invites field of the record corresponding to the profileID passed, from the profiles collection with groupID and uses pending as value for the state field if operation is set to add.
  • Updates and saves the group with a new record for the members field with the profileID passed, and uses a value of pending for the status field, and uses false as value for the is_admin and has_muted fields if operation is set to add.
  • 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 if operation is set to add:
    {
      uid: profileID,
      notificationID: notificationID,
      content: `uid.${uid} invited you to the group.${groupID} group`,
      profileID: uid,
      type: "group_invite",
      created_on: timestamp,
      read: false,
      redirect: `/group/${groupID}`
    }
    
  • Removes the record in the members field referenced by the profileID passed from the group and saves if operation is set to remove.
  • Loops through the group_invites field of the record corresponding to the profileID passed from the profiles collection, finding any instance having the same groupID as that being referenced with a status of pending, and setting that instance to have a status of rejected if operation is set to block or remove.
  • Updates and saves the group with the record of the members field corresponding to profileID to use a value of unauthorized for the status field if operation is set to block.
  • 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 if operation is set to remove or block:
    {
      uid: profileID, 
      notificationID: notificationID,
      content: `You were removed from the group.${groupID} group`,
      profileID: uid,
      type: "group_kick",
      created_on: timestamp,
      read: false,
      redirect: `/group/${groupID}`
    }
    
  • Updates and saves the group with the record for the members field corresponding to profileID having a value of true for the is_admin field if operation is set to promote.
  • 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 if operation is set to promote:
    {
      uid: profileID, 
      notificationID: notificationID,
      content: `You were promoted to an admin in the group.${groupID} group`,
      profileID: uid,
      type: "group_promote",
      created_on: timestamp,
      read: false,
      redirect: `/group/${groupID}`
    }