changes to organization model
This commit is contained in:
@@ -8,21 +8,29 @@ const { Grant, Cause, Region, Organization } = db;
|
|||||||
exports.create = async (req, res, next) => {
|
exports.create = async (req, res, next) => {
|
||||||
let {
|
let {
|
||||||
name,
|
name,
|
||||||
email,
|
|
||||||
password,
|
|
||||||
short_description,
|
short_description,
|
||||||
primary_cause,
|
|
||||||
primary_region,
|
primary_contact_email,
|
||||||
ein,
|
password,
|
||||||
primary_contact_first_name,
|
|
||||||
primary_contact_last_name,
|
|
||||||
phone,
|
|
||||||
country,
|
|
||||||
address,
|
address,
|
||||||
city,
|
city,
|
||||||
|
state,
|
||||||
|
country,
|
||||||
zip,
|
zip,
|
||||||
|
|
||||||
|
primary_cause,
|
||||||
|
primary_region,
|
||||||
|
|
||||||
|
ein,
|
||||||
estimate_assets,
|
estimate_assets,
|
||||||
estimate_year_operating_cost
|
estimate_year_operating_cost,
|
||||||
|
|
||||||
|
isNonprofit,
|
||||||
|
|
||||||
|
primary_contact_phone,
|
||||||
|
primary_contact_first_name,
|
||||||
|
primary_contact_last_name
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
primary_cause = primary_cause.trim().toLowerCase();
|
primary_cause = primary_cause.trim().toLowerCase();
|
||||||
@@ -33,10 +41,12 @@ exports.create = async (req, res, next) => {
|
|||||||
try {
|
try {
|
||||||
transaction = await db.sequelize.transaction();
|
transaction = await db.sequelize.transaction();
|
||||||
|
|
||||||
const orgs = await Organization.findAll({ where: { email } });
|
const orgs = await Organization.findAll({
|
||||||
|
where: { primary_contact_email }
|
||||||
|
});
|
||||||
|
|
||||||
if (orgs.length >= 1) {
|
if (orgs.length >= 1) {
|
||||||
return next(errorMaker(409, `Email Exists: ${email}`));
|
return next(errorMaker(409, `Email Exists: ${primary_contact_email}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
const CAUSE_QUERY = `SELECT name FROM causes
|
const CAUSE_QUERY = `SELECT name FROM causes
|
||||||
@@ -59,27 +69,35 @@ exports.create = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const saltRounds = await bcrypt.genSaltSync(10);
|
const saltRounds = await bcrypt.genSaltSync(10);
|
||||||
// hash with salt rounds
|
// 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
|
||||||
const org = await Organization.create({
|
const org = await Organization.create({
|
||||||
name,
|
name,
|
||||||
email,
|
|
||||||
password: hashedPass, //hashed password
|
|
||||||
short_description,
|
short_description,
|
||||||
primary_cause,
|
|
||||||
primary_region,
|
primary_contact_email,
|
||||||
ein,
|
password: hashedPass,
|
||||||
primary_contact_first_name,
|
|
||||||
primary_contact_last_name,
|
|
||||||
phone,
|
|
||||||
country,
|
|
||||||
address,
|
address,
|
||||||
city,
|
city,
|
||||||
|
state,
|
||||||
|
country,
|
||||||
zip,
|
zip,
|
||||||
|
|
||||||
|
primary_cause,
|
||||||
|
primary_region,
|
||||||
|
|
||||||
|
ein,
|
||||||
estimate_assets,
|
estimate_assets,
|
||||||
estimate_year_operating_cost
|
estimate_year_operating_cost,
|
||||||
|
|
||||||
|
isNonprofit,
|
||||||
|
|
||||||
|
primary_contact_phone,
|
||||||
|
primary_contact_first_name,
|
||||||
|
primary_contact_last_name
|
||||||
});
|
});
|
||||||
|
|
||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
const uuidv4 = require('uuid/v4');
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const Donor = sequelize.define('donors', {
|
const Donor = sequelize.define('donors', {
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.UUID,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
autoIncrement: true
|
defaultValue: uuidv4()
|
||||||
},
|
},
|
||||||
stripe_id: {
|
stripe_id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
@@ -28,17 +30,20 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
validate: {
|
validate: {
|
||||||
isEmail: true
|
isEmail: true
|
||||||
},
|
},
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: true
|
||||||
},
|
},
|
||||||
password: {
|
password: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
age: DataTypes.INTEGER,
|
age: DataTypes.INTEGER,
|
||||||
phone: DataTypes.BIGINT,
|
phone: DataTypes.DataTypes.STRING(20),
|
||||||
|
|
||||||
address: DataTypes.STRING,
|
address: DataTypes.STRING,
|
||||||
city: DataTypes.STRING,
|
city: DataTypes.STRING,
|
||||||
state: DataTypes.STRING,
|
state: DataTypes.STRING,
|
||||||
|
zip: DataTypes.STRING(10),
|
||||||
country: DataTypes.STRING
|
country: DataTypes.STRING
|
||||||
});
|
});
|
||||||
return Donor;
|
return Donor;
|
||||||
|
|||||||
@@ -1,22 +1,28 @@
|
|||||||
|
const uuidv4 = require('uuid/v4');
|
||||||
|
|
||||||
module.exports = (sequelize, DataTypes) => {
|
module.exports = (sequelize, DataTypes) => {
|
||||||
const Organization = sequelize.define('organizations', {
|
const Organization = sequelize.define('organizations', {
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.UUID,
|
||||||
primaryKey: true,
|
primaryKey: true,
|
||||||
autoIncrement: true
|
defaultValue: uuidv4()
|
||||||
},
|
},
|
||||||
name: { type: DataTypes.STRING, allowNull: false },
|
name: { type: DataTypes.STRING, allowNull: false },
|
||||||
email: {
|
short_description: { type: DataTypes.STRING, allowNull: false },
|
||||||
|
|
||||||
|
primary_contact_email: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
validate: {
|
validate: {
|
||||||
isEmail: true
|
isEmail: true
|
||||||
},
|
},
|
||||||
allowNull: false
|
allowNull: false,
|
||||||
|
unique: true
|
||||||
},
|
},
|
||||||
phone: {
|
password: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
|
|
||||||
address: {
|
address: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
@@ -25,29 +31,27 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
|
state: {
|
||||||
|
type: DataTypes.STRING(5),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
country: {
|
country: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
|
defaultValue: 'USA',
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
zip: {
|
zip: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING(10),
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
password: {
|
|
||||||
type: DataTypes.STRING,
|
|
||||||
allowNull: false
|
|
||||||
},
|
|
||||||
verified: {
|
|
||||||
type: DataTypes.BOOLEAN,
|
|
||||||
allowNull: false,
|
|
||||||
defaultValue: false
|
|
||||||
},
|
|
||||||
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 },
|
|
||||||
|
total_rating: { type: DataTypes.INTEGER, defaultValue: 0 },
|
||||||
|
|
||||||
ein: {
|
ein: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.INTEGER,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
},
|
},
|
||||||
estimate_assets: {
|
estimate_assets: {
|
||||||
@@ -58,6 +62,22 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isNonprofit: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
isVerified: {
|
||||||
|
type: DataTypes.BOOLEAN,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false
|
||||||
|
},
|
||||||
|
|
||||||
|
primary_contact_phone: {
|
||||||
|
type: DataTypes.STRING(20),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
primary_contact_first_name: {
|
primary_contact_first_name: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: false
|
allowNull: false
|
||||||
|
|||||||
+2
-1
@@ -31,7 +31,8 @@
|
|||||||
"mysql2": "^1.6.4",
|
"mysql2": "^1.6.4",
|
||||||
"sequelize": "^4.42.0",
|
"sequelize": "^4.42.0",
|
||||||
"sequelize-cli": "^5.4.0",
|
"sequelize-cli": "^5.4.0",
|
||||||
"stripe": "^6.22.0"
|
"stripe": "^6.22.0",
|
||||||
|
"uuid": "^3.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dotenv-flow": "^0.2.0"
|
"dotenv-flow": "^0.2.0"
|
||||||
|
|||||||
@@ -5,22 +5,30 @@ module.exports = {
|
|||||||
return queryInterface.bulkInsert('organizations', [
|
return queryInterface.bulkInsert('organizations', [
|
||||||
{
|
{
|
||||||
name: 'Gopala Goshala',
|
name: 'Gopala Goshala',
|
||||||
email: 'kcp1982@yahoo.com',
|
|
||||||
password: hashedPass, //hashed password
|
|
||||||
short_description:
|
short_description:
|
||||||
'We are focused on bringing lawful animal treatment in North India. Check out our many projects such as city water fountains for animals',
|
'We are focused on bringing lawful animal treatment in North India. Check out our many projects such as city water fountains for animals',
|
||||||
|
|
||||||
|
primary_contact_email: 'kcp1982@yahoo.com',
|
||||||
|
password: hashedPass,
|
||||||
|
|
||||||
|
address: '14872 Waverly Lane',
|
||||||
|
city: 'Irvine',
|
||||||
|
country: 'USA',
|
||||||
|
state: 'CA',
|
||||||
|
zip: '92604',
|
||||||
|
|
||||||
primary_cause: 'Animal',
|
primary_cause: 'Animal',
|
||||||
primary_region,
|
primary_region: '',
|
||||||
|
|
||||||
ein,
|
ein,
|
||||||
primary_contact_first_name,
|
|
||||||
primary_contact_last_name,
|
|
||||||
phone,
|
|
||||||
country,
|
|
||||||
address,
|
|
||||||
city,
|
|
||||||
zip,
|
|
||||||
estimate_assets,
|
estimate_assets,
|
||||||
estimate_year_operating_cost
|
estimate_year_operating_cost,
|
||||||
|
|
||||||
|
isNonprofit,
|
||||||
|
|
||||||
|
primary_contact_phone,
|
||||||
|
primary_contact_first_name,
|
||||||
|
primary_contact_last_name
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name,
|
name,
|
||||||
|
|||||||
Reference in New Issue
Block a user