diff --git a/src/auth.js b/src/auth.js index 048051bb9d375333ed4d0cfe072fd0e9b3dd4578..58fc35fbe59ce09efd54fd179c0f75837fd6acf9 100644 --- a/src/auth.js +++ b/src/auth.js @@ -86,6 +86,14 @@ export function getSession() { } export class ResourceHandler { + /* + * The ResourceHandler manages access to the AMIVAPI for a given resource. + * It automatically handles: + * - authorization + * - etags + * - search queries + * - filtering out non-patchable keys + */ constructor(resource, searchKeys = false) { this.resource = resource; this.searchKeys = searchKeys || config[resource].searchKeys; @@ -95,7 +103,12 @@ export class ResourceHandler { checkAuthenticated(); } - // definitions of query parameters in addition to API go here + /* + * query is a dictionary of different queries + * Additional to anything specified from eve + * (http://python-eve.org/features.html#filtering) + * we support the key `search`, which is translated into a `where` filter + */ buildQuerystring(query) { const queryKeys = Object.keys(query); @@ -105,6 +118,8 @@ export class ResourceHandler { if ('search' in query && query.search.length > 0) { // translate search into where, we just look if any field contains search + // The search-string may match any of the keys in the object specified in the + // constructor const searchQuery = { $or: this.searchKeys.map((key) => { const fieldQuery = {};