Class

Story

Story

This corresponds to a story in Quintype. Most forms of content are modelled under this class. Depending on which API the data is recieved from, the exact fields which are present on the story object may change. Please see the API reference for the full list of fields available.

See Story.getStoryBySlug for a simple example.

import { Story } from "@quintype/framework/server/api-client";

Methods

static getInBulk(client, requests)

This low level function can be used to make multiple API calls simultaneously to the backend. This is typically not meant to be used by developers directly, please consider using Collection and related functions instead

Parameters:
Name Type Description
client Client
requests Object
See:

View Source index.js, line 190

static getPublicPreviewStory(client, publicPreviewKey) → {Promise.<(Story|null)>}

This function can be used to fetch a draft story, given the secretKey generated by the editor. This function works very similar to Story.getStoryBySlug, except the fact that it accepts a secretKey. This is the only API which will give you the latest draft / un published version of a story.

See the public preview tutorial (FIXME: Broken Link) for an a tutorial on implementation

Parameters:
Name Type Description
client Client
publicPreviewKey string
See:

View Source index.js, line 140

Promise.<(Story|null)>

static getSearch(client, params) → {Object}

This function can be used to search for stories by the given string. The returned object has a stories property which is an array of Stories, but also contains other fields like from, and total.

Example

const {stories, total} = Story.getSearch(client, {q: "Some String"});
console.log(`Total Number of Results: ${total}`);
JSON.stringify(stories.map(story => story.asJson()));
Parameters:
Name Type Description
client Client
params Object

Please see the Search API documentation for more details.

q string

The search string

See:

View Source index.js, line 174

Please see Search API documentation for more details.

Object

static getStories(client, storyGroup, params) → {Array.<Story>}

This function can be used to fetch stories from the old sorters API.

Example

const stories = await Story.getStories(client, 'top', {'section-id': 42});
console.log(stories[0].headline)
console.log(JSON.stringify(stories.map(s => s.asJson())))
Parameters:
Name Type Description
client Client
storyGroup string
params Object
Deprecated:
  • Please use Collection and related functions instead
See:

View Source index.js, line 64

Array.<Story>

static getStoryById(client, id) → {Promise.<(Story|null)>}

This function can be used to fetch a story, given the id.

This function works very similar to Story.getStoryBySlug, except the fact that it accepts a id

Parameters:
Name Type Description
client Client
id string
See:

View Source index.js, line 153

Promise.<(Story|null)>

static getStoryBySlug(client, slug, params) → {Promise.<(Story|null)>}

This function can be used to fetch a story given a slug. This is typically done on story pages.

This returned promise will resolve to null if the story is not found

Example

const story = await Story.getStoryBySlug(client, slug);
if(!story) {
  render404();
} else {
  renderTheStoryPage(story);
}
Parameters:
Name Type Description
client Client
slug string

The slug of the story.

params Object

Parameters that are passed directly as query paremeters to the API

See:

View Source index.js, line 121

Promise.<(Story|null)>

asJson()

Use this to convert to a simple javascript object, suitable for JSON.

View Source index.js, line 44

getRelatedStories(client) → {Array.<Story>}

This method can be used to fetch stories related to a given story

Example

const story = await Story.getStoryBySlug(client, "some-slug");
const relatedStories = await story.getRelatedStories(client);
Parameters:
Name Type Description
client Client
See:

View Source index.js, line 82

Array.<Story>

getStoryAttributes(client) → {Object}

This method can be used to get various metadata for the given story. Apart from story related attributes, this API will also return all collections this story is a part of, along with collection metadata.

Parameters:
Name Type Description
client Client
See:

View Source index.js, line 97

Please see API documentation for more details

Object