Class Controller

Defined in: src/controller.coffee

Overview

Public: minimalist convenience controller

Instance Method Summary

Constructor Details

::constructor(options) Source

Public: create a new controller from a model and params options - Object options :model - String model to be used :reqParamID - String name of the req param for model id :reqProp - String name of the req property where the model will be placed Returns null Examples Note = new cozydb.getModel 'Note', SCHEMA baseController = cozydb.SimpleController model: Note reqProp: 'note' reqParamID: 'noteid'

Examples:

Note = new cozydb.getModel 'Note', SCHEMA
baseController = cozydb.SimpleController
     model: Note
     reqProp: 'note'
     reqParamID: 'noteid' 

Parameters:

  • (Object) optionsObject options
    • (String) modelString model to be used
    • (String) reqParamIDString name of the req param for model id
    • (String) reqPropString name of the req property where the model will be placed

Returns:

  • Returns null

Instance Method Details

::destroy(req, res, next) (bound) Source

Public: express handler to destroy the @reqParamID model (dont get the model before destroy) Returns null Examples app.del 'note/:noteid', baseController.destroy

Examples:

app.del 'note/:noteid', baseController.destroy 

Returns:

  • Returns null

::fetch(req, res, next, id) (bound) Source

Public: express handler to be link a model to the request set a req[@reqProp] with the model found from the param id. You should use this or ::find but not both Returns null Examples app.param 'noteid', baseController.fetch

Examples:

app.param 'noteid', baseController.fetch 

Returns:

  • Returns null

::find(req, res, next) (bound) Source

Public: express handler to link a model to the request set a req[@reqProp] with the model found from the param @reqParamID You should use this or ::fetch but not both Returns null Examples app.get '/note/:noteid', [ baseController.fetch, baseController.send ]

Examples:

app.get '/note/:noteid', [
     baseController.fetch,
     baseController.send
] 

Returns:

  • Returns null

::listAll(req, res, next) (bound) Source

Public: express handler to send the result of request 'all' Returns null Examples app.get '/notes/', baseController.listAll

Examples:

app.get '/notes/', baseController.listAll 

Returns:

  • Returns null

::send(req, res, next) (bound) Source

Public: express handler to send the @reqProp model Returns null

Returns:

  • Returns null

::sendAttachment(options = {}) (bound) Source

Public: express handler to send a file (no need for a ::find or ::fetch before) options - :reqParamFilename - get the filename to send from this req.param :filename - set the filename :download - force download (content-disposition attachment) Examples handler = baseController.sendAttachment filename: 'picture' app.get 'contact/:contactid.jpg',

Examples:

handler = baseController.sendAttachment filename: 'picture'
 app.get 'contact/:contactid.jpg',

Parameters:

  • options -
    • reqParamFilenameget the filename to send from this req.param
    • filenameset the filename
    • downloadforce download (content-disposition attachment)

::sendBinary(options = {}) Source

Public: express handler to send a file (no need for a ::find or ::fetch before) options - :reqParamFilename - get the filename to send from this req.param :filename - set the filename Examples handler = baseController.sendAttachment filename: 'picture' app.get 'contact/:contactid.jpg',

Examples:

handler = baseController.sendAttachment filename: 'picture'
 app.get 'contact/:contactid.jpg',

Parameters:

  • options -
    • reqParamFilenameget the filename to send from this req.param
    • filenameset the filename

::update(req, res, next) (bound) Source

Public: express handler to update the @reqParamID model with request body (dont get the model before update) Returns null Examples app.put 'note/:noteid', baseController.update

Examples:

app.put 'note/:noteid', baseController.update 

Returns:

  • Returns null