diff --git a/src/api.ts b/src/api.ts index 12f86d21..be72724c 100644 --- a/src/api.ts +++ b/src/api.ts @@ -79,6 +79,9 @@ export interface FernsRouterOptions { user?: User, query?: Record ) => Record | null | Promise | null>; + /** queryTransform is a function to transform the query params before they are used to query the database. This can be + * used to run intermediate queries to generate query fields for the main query. Runs before the queryFilter. */ + queryTransform?: (query: Record) => Record; /** Transformers allow data to be transformed before actions are executed, and serialized before being returned to * the user. * @@ -430,6 +433,10 @@ export function fernsRouter( mongoose.connection.db.collection(model.collection.collectionName); } + if (options.queryTransform) { + query = options.queryTransform(query); + } + // Check if any of the keys in the query are not allowed by options.queryFilter if (options.queryFilter) { let queryFilter;