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
}); });
+22 -7
View File
@@ -1,15 +1,30 @@
module.exports = (sequelize, DataTypes) => { module.exports = (sequelize, DataTypes) => {
const Donors = sequelize.define('donors', { const Donors = sequelize.define(
'donors',
{
id: { id: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
primaryKey: true, primaryKey: true,
autoIncrement: true autoIncrement: true
}, },
first_name: DataTypes.STRING, first_name: {
type: DataTypes.STRING,
allowNull: false
},
middle_name: DataTypes.STRING, middle_name: DataTypes.STRING,
last_name: DataTypes.STRING, last_name: {
email: DataTypes.STRING, type: DataTypes.STRING,
password: DataTypes.STRING, allowNull: false
},
email: {
type: DataTypes.STRING,
isEmail: true,
allowNull: false
},
password: {
type: DataTypes.STRING,
allowNull: false
},
age: DataTypes.INTEGER, age: DataTypes.INTEGER,
phone: DataTypes.BIGINT, phone: DataTypes.BIGINT,
address: DataTypes.STRING, address: DataTypes.STRING,
@@ -18,8 +33,8 @@ module.exports = (sequelize, DataTypes) => {
country: DataTypes.STRING country: DataTypes.STRING
}, },
{ {
freezeTableName: true, freezeTableName: true
} }
); );
return Donors; 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;