Helper functions for model operations in the Dobo framework.

Methods

(static) buildFilterQuery(filter) → {Object}

Builds a sanitized filter query for the given filter.

Parameters:
NameTypeDescription
filterObject

The filter object containing query parameters.

Returns:

The sanitized query object.

Type: 
Object

(static) buildFilterSearch(filter) → {Object}

Builds a search filter from the given filter object.

Parameters:
NameTypeDescription
filterObject

The filter object containing search parameters.

Returns:

The constructed search filter.

Type: 
Object

(async, static) clearCache(id) → {Promise.<void>}

Clears the cache for a specific record ID and related find operations.

Parameters:
NameTypeDescription
idstring | number

The ID of the record for which to clear the cache.

Returns:
Type: 
Promise.<void>

(static) cloneOptions(optionsopt) → {DoboModel.TOptions}

Clone options object and omit some keys to avoid reference issues

Parameters:
NameTypeAttributesDefaultDescription
optionsDoboModel.TOptions<optional>
{}
Returns:

Cloned options object

Type: 
DoboModel.TOptions

(async, static) copyAttachment(id, options) → {Promise.<Array>}

Copies attachments for a given record.

Parameters:
NameTypeDescription
idstring | number

The ID of the record.

optionsObject

Additional options for copying attachments.

Returns:

The copied attachment records.

Type: 
Promise.<Array>

(async, static) execDynHook(name, …args) → {Promise.<void>}

Executes a dynamic hook function with the provided name and arguments.

Parameters:
NameTypeAttributesDescription
namestring

The name of the dynamic hook to execute.

argsany<repeatable>

Arguments to pass to the dynamic hook function.

Returns:
Type: 
Promise.<void>

(async, static) execHook(name, …args) → {Promise.<void>}

Executes a hook function with the provided name and arguments.

Parameters:
NameTypeAttributesDescription
namestring

The name of the hook to execute.

argsany<repeatable>

Arguments to pass to the hook function.

Returns:
Type: 
Promise.<void>

(async, static) execModelHook(name, …args) → {Promise.<void>}

Executes a model hook function with the provided name and arguments.

Parameters:
NameTypeAttributesDescription
namestring

The name of the model hook to execute.

argsany<repeatable>

Arguments to pass to the model hook function.

Returns:
Type: 
Promise.<void>

(async, static) execValidation(body, optionsopt) → {Promise.<Object>}

Executes validation on the provided body with the given options.

Parameters:
NameTypeAttributesDefaultDescription
bodyObject

The data to validate.

optionsDoboModel.TOptions<optional>
{}

Validation options.

Returns:

The result of the validation.

Type: 
Promise.<Object>

(async, static) getAttachmentPath(id, field, file, options) → {Promise.<string>}

Gets the attachment path for a given record and field.

Parameters:
NameTypeDescription
idstring | number

The ID of the record.

fieldstring

The field name of the attachment.

filestring

The file name of the attachment.

optionsObject

Additional options, including dirOnly.

Returns:

The path to the attachment.

Type: 
Promise.<string>

(async, static) getFilterAndOptions(filter, options, action) → {Promise.<{filter: DoboModel.TFilter, options: DoboModel.TOptions}>}

Prepares and returns the filter and options for a given action.

Parameters:
NameTypeDescription
filterDoboModel.TFilter

The filter criteria.

optionsDoboModel.TOptions

The options for the action.

actionstring

The action being performed.

Returns:

The prepared filter and options.

Type: 
Promise.<{filter: DoboModel.TFilter, options: DoboModel.TOptions}>

(async, static) getRefs(records, options) → {Promise.<void>}

Gets reference records for the given records.

Parameters:
NameTypeDescription
recordsArray.<Object>

The records to get references for.

optionsObject

Additional options for fetching references.

Returns:
Type: 
Promise.<void>

(async, static) handleAttachmentUpload(id, trigger, options) → {Promise.<void>}

Handles attachment uploads for a given record and trigger.

Parameters:
NameTypeDescription
idstring | number

The ID of the record.

triggerstring

The action trigger (e.g., 'added', 'removed').

optionsObject

Additional options for handling the upload.

Returns:
Type: 
Promise.<void>

(async, static) handleReq(id, trigger, optionsopt) → {Promise.<void>}

Handles a request for a given action trigger.

Parameters:
NameTypeAttributesDefaultDescription
idstring | number

The ID of the record.

triggerstring

The action trigger (e.g., 'created', 'updated', 'removed').

optionsDoboModel.TOptions<optional>
{}

Additional options for handling the request.

Returns:
Type: 
Promise.<void>

(async, static) mergeAttachmentInfo(rec, source, options) → {Promise.<void>}

Merges attachment information into the given record.

Parameters:
NameTypeDescription
recObject

The record to merge attachment info into.

sourcestring

The source file path of the attachment.

optionsObject

Additional options including mimeType, stats, and fullPath.

Returns:
Type: 
Promise.<void>

(async, static) preparePagination(filter, options) → {Object}

Prepare pagination parameters for a query:

  • Ensures that the limit does not exceed the maximum allowed limit.
  • Ensures that the page number is within the allowed range.
  • Calculates the number of records to skip based on the page and limit.
  • Builds the sort order based on the provided sort input.
Parameters:
NameTypeDescription
filterDoboModel.TFilter

The filter object containing pagination parameters.

optionsDoboModel.TOptions

Additional options for pagination.

Returns:

The prepared pagination parameters including limit, page, skip, and sort.

Type: 
Object

(static) sanitizeQuery(query, parent) → {Object}

Sanitizes a query object by ensuring that its fields and values conform to the model's schema.

Parameters:
NameTypeDescription
queryObject

The query object to sanitize.

parentstring

The parent field name, if applicable.

Returns:

The sanitized query object.

Type: 
Object