Within my application, both req.body
and req.user
are available for use. I am attempting to utilize both of these to generate a new document in the system. However, it appears that the Model.create function can only accept one input parameter. What would be the most effective approach to include both createdBy
and the content from req.body
when creating the new document?
exports.createOne = Model =>
catchAsync(async (req, res, next) => {
const createdBy = req.user.id;
const doc = await Model.create(req.body, createdBy);
res.status(201).json({
status: 'success',
data: {
data: doc
}
});
});