CrudController

flitter-crud/CrudController~ CrudController

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


Constructor

new CrudController()

Extends

Members

(static) services

Defines the services required by this controller.

Methods

create(req, res, next)

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)

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

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

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

model() → {module:flitter-orm/src/model/Model~Model}

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

name() → {string|null}

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)

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)

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)

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