первый коммит, надеюсь последний.
Сделанно: 1. минимально рабочий бэк 2. 2 модели 3. 1 миграция
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
const db = require("../models");
|
||||
const ROLES = db.ROLES;
|
||||
const User = db.user;
|
||||
|
||||
checkDuplicateUsernameOrEmail = (req, res, next) => {
|
||||
User.findOne({
|
||||
where: {
|
||||
username: req.body.username
|
||||
}
|
||||
}).then(user => {
|
||||
if (user) {
|
||||
res.status(400).send({
|
||||
message: "Ошибка. Такой ник уже есть."
|
||||
});
|
||||
return;
|
||||
}
|
||||
User.findOne({
|
||||
where: {
|
||||
email: req.body.email
|
||||
}
|
||||
}).then(user => {
|
||||
if (user) {
|
||||
res.status(400).send({
|
||||
message: "Ошибка. Такая почта уже есть."
|
||||
});
|
||||
return;
|
||||
}
|
||||
next();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
checkRolesExisted = (req, res, next) => {
|
||||
if (req.body.roles) {
|
||||
for (let i = 0; i < req.body.roles.length; i++) {
|
||||
if (!ROLES.includes(req.body.roles[i])) {
|
||||
res.status(400).send({
|
||||
message: "Ошибка. Нет такой роли = " + req.body.roles[i]
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
const verifySignUp = {
|
||||
checkDuplicateUsernameOrEmail: checkDuplicateUsernameOrEmail,
|
||||
checkRolesExisted: checkRolesExisted
|
||||
};
|
||||
|
||||
module.exports = verifySignUp;
|
||||
Reference in New Issue
Block a user