import BaseContentController from 'pop-api/src/controllers/BaseContentController.js'BaseContentController
Extends:
Implements:
Indirect Implements:
Base class for getting content from endpoints.
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 |
checkEmptyContent(res: ServerResponse, content: Object | Array<Object>): Object Check if the content is empty or the length of the content array is zero. |
|
| public |
createContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Create a new content item. |
|
| public |
deleteContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Delete a content item. |
|
| public |
getContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Get a content item based on the id. |
|
| public |
getContents(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<string>, Error> Get all the available pages. |
|
| public |
getPage(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<Object>, Error> Get content from one page. |
|
| public |
getRandomContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> 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 |
updateContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> 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 |
createContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Create a new content item. |
|
| public abstract |
deleteContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Delete a content item. |
|
| public abstract |
getContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Get a content item based on the id. |
|
| public abstract |
getContents(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<string>, Object> Default method to get content pages. |
|
| public abstract |
getPage(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<Object>, Error> Default method to get a page of content. |
|
| public abstract |
getRandomContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Default method to get a random content item. |
|
| public abstract |
sortContent(sort: string, order: number): Object Default method to sort the items. |
|
| public abstract |
updateContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> Update the info of one content item. |
|
Public Constructors
public constructor(options: Object) source
Create a new base content controller.
Params:
| Name | Type | Attribute | Description |
| options | Object |
|
The options for the base content controller. |
| options.basePath | string |
|
The base path for the routes. |
| options.service | ContentService |
|
The service for the content controller. |
Public Members
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:
| Name | Type | Attribute | Description |
| res | ServerResponse |
|
The server response object. |
| content | Object | Array<Object> |
|
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#createContentParams:
| Name | Type | Attribute | Description |
| req | IncomingMessage |
|
The incoming message request object. |
| res | ServerResponse |
|
The server response object. |
| next | Function |
|
The next function to move to the next middleware. |
public deleteContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source
Delete a content item.
Override:
IContentController#deleteContentParams:
| Name | Type | Attribute | Description |
| req | IncomingMessage |
|
The incoming message request object. |
| res | ServerResponse |
|
The server response object. |
| next | Function |
|
The next function to move to the next middleware. |
public getContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source
Get a content item based on the id.
Override:
IContentController#getContentParams:
| Name | Type | Attribute | Description |
| req | IncomingMessage |
|
The incoming message request object. |
| res | ServerResponse |
|
The server response object. |
| next | Function |
|
The next function to move to the next middleware. |
public getContents(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<string>, Error> source
Get all the available pages.
Override:
IContentController#getContentsParams:
| Name | Type | Attribute | Description |
| req | IncomingMessage |
|
The incoming message request object. |
| res | ServerResponse |
|
The server response object. |
| next | Function |
|
The next function to move to the next middleware. |
public getPage(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Array<Object>, Error> source
Get content from one page.
Override:
IContentController#getPageParams:
| Name | Type | Attribute | Description |
| req | IncomingMessage |
|
The incoming message request object. |
| res | ServerResponse |
|
The server response object. |
| next | Function |
|
The next function to move to the next middleware. |
public getRandomContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source
Get a random item.
Override:
IContentController#getRandomContentParams:
| Name | Type | Attribute | Description |
| req | IncomingMessage |
|
The incoming message request object. |
| res | ServerResponse |
|
The server response object. |
| next | Function |
|
The next function to move to the next middleware. |
public registerRoutes(router: Object, PopApi: PopApi): undefined source
Default method to register the routes.
Override:
IController#registerRoutespublic sortContent(sort: string, order: number): Object source
Default method to sort the items.
Override:
IContentController#sortContentpublic updateContent(req: IncomingMessage, res: ServerResponse, next: Function): Promise<Object, Error> source
Update the info of one content item.
Override:
IContentController#updateContentParams:
| Name | Type | Attribute | Description |
| req | IncomingMessage |
|
The incoming message request object. |
| res | ServerResponse |
|
The server response object. |
| next | Function |
|
The next function to move to the next middleware. |
Manual
Reference
Source
Test
