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

ContentService

ContentService class for the CRUD operations.

Test:

Constructor Summary

Public Constructor
public

constructor(options: Object)

Create a new ContentService.

Member Summary

Public Members
public

The model of the service.

public

The maximum items to display per page.

public

Simple projection for showing multiple content items.

public

The query of the service.

Method Summary

Public Methods
public

Insert the content into the database.

public

Insert multiple content models into the database.

public

Delete a content model.

public

Delete multiple content models from the database.

public

Get the content from the database with an id.

public

Get all the available pages.

public

Get content from one page.

public

Get random content.

public

Update the content.

public

Update multiple content models into the database.

Public Constructors

public constructor(options: Object) source

Create a new ContentService.

Params:

NameTypeAttributeDescription
options Object
  • nullable: false

The options for the content service.

options.Model MongooseModel
  • nullable: false

The model of the service.

options.projection Object
  • nullable: false

The projection of the service.

options.query Object
  • default: {}
  • nullable: false

The query of the service.

options.pageSize number
  • optional
  • default: 25
  • nullable: false

The page size of the service.

Test:

Public Members

public Model: MongooseModel source

The model of the service.

public pageSize: number source

The maximum items to display per page.

public projection: Object source

Simple projection for showing multiple content items.

public query: Object source

The query of the service.

Public Methods

public createContent(obj: Object): Promise<MongooseModel, Error> source

Insert the content into the database.

Params:

NameTypeAttributeDescription
obj Object
  • nullable: false

The object to insert.

Return:

Promise<MongooseModel, Error>

The created content.

Test:

public createMany(arr: Array<Object>): Promise<Array<MongooseModel>, Error> source

Insert multiple content models into the database.

Params:

NameTypeAttributeDescription
arr Array<Object>
  • nullable: false

The array of content to insert.

Return:

Promise<Array<MongooseModel>, Error>

The inserted content.

Test:

public deleteContent(id: string): Promise<MongooseModel, Error> source

Delete a content model.

Params:

NameTypeAttributeDescription
id string
  • nullable: false

The id of the content to delete.

Return:

Promise<MongooseModel, Error>

The deleted content.

Test:

public deleteMany(arr: Array<Object>): Promise<Array<MongooseModel>, Error> source

Delete multiple content models from the database.

Params:

NameTypeAttributeDescription
arr Array<Object>
  • nullable: false

The array of content to delete.

Return:

Promise<Array<MongooseModel>, Error>

The deleted content.

Test:

public getContent(id: string, projection: Object): Promise<MongooseModel, Error> source

Get the content from the database with an id.

Params:

NameTypeAttributeDescription
id string
  • nullable: false

The id of the content to get.

projection Object
  • nullable: false

The projection for the content.

Return:

Promise<MongooseModel, Error>

The details of the content.

Test:

public getContents(base: string): Promise<Array<string>, Error> source

Get all the available pages.

Params:

NameTypeAttributeDescription
base string
  • optional
  • default: ''
  • nullable: false

The base of the url to display.

Return:

Promise<Array<string>, Error>

A list of pages which are available.

Test:

public getPage(sort: Object, p: number, query: Object): Promise<Array<MongooseModel>, Error> source

Get content from one page.

Params:

NameTypeAttributeDescription
sort Object
  • nullable: true

The sort object to sort and order content.

p number
  • optional
  • default: 1
  • nullable: false

The page to get.

query Object
  • optional
  • default: this.query
  • nullable: false

A copy of the query object to get the objects.

Return:

Promise<Array<MongooseModel>, Error>

The content of one page.

Test:

public getRandomContent(): Promise<MongooseModel, Error> source

Get random content.

Return:

Promise<MongooseModel, Error>

Random content.

Test:

public updateContent(id: string, obj: Object): Promise<MongooseModel, Error> source

Update the content.

Params:

NameTypeAttributeDescription
id string
  • nullable: false

The id of the content to get.

obj Object
  • nullable: false

The object to update.

Return:

Promise<MongooseModel, Error>

The updated content.

Test:

public updateMany(arr: Array<Object>): Promise<Array<MongooseModel>, Error> source

Update multiple content models into the database.

Params:

NameTypeAttributeDescription
arr Array<Object>
  • nullable: false

The array of content to update.

Return:

Promise<Array<MongooseModel>, Error>

The updated content.

Test: