Class: Controller

Controller

new Controller(resources)

A core constructor that provides numerous controller helper functions.

Parameters:
Name Type Description
resources object

variable injection from resources from instantiated periodic express app

Author:
  • Yaw Joseph Etse
License:
  • MIT
Source:

Requires

  • module:fs-extra
  • module:path
  • module:periodicjs.core.utilities

Methods

createModel(options) → {object}

short hand mongoose create document query

Parameters:
Name Type Description
options object

model,newdoc - document to insert, req, res,callback, successredirect, appendid - append the id of newly created document on redirect

Source:
Returns:

responseData or redirected page

Type
object

deleteModel(options) → {function}

short hand mongoose delete document query

Parameters:
Name Type Description
options object

model,deleteid - id to delete,callback

Source:
Returns:

callback(err)

Type
function

getPluginViewDefaultTemplate(options, callback) → {function}

Gets the path to the view file specified, first look at custom theme views, then extension views, then default views

Parameters:
Name Type Description
options object

extname, themename, themefileext - support custom theme files

callback function

async callback

Source:
Returns:

async callback(err,viewname)

Type
function

handleDocumentQueryErrorResponse(options) → {object}

default response handler for error, or will redirect with flash error set

Parameters:
Name Type Description
options object

err,req,res,callback

Source:
Returns:

response object render or callback

Type
object

handleDocumentQueryRender(options) → {object}

default response handler for express views, or will redirect to another request

Parameters:
Name Type Description
options object

res,req,redirecturl,err,callback,responseData - this is what's sent to the rendered template view, also appends http request information like base url, query string parameters, etc

Source:
Returns:

response object render or callback

Type
object

loadModel(options) → {function}

short hand mongoose load document query

Parameters:
Name Type Description
options object

model,docid - id or name,callback,population -mongoose population, selection - mongoose selection

Source:
Returns:

callback(err,document)

Type
function

searchModel(options) → {function}

short hand mongoose search documents query

Parameters:
Name Type Description
options object

model,query - mongoose query,callback,population -mongoose population, selection - mongoose selection , limit, offset

Source:
Returns:

callback(err,documents)

Type
function

updateModel(options) → {object}

short hand mongoose update document query

Parameters:
Name Type Description
options object

model, id - objectid of mongoose document,updatedoc - document to update, req, res,callback, successredirect, appendid - append the id of newly created document on redirect, removefromarray - sets the update operation to manipulate an array of documents with mongo $pull, appendArray - sets the update operation to manipulate an array of documents with mongo $push, saverevision - save revisions

Source:
Returns:

responseData or redirected page

Type
object