CrudController

flitter-crud/CrudController~ CrudController

A controller with built-in create, read, update, delete methods that references a specific model.

Constructor

new CrudController()

Source:

Methods

create(req, res, next)

Source:

Create a new instance of the resource managed by this controller. Input taken from req.body is validated before the resource is created.

Parameters:
Name Type Description
req Express/Request

the Express request

res Express/Response

the Express response

next function

the error handler

delete(req, res, next)

Source:

Delete an instance of the resource managed by this controller with the ID "req.params.id".

Parameters:
Name Type Description
req Express/Request

the Express request

res Express/Response

the Express response

next function

the error handler

model() → {Mongoose/Model}

Source:

Get the registered model with the name of this controller's resource.

Returns:
Type
Mongoose/Model

name() → {string|null}

Source:

Get the name of the resource managed by this controller. Should be a Flitter canonical name.

Returns:

null

Type
string | null

read(req, res, next)

Source:

Retrieve an instance of the resource managed by this controller with the ID "req.params.id".

Parameters:
Name Type Description
req Express/Request

the Express request

res Express/Response

the Express response

next function

the error handler

send(res, bodyopt)

Source:

Send a JSON formatted, API-style response.

Parameters:
Name Type Attributes Default Description
res Express/Response

the Express response

body object <optional>
{}

the response information. Accepts the following fields, optionally: "status", "message", and "data"

update(req, res, next)

Source:

Update an instance of the resource managed by this controller with the ID "req.params.id". Any input taken from req.body is validated before updating.

Parameters:
Name Type Description
req Express/Request

the Express request

res Express/Response

the Express response

next function

the error handler

validator() → {module:flitter-forms/Validator~Validator}

Source:

Get the registered validator with the name of this controller's resource.

Returns:
Type
module:flitter-forms/Validator~Validator