Function handlers for CRUD operations.

To use these handlers, you need to import them first and call them with the appropriate parameters.

Methods

(async, static) addHandler(opts) → {Promise.<string>}

Handler for rendering the add view of a model.

To use this handler, you must import it first and call it with the necessary parameters. For example:

const { importModule } = this.app.bajo
const addHandler = await importModule('waibuDb:/lib/crud/add-handler.js')
const result = await addHandler.call(this, { model: 'YourModelName', req, reply })
Parameters:
NameTypeDescription
optsobject

Options object

Properties
NameTypeAttributesDefaultDescription
reqobject

Request object

replyobject

Reply object

modelstring

Model name

templatestring

Template path

paramsobject<optional>
{}

Parameters for the template

addOnsHandlerfunction<optional>

Add-ons handler function

templateDisabledstring<optional>
'waibuDb.template:/disabled.html'

Disabled template path

optionsobject<optional>
{}

Additional options

Returns:

Renders the add view

Type: 
Promise.<string>

(async, static) allHandler(opts) → {Promise.<any>}

Handler for routing to the appropriate CRUD action based on the provided options.

To use this handler, you must import it first and call it with the necessary parameters. For example:

const { importModule } = this.app.bajo
const allHandler = await importModule('waibuDb:/lib/crud/all-handler.js')
const result = await allHandler.call(this, { model: 'YourModelName', action: 'list', req, reply })

For more information on the available actions, see THandlerMap.

Parameters:
NameTypeDescription
optsobject

Options object

Properties
NameTypeAttributesDefaultDescription
modelstring

Model name

actionstring

Action name

reqobject

Request object

replyobject

Reply object

templatestring<optional>

Template path

paramsobject<optional>
{}

Parameters for the template

optionsobject<optional>
{}

Additional options

Returns:

Result of the handler

Type: 
Promise.<any>

(async, static) deleteHandler(opts) → {Promise.<void>}

Handler for deleting records of a model.

To use this handler, you must import it first and call it with the necessary parameters. For example:

const { importModule } = this.app.bajo
const deleteHandler = await importModule('waibuDb:/lib/crud/delete-handler.js')
await deleteHandler.call(this, { model: 'YourModelName', req, reply })
Parameters:
NameTypeDescription
optsobject

Options object

Properties
NameTypeAttributesDefaultDescription
reqobject

Request object

replyobject

Reply object

modelstring

Model name

paramsobject<optional>
{}

Parameters for the template

templateDisabledstring<optional>
'waibuDb.template:/disabled.html'

Disabled template path

optionsobject<optional>
{}

Additional options

Returns:

Redirects to the list view

Type: 
Promise.<void>

(async, static) detailsHandler(opts) → {Promise.<string>}

Handler for rendering the details view of a model.

To use this handler, you must import it first and call it with the necessary parameters. For example:

const { importModule } = this.app.bajo
const detailsHandler = await importModule('waibuDb:/lib/crud/details-handler.js')
const result = await detailsHandler.call(this, { model: 'YourModelName', req, reply })
Parameters:
NameTypeDescription
optsobject

Options object

Properties
NameTypeAttributesDefaultDescription
reqobject

Request object

replyobject

Reply object

modelstring

Model name

paramsobject<optional>
{}

Parameters for the template

idstring<optional>

Record ID

templatestring<optional>

Template path

addOnsHandlerfunction<optional>

Add-ons handler function

templateDisabledstring<optional>
'waibuDb.template:/disabled.html'

Disabled template path

optionsobject<optional>
{}

Additional options

Returns:

Renders the details view

Type: 
Promise.<string>

(async, static) editHandler(opts) → {Promise.<string>}

Handler for rendering the edit view of a model.

To use this handler, you must import it first and call it with the necessary parameters. For example:

const { importModule } = this.app.bajo
const editHandler = await importModule('waibuDb:/lib/crud/edit-handler.js')
const result = await editHandler.call(this, { model: 'YourModelName', req, reply })
Parameters:
NameTypeDescription
optsobject

Options object

Properties
NameTypeAttributesDefaultDescription
reqobject

Request object

replyobject

Reply object

modelstring

Model name

idstring<optional>

Record ID

paramsobject<optional>
{}

Parameters for the template

templatestring<optional>

Template path

addOnsHandlerfunction<optional>

Add-ons handler function

templateDisabledstring<optional>
'waibuDb.template:/disabled.html'

Disabled template path

optionsobject<optional>
{}

Additional options

Returns:

Renders the edit view

Type: 
Promise.<string>

(async, static) exportHandler(opts) → {Promise.<void>}

Handler for rendering the export view of a model.

To use this handler, you must import it first and call it with the necessary parameters. For example:

const { importModule } = this.app.bajo
const exportHandler = await importModule('waibuDb:/lib/crud/export-handler.js')
await exportHandler.call(this, { model: 'YourModelName', req, reply })
Parameters:
NameTypeDescription
optsobject

Options object

Properties
NameTypeAttributesDefaultDescription
reqobject

Request object

replyobject

Reply object

modelstring

Model name

paramsobject<optional>
{}

Parameters for the template

templateDisabledstring<optional>
'waibuDb.template:/disabled.html'

Disabled template path

optionsobject<optional>
{}

Additional options

Returns:

Redirect to the list view

Type: 
Promise.<void>

(async, static) listHandler(opts) → {Promise.<string>}

Handle the list view for a given model, rendering the appropriate template with the retrieved data.

To use this handler, you must import it first and call it with the necessary parameters. For example:

const { importModule } = this.app.bajo
const listHandler = await importModule('waibuDb:/lib/crud/list-handler.js')
const result = await listHandler.call(this, { model: 'YourModelName', req, reply })
Parameters:
NameTypeDescription
optsobject

Options object

Properties
NameTypeAttributesDefaultDescription
reqobject

Request object

replyobject

Reply object

modelstring

Model name

templatestring

Template path

paramsobject<optional>
{}

Parameters for the template

addOnsHandlerfunction<optional>

Add-ons handler function

templateDisabledstring<optional>
'waibuDb.template:/disabled.html'

Disabled template path

optionsobject<optional>
{}

Additional options

Returns:

Renders the list view

Type: 
Promise.<string>

Type Definitions

THandlerMap

Map of CRUD action names to their corresponding handler functions.

Type:
  • Object
Properties
NameTypeDescription
addfunction

Handler for the addHandler action

deletefunction

Handler for the deleteHandler action

detailsfunction

Handler for the detailsHandler action

editfunction

Handler for the editHandler action

exportfunction

Handler for the exportHandler action

listfunction

Handler for the listHandler action