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:
Argument | Type | Description |
---|---|---|
options | indexRecourceHelperOptions<T> | An object that provides configuration options for indexing. |
options.model | Model<T> | The model used for indexing. |
options.related | PopulateOptions[] | ((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) => void | A hook function to be executed before indexing. |
options.afterFnHook | (event: H3Event, response: { totalPage: number; totalRecords: number; records: T[] }) => void | A hook function to be executed after indexing. It receives the event and the indexing response. |
PopulateOptions
Object
Property | Type | Description |
---|---|---|
path | string | The field path to populate. |
select | string | string[] | object | Field(s) to select from the populated document(s). |
model | string | Model<any> | The model to use for population. |
match | object | Conditions to match against the populated documents. |
options | object | Additional query options for population. |
populate | string | PopulateOptions | Array<PopulateOptions> | The options to use for populating nested paths. |
perDocumentLimit | number | Limit the number of populated documents per document. This option is only applicable when populating an array field. |
justOne | boolean | If true , mongoose will populate only the first document from the array of referenced documents. This option is only applicable when populating an array field. |
lean | boolean | If 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
.