Class

Author

Author

An author represents a contributor to a story.

Note: This class is typically needed only for an Author's page. For most usecases, the authors field on Story should be sufficient.

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

function loadDataForAuthorPage(client, authorId) {
  const [author, collection] = await Promise.all([
    Author.getAuthor(client, authorId),
    Author.getAuthorCollection(client, authorId)
  ])
  if(!author) {
    render404();
  } else {
    renderAuthorPage(author.asJson(), collection);
  }
}

Methods

static getAuthor(client, authorId) → {Promise.<(Author|null)>}

This method fetches an author by Id. See the example on Author for usage.

Parameters:
Name Type Description
client Client
authorId number
See:

View Source index.js, line 465

Promise.<(Author|null)>

static getAuthorCollection(client, authorId) → {Object}

This method fetches the collection. See the example on Author for usage.

Please note, this function does not return a Collection object, but a plain javascript object.

Parameters:
Name Type Description
client Client
authorId number
Deprecated:
  • This will be deprecated in favor of a method which returns a Collection.

View Source index.js, line 493

Please see API documentation for more details

Object

static getAuthors(client, params)

This method can be used to fetch all authors across the site. Use of this API is highly discouraged as you will need to make multiple calls to fetch all authors, as authors grow.

Parameters:
Name Type Description
client Client
params Object
limit number

Number of authors to be returned (default 20)

offset number

Number of authors to skip

Deprecated:
  • This API is very slow if there are more than ~100 authors.

View Source index.js, line 479

asJson()

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

View Source index.js, line 453