Skip to content

Commit

Permalink
Fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sonsoleslp committed May 1, 2022
1 parent b8af6f1 commit 025fb23
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
42 changes: 26 additions & 16 deletions controllers/user_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,25 @@ exports.create = (req, res, next) => {
req.body.redir = redir;
next();
}).
catch(Sequelize.UniqueConstraintError, (error) => {
console.error(error);
req.flash("error", i18n.common.flash.errorExistingUser);
res.render("index", {user, "register": true, redir});
}).
catch(Sequelize.ValidationError, (error) => {
req.flash("error", i18n.common.validationError);
error.errors.forEach((err) => {
req.flash("error", validationError(err, i18n));
});
res.render("index", {user, "register": true, redir});
}).
catch((error) => next(error));
catch((error) => {
if (error instanceof Sequelize.UniqueConstraintError) {
req.flash("error", i18n.common.flash.errorExistingUser);
res.render("index", {user, "register": true, redir});
} else if (error instanceof Sequelize.ValidationError) {
req.flash("error", i18n.common.validationError);
error.errors.forEach((err) => {
req.flash("error", validationError(err, i18n));
});
// console.log(error.errors[0])
// console.log(error.errors[0].validatorArgs)
// console.log(error.errors[0].path)
// console.log(error.errors[0].validatorKey)
res.render("index", {user, "register": true, redir});
} else {
next(error);
}

}).catch(error=> next(error));
};

// GET /users/:userId/edit
Expand Down Expand Up @@ -141,9 +147,13 @@ exports.update = (req, res, next) => {
req.flash("success", scs);
res.redirect(`/users/${user_saved.id}/edit`);
}).
catch(Sequelize.ValidationError, (error) => {
error.errors.forEach(({message}) => req.flash("error", message));
res.render("users/edit", {user});
catch((error) => {
if (error instanceof Sequelize.ValidationError){
error.errors.forEach(({message}) => req.flash("error", message));
res.render("users/edit", {user});
} else {
next(error);
}
}).
catch((error) => next(error));
};
Expand Down
7 changes: 7 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,13 @@
"resetPassword" : "Reset password",
"save": "save"
},
"attributes": {
"surname": "Surname",
"name": "Name",
"username": "E-mail",
"password": "Password",
"gender": "Gender"
},
"role": "Role",
"teacher": "Teacher",
"student": "Student",
Expand Down
7 changes: 7 additions & 0 deletions i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,13 @@
"resetPassword" : "Recuperar contraseña",
"save": "guardar"
},
"attributes": {
"surname": "El apellido",
"name": "El nombre",
"username": "El e-mail",
"password": "La contraseña",
"gender": "El género"
},
"role": "Rol",
"teacher": "Profesor",
"student": "Alumno",
Expand Down
2 changes: 1 addition & 1 deletion views/partials/_puzzles_card.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<h3>
<span class="material-icons">check</span>
<label for="puzzles[<%=reto%>][correct]"><%=i18n.escapeRoom.steps.puzzles.successMsg%></label>
<input class="light" type="text" name="puzzles[<%=reto%>][correct]" id="puzzles[<%=reto%>][correct]" maxlength="10000" placeholder="<%=i18n.escapeRoom.play.correctAnswer%>" value="<%=puzzle.correct%>"/>
<input class="light" type="text" name="puzzles[<%=reto%>][correct]" id="puzzles[<%=reto%>][correct]" maxlength="10000" placeholder="<%=i18n.puzzle.correctAnswer%>" value="<%=puzzle.correct%>"/>
</h3>
<h3>
<span class="material-icons">close</span>
Expand Down

0 comments on commit 025fb23

Please sign in to comment.