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
profile
corresponding to theuid
passed and fetches a list of all values inside of thefollowing
andblocked
fields. - Finds all records from the
stories
collection. - Filters among all these records to get the
story
having the same value for itsstoryID
field as that of the one passed. - Loops through each of these remaining
story
records and:- Skip everything that follows if the record’s
uid
has a value equal to the one passed except for the last point. - Removes that record if it has a
visibility
set tonone
. - If the record does not have a
visibility
ofnone
,followers
orpublic
, fetch themembers
field of theAccessGroup
corresponding to the value of thevisibility
field and ifuid
is not among the values of thatmembers
field, remove the record. - Removes that record if the value of its
uid
field is among that of the fetchedblocked
field above. - Finds the
profile
that has auid
corresponding to that of the currentstory
record, and removes that record if theblocked
field contains theuid
passed. - Else, if the record has a value of
followers
for its visibility field, check ifuid
is among the values of thefollowers
field of theprofile
fetched. If that is not the case, remove that record. - If the current day / time minus the value of the
posted_on
field of thatstory
record is more than or equal to 24 hours, remove that record. - Remove the
views
field of thatstory
record. - Appends that
story
record to an array of stories to be returned.
- Skip everything that follows if the record’s
- Checks if there’s at least one
story
in the final array and returns it [404].