Create
/api/v2/group/create
Post
groups
profiles
notifications
jwt
Purpose
To allow a user to create a group.
Body Content [input]
{
uid: string,
membersID: string[],
name: string,
description: string,
icon: string,
cover_image: string,
privacy: string
}
Returns if valid [output]
{
groupID: string,
error: 0
}
What the API does
- Ensures that privacy is either set to
privateorpublic, and defaults topublic. - Generates a
groupID. - Loops through
membersIDwith each value corresponding tomemberIDand:- Fetches the profile for the record with a
uidcorresponding to theuidpassed (src) [404]. - Fetches the profile for the record with a
uidcorresponding tomemberID(dest) [404]. - Ensures that neither
uidis found indest’sblockedfield nor thatmemberIDis found insrc’sblockedfield [403]. - Ensures that
uidis found indest’sfollowersfield [403]. - Saves a new
inviteindest’sgroup_inviteswith the generatedgroupIDand usespendingas value for thestatefield. - Generates a new
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection with the following data:{ uid: memberID, 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}` } - Generates a new object with the passed
name,description,privacy,icon,cover_imageand the generatedgroupID. Records will be added to themembersfield with each one corresponding to the current user’suid, with a value offalseforis_adminandhas_muted, and uses a value ofpendingfor thestatusfield. A record will be similarly created for the current user using theuidpassed, but with values oftrueforis_admin,falseforhas_mutedandacceptedforstatus.
- Fetches the profile for the record with a