changes to organization model

This commit is contained in:
Arjun Patel
2019-03-01 23:38:22 -08:00
parent d14e111f53
commit 571c3931c2
4 changed files with 70 additions and 7 deletions
+1
View File
@@ -7,6 +7,7 @@ const { Donor, Organization } = db;
// Find a Donor/Org by email + login with JWT // Find a Donor/Org by email + login with JWT
exports.login = (type, role) => (req, res, next) => { exports.login = (type, role) => (req, res, next) => {
console.log('haha');
const curr_types = { const curr_types = {
donor: Donor, donor: Donor,
org: Organization org: Organization
@@ -5,7 +5,6 @@ const db = require('../../config/db.config.js'),
const { Grant, Cause, Region, Organization } = db; const { Grant, Cause, Region, Organization } = db;
// POST create an organization // POST create an organization
// Temporarily only use: name, email, password, short_description, primary_cause, primary_region
exports.create = async (req, res, next) => { exports.create = async (req, res, next) => {
let { let {
name, name,
@@ -13,7 +12,17 @@ exports.create = async (req, res, next) => {
password, password,
short_description, short_description,
primary_cause, primary_cause,
primary_region primary_region,
ein,
primary_contact_first_name,
primary_contact_last_name,
phone,
country,
address,
city,
zip,
estimate_assets,
estimate_year_operating_cost
} = req.body; } = req.body;
primary_cause = primary_cause.trim().toLowerCase(); primary_cause = primary_cause.trim().toLowerCase();
@@ -44,7 +53,7 @@ exports.create = async (req, res, next) => {
type: db.Sequelize.QueryTypes.SELECT type: db.Sequelize.QueryTypes.SELECT
}); });
// could not find the cause or region in the db, so add // cause or region not found
if (!causes.length) { if (!causes.length) {
await Cause.create({ name: primary_cause }, { transaction }); await Cause.create({ name: primary_cause }, { transaction });
} }
@@ -53,7 +62,7 @@ exports.create = async (req, res, next) => {
} }
const saltRounds = await bcrypt.genSaltSync(10); const saltRounds = await bcrypt.genSaltSync(10);
// hash // hash with salt rounds
const hashedPass = await bcrypt.hashSync(password, saltRounds); const hashedPass = await bcrypt.hashSync(password, saltRounds);
// Store hash in DB // Store hash in DB
@@ -63,7 +72,17 @@ exports.create = async (req, res, next) => {
password: hashedPass, //hashed password password: hashedPass, //hashed password
short_description, short_description,
primary_cause, primary_cause,
primary_region primary_region,
ein,
primary_contact_first_name,
primary_contact_last_name,
phone,
country,
address,
city,
zip,
estimate_assets,
estimate_year_operating_cost
}); });
await transaction.commit(); await transaction.commit();
+4 -1
View File
@@ -5,8 +5,11 @@ module.exports = role => (req, res, next) => {
try { try {
const token = req.headers.authorization.split(' ')[1]; const token = req.headers.authorization.split(' ')[1];
const decoded = jwt.verify(token, process.env.JWT_KEY); const decoded = jwt.verify(token, process.env.JWT_KEY);
req.user = decoded; //for use till end of request
// user info till end of request
req.user = decoded;
// verify role of the call
if (role != req.user.role) { if (role != req.user.role) {
throw new Error(); throw new Error();
} }
+41 -1
View File
@@ -13,6 +13,26 @@ module.exports = (sequelize, DataTypes) => {
}, },
allowNull: false allowNull: false
}, },
phone: {
type: DataTypes.STRING,
allowNull: false
},
address: {
type: DataTypes.STRING,
allowNull: false
},
city: {
type: DataTypes.STRING,
allowNull: false
},
country: {
type: DataTypes.STRING,
allowNull: false
},
zip: {
type: DataTypes.STRING,
allowNull: false
},
password: { password: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false
@@ -25,7 +45,27 @@ module.exports = (sequelize, DataTypes) => {
short_description: DataTypes.STRING, short_description: DataTypes.STRING,
primary_cause: { type: DataTypes.STRING, allowNull: false }, primary_cause: { type: DataTypes.STRING, allowNull: false },
primary_region: { type: DataTypes.STRING, allowNull: false }, primary_region: { type: DataTypes.STRING, allowNull: false },
rating: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false } rating: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false },
ein: {
type: DataTypes.STRING,
allowNull: false
},
estimate_assets: {
type: DataTypes.BIGINT,
defaultValue: 0
},
estimate_year_operating_cost: {
type: DataTypes.INTEGER,
defaultValue: 0
},
primary_contact_first_name: {
type: DataTypes.STRING,
allowNull: false
},
primary_contact_last_name: {
type: DataTypes.STRING,
allowNull: false
}
}); });
return Organization; return Organization;
}; };