In mongoose there is one pattern i keep repeating:
Model.method(someParameterOrCondition, callback(error, result)=>{
if (error) return console.log(error)
done(null, result)
})
The callback is repeating everytime and each time i have to write it from start to bottom. I cant figure out how(if its possible) to declare it once and just reference to it in every method?
I am sorry, you are right, i think i have figured out why my attempts fail and there was no way someone would help me with the little info i gave initially.
Ill give a particular problem example, here is the task:
I havent included the prerequisite code, lets assume it correct as my solution passes the tests.
I want to move the callback which i employ in the .save() method outside of the createAndSavePerson body, to be able to use it in following solutions as majority of them use same construction. What i guess was failing my approach is i dont have access to the done parameter. The problem is i dont even know how the createAndSavePerson is called, where this parameter comes from and in what shape or form . I can only assume its the done function which is used in the end each time and somehow i need to reference to it in my own custom callback