This is a collection of JavaScript files that function as the API for resource management. The API provides functions for searching, filtering, and fetching resources from a database. The implementation of the database can be either MongoDB or JSON, depending on the value of the process.env.RESOURCES.isMongo environment variable.
The API is composed of the following files:
-
getResourcesByQuery.js: This file contains a wrapper function that invokes thegetResourcesByQueryfunction for either MongoDB or JSON, depending on the value ofisMongoof the Resource config. ThegetResourcesByQueryfunction is used for searching resources based on a query. It also takes in other parameters likecurrentPageandnPerPagewhich aid in pagination. -
getFilters.js: This file contains a wrapper function that invokes thegetFiltersfunction for either MongoDB or JSON, depending on the value ofisMongoof the Resource config. ThegetFiltersfunction is used for fetching the filtering options present on the website dynamically. -
getResourceByID.js: This file contains a wrapper function that invokes thegetResourceByIDfunction for either MongoDB or JSON, depending on the value ofisMongoof the Resource config. ThegetResourceByIDfunction is used for finding a resource by its exact ID, and throws an error if the database is invalid. -
getVersionsByID.js: ThegetVersionsByIDfunction retrieves versions of a resource with the given ID from a specified database. It determines the type of database by the value ofisMongoproperty in the environment variable. IfisMongois true, it calls thegetVersionsByIDMongoDBfunction to fetch versions from a MongoDB database. Otherwise, it calls thegetVersionsByIDJSONfunction to fetch versions from a JSON file. -
getTabs.js: ThegetTabsfunction takes in a JSON object res and returns an object with information about the required, optional, and metadata fields for a specific category. The function first fetches a schema from a specified URL, then recursively calls a helper function getRequiredFields() to determine which fields are required and which are optional for the given category. It then adds the required and optional fields from the schema to the respective arrays, removes any duplicate fields, removes any fields that are not in the resource, and adds the content of the fields to the corresponding objects in the arrays. Finally, it uses a tabs object to determine which fields should be in which tab and returns the required, optional, and metadata fields grouped accordingly.
Wrapper function to fetch the resources based on the query object.
Kind: global function
Returns: json - The resources in JSON format.
| Param | Type | Description |
|---|---|---|
| queryObject | json |
The query object. |
| currentPage | number |
The current page number. |
| pageSize | number |
The number of resources to be displayed per page. |
Gets the filters from the database.
Kind: global function
Returns: json - A json object with the filters.
Fetches a resource from the MongoDB database or JSON file.
Kind: global function
Returns: json - The resource in JSON format.
| Param | Type | Description |
|---|---|---|
| id | string |
The id of the resource to be fetched. |
| database | string |
The database of the resource from which the id should be fetched. |
| version | string |
The version of the resource to be fetched. |
Returns an object with information about the versions of a resource with the given ID from a specified database.
Kind: global function
Returns: json - The versions in JSON format.
| Param | Type | Description |
|---|---|---|
| id | string |
The id of the resource to be fetched. |
| database | string |
The database of the resource from which the id should be fetched. |
Returns an object with information about the required, optional, and metadata fields for a specific category
Kind: global function
Returns: json - Contains the required, optional and metadata tabs.
| Param | Type | Description |
|---|---|---|
| res | string |
The config for where the schema properties should lie ("required", "optional" or "metadata") |