I have successfully implemented code that retrieves all users from my neDB-promisses:
const fetchAllUsers = (res) => { db.find({}) .sort({ name: 1 }) .exec() .then( (content) => { res.status(200).json(content); }, (err) => { res.status(400).json(err); } ); };
Now, I am aiming to optimize this code to prevent future redundancy in CRUD functions. I envision something like the following:
... .then(successFunctionCall, failureFunctionCall) ...
I considered designing a separate module named successFunctionCall/failureFunctionCall, but I am faced with the challenge of needing to invoke res within it to define the response JSON and status code. Is there a more efficient approach to accomplishing this?
Thank you.