From 0d71d47cd7335d7538f280b3572cb0b3c5c0f799 Mon Sep 17 00:00:00 2001 From: T-vK Date: Fri, 8 Mar 2024 13:01:00 +0100 Subject: [PATCH] Fix support for modelFactory --- package.json | 2 +- src/express-restify-mongoose.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 0f90b61..d214161 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-restify-mongoose", - "version": "9.0.1", + "version": "9.0.2", "description": "Easily create a flexible REST interface for mongoose models", "keywords": [ "ReST", diff --git a/src/express-restify-mongoose.ts b/src/express-restify-mongoose.ts index d368b1d..a2409ca 100644 --- a/src/express-restify-mongoose.ts +++ b/src/express-restify-mongoose.ts @@ -96,9 +96,13 @@ export function serve( app.delete = app.del; } - app.use((req, res, next) => { - req.erm = {}; - + app.use(async (req, res, next) => { + const getModel = serveOptions?.modelFactory?.getModel; + + req.erm = { + model: typeof getModel === 'function' ? await getModel(req) : model, + }; + next(); });