indexResourceHelper

The function indexRecourceHelper is a REST API helper function used to get all documents from a collection. It takes in an options object and returns an async function that handles the indexing process.

indexRecourceHelper<T>(options: indexRecourceHelperOptions<T>) => (event: H3Event) => Promise<{
  totalPage: number;
  totalRecords: number;
  records: T[];
}>

The indexResourceHelper function accepts an options object with the following properties:

ArgumentTypeDescription
optionsindexRecourceHelperOptions<T>An object that provides configuration options for indexing.
options.modelModel<T>The model used for indexing.
options.relatedPopulateOptions[] | ((event: H3Event) => PopulateOptions[])Options for populating related data. It can be an array of PopulateOptions or a function that returns options based on an event.
options.beforeFnHook(event: H3Event) => voidA hook function to be executed before indexing.
options.afterFnHook(event: H3Event, response: { totalPage: number; totalRecords: number; records: T[] }) => voidA hook function to be executed after indexing. It receives the event and the indexing response.

PopulateOptions Object

PropertyTypeDescription
pathstringThe field path to populate.
selectstring | string[] | objectField(s) to select from the populated document(s).
modelstring | Model<any>The model to use for population.
matchobjectConditions to match against the populated documents.
optionsobjectAdditional query options for population.
populatestring | PopulateOptions | Array<PopulateOptions>The options to use for populating nested paths.
perDocumentLimitnumberLimit the number of populated documents per document. This option is only applicable when populating an array field.
justOnebooleanIf true, mongoose will populate only the first document from the array of referenced documents. This option is only applicable when populating an array field.
leanbooleanIf true, documents returned from queries with this populate will be lean.

The function returns a Promise that resolves to an object with properties totalPage, totalRecords, and records.