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 
groupbeing referenced by thegroupIDpassed [404]. - Ensures that 
uidcorresponds to a record in themembersfield with astatusofacceptedand which has a value oftruefor theis_adminfield [403]. - Loops through each value named 
profileIDin themembersIDfield and does the following. - Checks that 
uidandprofileIDare not the same value [400]. - Ensures that 
operationhas a value of eitheradd,remove,promoteorblock[400]. - Ensures that 
profileIDdoes not already correspond to a record in themembersfield ifoperationis set toadd[403]. - Ensures that 
profileIDcorresponds to a record in themembersfield ifoperationis set toremove,promoteorblock[403]. - Ensures that 
profileIDdoes not correspond to a record in themembersfield with a value oftruefor theis_adminfield ifoperationis set toremove,promoteorblock[403]. - Saves a new 
invitein thegroup_invitesfield of the record corresponding to theprofileIDpassed, from theprofilescollection withgroupIDand usespendingas value for thestatefield if operation is set toadd. - Updates and saves the 
groupwith a new record for themembersfield with theprofileIDpassed, and uses a value ofpendingfor thestatusfield, and usesfalseas value for theis_adminandhas_mutedfields ifoperationis set toadd. - Generates a new 
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection with the following data ifoperationis set toadd:{ 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 
membersfield referenced by theprofileIDpassed from thegroupand saves ifoperationis set toremove. - Loops through the 
group_invitesfield of the record corresponding to theprofileIDpassed from theprofilescollection, finding any instance having the samegroupIDas that being referenced with astatusofpending, and setting that instance to have astatusofrejectedifoperationis set toblockorremove. - Updates and saves the 
groupwith the record of themembersfield corresponding toprofileIDto use a value ofunauthorizedfor thestatusfield ifoperationis set toblock. - Generates a new 
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection with the following data ifoperationis set toremoveorblock:{ 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 
groupwith the record for themembersfield corresponding toprofileIDhaving a value oftruefor theis_adminfield ifoperationis set topromote. - Generates a new 
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection with the following data ifoperationis set topromote:{ 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}` }