Class Controller
Defined in: | src/controller.coffee |
Overview
Instance Method Summary
- ::constructor(options) create a new controller from a model and params
- ::destroy(req, res, next) Bound express handler to destroy the @reqParamID model (dont get the model before destroy)
- ::fetch(req, res, next, id) Bound express handler to be link a model to the request set a req[@reqProp] with the model found from the param id.
- ::find(req, res, next) Bound 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
- ::listAll(req, res, next) Bound express handler to send the result of request 'all'
- ::send(req, res, next) Bound express handler to send the @reqProp model
- ::sendAttachment(options = {}) Bound express handler to send a file (no need for a ::find or ::fetch before)
- ::sendBinary(options = {}) express handler to send a file (no need for a ::find or ::fetch before)
- ::update(req, res, next) Bound express handler to update the @reqParamID model with request body (dont get the model before update)
Constructor Details
::constructor(options) Source
Examples:
Note = new cozydb.getModel 'Note', SCHEMA
baseController = cozydb.SimpleController
model: Note
reqProp: 'note'
reqParamID: 'noteid'
Instance Method Details
::destroy(req, res, next) (bound) Source
Examples:
app.del 'note/:noteid', baseController.destroy
::fetch(req, res, next, id) (bound) Source
Examples:
app.param 'noteid', baseController.fetch
::find(req, res, next) (bound) Source
Examples:
app.get '/note/:noteid', [
baseController.fetch,
baseController.send
]
::listAll(req, res, next) (bound) Source
Examples:
app.get '/notes/', baseController.listAll
::send(req, res, next) (bound) Source
::sendAttachment(options = {}) (bound) Source
Examples:
handler = baseController.sendAttachment filename: 'picture'
app.get 'contact/:contactid.jpg',
::sendBinary(options = {}) Source
Examples:
handler = baseController.sendAttachment filename: 'picture'
app.get 'contact/:contactid.jpg',
::update(req, res, next) (bound) Source
Examples:
app.put 'note/:noteid', baseController.update