Fetch One
/api/v2/story/fetch/one
Post
stories
profiles
jwt
Purpose
To allow a user to fetch one story among all those from users that he/she follows that he/she is allowed to see in his/her feed.
Body Content [input]
{
uid: string,
storyID: string
}
Returns if valid [output]
{
story: {
uid: string,
storyID: string,
posted_on: Date,
content: String,
visibility: string
},
error: 0
}
What the API does
- Finds the
profilecorresponding to theuidpassed and fetches a list of all values inside of thefollowingandblockedfields. - Finds all records from the
storiescollection. - Filters among all these records to get the
storyhaving the same value for itsstoryIDfield as that of the one passed. - Loops through each of these remaining
storyrecords and:- Skip everything that follows if the record’s
uidhas a value equal to the one passed except for the last point. - Removes that record if it has a
visibilityset tonone. - If the record does not have a
visibilityofnone,followersorpublic, fetch themembersfield of theAccessGroupcorresponding to the value of thevisibilityfield and ifuidis not among the values of thatmembersfield, remove the record. - Removes that record if the value of its
uidfield is among that of the fetchedblockedfield above. - Finds the
profilethat has auidcorresponding to that of the currentstoryrecord, and removes that record if theblockedfield contains theuidpassed. - Else, if the record has a value of
followersfor its visibility field, check ifuidis among the values of thefollowersfield of theprofilefetched. If that is not the case, remove that record. - If the current day / time minus the value of the
posted_onfield of thatstoryrecord is more than or equal to 24 hours, remove that record. - Remove the
viewsfield of thatstoryrecord. - Appends that
storyrecord to an array of stories to be returned.
- Skip everything that follows if the record’s
- Checks if there’s at least one
storyin the final array and returns it [404].