43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
const db = require("../models/index");
|
|
const Auth = db.Auth;
|
|
|
|
checkDuplicateUsernameOrEmail = (req, res, next) => {
|
|
// Username
|
|
Auth.findOne({
|
|
where: {
|
|
email: req.body.email
|
|
}
|
|
}).then(auth => {
|
|
if (auth) {
|
|
res.status(400).send({
|
|
message: "Failed! Email is already in use!"
|
|
});
|
|
return;
|
|
}
|
|
|
|
next();
|
|
});
|
|
};
|
|
|
|
checkRolesExisted = (req, res, next) => {
|
|
if (req.body.roles) {
|
|
const ROLES = ['player', 'coach', 'admin'];
|
|
for (let i = 0; i < req.body.roles.length; i++) {
|
|
if (!ROLES.includes(req.body.roles[i])) {
|
|
res.status(400).send({
|
|
message: "Failed! Role does not exist = " + req.body.roles[i]
|
|
});
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
next();
|
|
};
|
|
|
|
const verifySignUp = {
|
|
checkDuplicateUsernameOrEmail: checkDuplicateUsernameOrEmail,
|
|
checkRolesExisted: checkRolesExisted
|
|
};
|
|
|
|
module.exports = verifySignUp; |