adding user model and necessary basic fields

This commit is contained in:
Arjun Patel
2019-01-25 01:01:37 -08:00
parent 8c6f439f61
commit 598139c980
6 changed files with 95 additions and 1 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
module.exports = {
cause: require('./cause.controller'),
region: require('./region.controller'),
organization: require('./organization.controller')
organization: require('./organization.controller'),
user: require('./user.controller')
};
@@ -0,0 +1,31 @@
const db = require('../../config/db.config.js'),
errorMaker = require('../../helpers/error.maker');
const { Grant, Cause, Region, Organization, User } = db;
// POST an email into user general model from given email
exports.addEmail = (req, res, next) => {
User.findAll({
where: {
email: req.body.email
}
})
.then(users => {
if (users.length >= 1) {
return next(errorMaker(409, `Email Exists: ${req.body.email}`));
} else {
User.create({
email: req.body.email
})
.then(donor => {
// Send created user to client
return res.status(201).json({
message: 'User created',
donor
});
})
.catch(error => next(error));
}
})
.catch(error => next(error));
};