Link Search Menu Expand Document

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 the uid passed and fetches a list of all values inside of the following and blocked fields.
  • Finds all records from the stories collection.
  • Filters among all these records to get the story having the same value for its storyID 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 to none.
    • If the record does not have a visibility of none, followers or public, fetch the members field of the AccessGroup corresponding to the value of the visibility field and if uid is not among the values of that members field, remove the record.
    • Removes that record if the value of its uid field is among that of the fetched blocked field above.
    • Finds the profile that has a uid corresponding to that of the current story record, and removes that record if the blocked field contains the uid passed.
    • Else, if the record has a value of followers for its visibility field, check if uid is among the values of the followers field of the profile fetched. If that is not the case, remove that record.
    • If the current day / time minus the value of the posted_on field of that story record is more than or equal to 24 hours, remove that record.
    • Remove the views field of that story record.
    • Appends that story record to an array of stories to be returned.
  • Checks if there’s at least one story in the final array and returns it [404].