Manual Reference Source Test
import BaseContentController from 'pop-api/src/controllers/BaseContentController.js'
public class | source

BaseContentController

Extends:

IControllerIContentController → BaseContentController

Indirect Implements:

Base class for getting content from endpoints.

Test:

Constructor Summary

Public Constructor
public

constructor(options: Object)

Create a new base content controller.

Member Summary

Public Members
public

The base path for the routes.

public

The service of the content controller.

Method Summary

Public Methods
public

Check if the content is empty or the length of the content array is zero.

public

Create a new content item.

public

Delete a content item.

public

Get a content item based on the id.

public

Get all the available pages.

public

Get content from one page.

public

Get a random item.

public

registerRoutes(router: Object, PopApi: PopApi): undefined

Default method to register the routes.

public

sortContent(sort: string, order: number): Object

Default method to sort the items.

public

Update the info of one content item.

Inherited Summary

From class IController
public abstract

registerRoutes(router: Object, PopApi: PopApi): undefined

Default method to register the routes.

From class IContentController
public abstract

Create a new content item.

public abstract

Delete a content item.

public abstract

Get a content item based on the id.

public abstract

Default method to get content pages.

public abstract

Default method to get a page of content.

public abstract

Default method to get a random content item.

public abstract

sortContent(sort: string, order: number): Object

Default method to sort the items.

public abstract

Update the info of one content item.

Public Constructors

public constructor(options: Object) source

Create a new base content controller.

Params:

NameTypeAttributeDescription
options Object
  • nullable: false

The options for the base content controller.

options.basePath string
  • nullable: false

The base path for the routes.

options.service ContentService
  • nullable: false

The service for the content controller.

Test:

Public Members

public basePath: string source

The base path for the routes.

public service: ContentService source

The service of the content controller.

Public Methods

public checkEmptyContent(res: ServerResponse, content: Object | Array<Object>): Object source

Check if the content is empty or the length of the content array is zero.

Params:

NameTypeAttributeDescription
res ServerResponse
  • nullable: false

The server response object.

content Object | Array<Object>
  • nullable: false

The content to check.

Return:

Object

Returns a 204 response if the content is empty, or a 200 response with the content if it is not empty.

public createContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source

Create a new content item.

Override:

IContentController#createContent

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Promise<Object, Error>

The created content item.

Test:

public deleteContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source

Delete a content item.

Override:

IContentController#deleteContent

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Promise<Object, Error>

The deleted content item

Test:

public getContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source

Get a content item based on the id.

Override:

IContentController#getContent

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Promise<Object, Error>

The details of a single content item.

Test:

public getContents(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<string>, Error> source

Get all the available pages.

Override:

IContentController#getContents

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Promise<Array<string>, Error>

A list of pages which are available.

Test:

public getPage(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<Object>, Error> source

Get content from one page.

Override:

IContentController#getPage

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Promise<Array<Object>, Error>

The content of one page.

Test:

public getRandomContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source

Get a random item.

Override:

IContentController#getRandomContent

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Promise<Object, Error>

A random item.

Test:

public registerRoutes(router: Object, PopApi: PopApi): undefined source

Default method to register the routes.

Override:

IController#registerRoutes

Params:

NameTypeAttributeDescription
router Object
  • nullable: false

The router to register the routes to.

PopApi PopApi
  • nullable: false

The PopApi instance.

Return:

undefined

Test:

public sortContent(sort: string, order: number): Object source

Default method to sort the items.

Override:

IContentController#sortContent

Params:

NameTypeAttributeDescription
sort string
  • nullable: false

The property to sort on.

order number
  • nullable: false

The way to sort the property.

Return:

Object

The sort object.

public updateContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source

Update the info of one content item.

Override:

IContentController#updateContent

Params:

NameTypeAttributeDescription
req IncomingMessage
  • nullable: false

The incoming message request object.

res ServerResponse
  • nullable: false

The server response object.

next Function
  • nullable: false

The next function to move to the next middleware.

Return:

Promise<Object, Error>

The updated content item.

Test: