P.S I probably didn't quite understand the mvc principle, but I always thought that business logic should happen in models - correct me if I'm wrong
I am writing project and using the mvc pattern. router accepts requests and passes to controller, it takes data and sends it to model. Model checks the data for validation and, if successful, works with the database. My models have very large code and mix with validation.
exports.modelFunction = (data) => {
// validation data ...
// working with the database
}
With new fixes it becomes difficult for me to read the code.
I decided to create a utils / validation / folder where I will handle all possible model validations and yes, now the code is more readable
exports.modelFunction = (data) => {
const validation = validationModel(data);
if (!validation) return {ok: false, message: 'Validation failed'}
// working with the database
}
I thought that there are already some other patterns that adhere to the separation of logic and solve problems like mine. So I decided to ask you for a hint.
Aucun commentaire:
Enregistrer un commentaire