specs for donors model

This commit is contained in:
Arjun Patel
2019-01-12 14:03:34 -08:00
parent ec2a3b5362
commit 43bf237942
3 changed files with 56 additions and 36 deletions
+1 -8
View File
@@ -18,10 +18,7 @@ exports.create = (req, res) => {
}); });
} else { } else {
// hash and store // hash and store
bcrypt.hash(req.body.password, null, null, function( bcrypt.hash(req.body.password, null, null, function(error, hash) {
error,
hash
) {
// Store hash in your password DB. // Store hash in your password DB.
if (error) { if (error) {
return res.status(500).json({ return res.status(500).json({
@@ -49,8 +46,6 @@ exports.create = (req, res) => {
}); });
}) })
.catch(error => { .catch(error => {
console.log(error);
return res.status(500).json({ return res.status(500).json({
error error
}); });
@@ -60,8 +55,6 @@ exports.create = (req, res) => {
} }
}) })
.catch(error => { .catch(error => {
console.log(error);
return res.status(500).json({ return res.status(500).json({
error error
}); });
+39 -24
View File
@@ -1,25 +1,40 @@
module.exports = (sequelize, DataTypes) => { module.exports = (sequelize, DataTypes) => {
const Donors = sequelize.define('donors', { const Donors = sequelize.define(
id: { 'donors',
type: DataTypes.INTEGER, {
primaryKey: true, id: {
autoIncrement: true type: DataTypes.INTEGER,
}, primaryKey: true,
first_name: DataTypes.STRING, autoIncrement: true
middle_name: DataTypes.STRING, },
last_name: DataTypes.STRING, first_name: {
email: DataTypes.STRING, type: DataTypes.STRING,
password: DataTypes.STRING, allowNull: false
age: DataTypes.INTEGER, },
phone: DataTypes.BIGINT, middle_name: DataTypes.STRING,
address: DataTypes.STRING, last_name: {
city: DataTypes.STRING, type: DataTypes.STRING,
state: DataTypes.STRING, allowNull: false
country: DataTypes.STRING },
}, email: {
{ type: DataTypes.STRING,
freezeTableName: true, isEmail: true,
} allowNull: false
); },
return Donors; password: {
} type: DataTypes.STRING,
allowNull: false
},
age: DataTypes.INTEGER,
phone: DataTypes.BIGINT,
address: DataTypes.STRING,
city: DataTypes.STRING,
state: DataTypes.STRING,
country: DataTypes.STRING
},
{
freezeTableName: true
}
);
return Donors;
};
+16 -4
View File
@@ -17,10 +17,7 @@ app.use((req, res, next) => {
); );
if (req.method == 'OPTIONS') { if (req.method == 'OPTIONS') {
res.header( res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, PATCH');
'Access-Control-Allow-Methods',
'PUT, POST, GET, DELETE, PATCH'
);
return res.status(200).json({}); return res.status(200).json({});
} }
@@ -52,6 +49,21 @@ app.get('/', function(req, res, next) {
app.use('/api/donors', require('./app/routes/donors.route.js')); app.use('/api/donors', require('./app/routes/donors.route.js'));
app.use('/api/auth', require('./app/routes/auth.route.js')); app.use('/api/auth', require('./app/routes/auth.route.js'));
app.use((req, res, next) => {
const error = new Error('Not found');
error.status = 404;
next(error);
});
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: {
message: error.message
}
});
});
// Create a Server // Create a Server
var server = app.listen(port, function() { var server = app.listen(port, function() {
var host = server.address().address; var host = server.address().address;