Admin
/api/v2/room/admin
Post
rooms
profiles
jwt
Purpose
To allow a user that is the administrator of a chat room 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,
    roomID: string,
    membersID: string[],
    operation: string
}
Returns if valid [output]
{
    message: string,
    error: 0
}
What the API does
- Finds the 
roombeing referenced by theroomIDpassed [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]. - Generates a 
messageIDandtimestampcorresponding to the current date and time ifoperationis set to anything other thanpromote. - Saves a new 
invitein thechat_invitesfield of the record corresponding to theprofileIDpassed, from theprofilescollection withroomIDand usespendingas value for thestatefield if operation is set toadd. - Updates and saves the 
roomwith 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 room.${roomID} chat room`, profileID: uid, type: "room_invite", created_on: timestamp, read: false, redirect: `/chat/${roomID}` } - Removes the record in the 
membersfield referenced by theprofileIDpassed from theroomand saves ifoperationis set toremove. - Generates and saves a new object in the 
messagesfield of theroomusingmessageID, “uid.${uid} was kicked from the chat” asmessage,timestampascreated_onandmodified_on, “_system” assenderID,falseforis_deletedand an empty array forviewsifoperationis set toremove. - Loops through the 
chat_invitesfield of the record corresponding to theprofileIDpassed from theprofilescollection, finding any instance having the sameroomIDas that being referenced with astatusofpending, and setting that instance to have astatusofrejectedifoperationis set toblockorremove. - Updates and saves the 
roomwith 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 room.${roomID} chat room`, profileID: uid, type: "room_kick", created_on: timestamp, read: false, redirect: `/chat/${roomID}` } - Generates and saves a new object in the 
messagesfield of theroomusingmessageID, “uid.${uid} has been banned from the chat” asmessage,timestampascreated_onandmodified_on, “_system” assenderID,falseforis_deletedand an empty array forviewsifoperationis set toblock. - Updates and saves the 
roomwith 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 room.${roomID} chat room`, profileID: uid, type: "room_promote", created_on: timestamp, read: false, redirect: `/chat/${roomID}` }