diff --git a/app/controllers/organization/organization.controller.js b/app/controllers/organization/organization.controller.js index 0a4e47b..558ed34 100644 --- a/app/controllers/organization/organization.controller.js +++ b/app/controllers/organization/organization.controller.js @@ -8,21 +8,29 @@ const { Grant, Cause, Region, Organization } = db; exports.create = async (req, res, next) => { let { name, - email, - password, short_description, - primary_cause, - primary_region, - ein, - primary_contact_first_name, - primary_contact_last_name, - phone, - country, + + primary_contact_email, + password, + address, city, + state, + country, zip, + + primary_cause, + primary_region, + + ein, estimate_assets, - estimate_year_operating_cost + estimate_year_operating_cost, + + isNonprofit, + + primary_contact_phone, + primary_contact_first_name, + primary_contact_last_name } = req.body; primary_cause = primary_cause.trim().toLowerCase(); @@ -33,10 +41,12 @@ exports.create = async (req, res, next) => { try { 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) { - return next(errorMaker(409, `Email Exists: ${email}`)); + return next(errorMaker(409, `Email Exists: ${primary_contact_email}`)); } const CAUSE_QUERY = `SELECT name FROM causes @@ -59,27 +69,35 @@ exports.create = async (req, res, next) => { } const saltRounds = await bcrypt.genSaltSync(10); - // hash with salt rounds + // hash with salt rounds const hashedPass = await bcrypt.hashSync(password, saltRounds); // Store hash in DB const org = await Organization.create({ name, - email, - password: hashedPass, //hashed password short_description, - primary_cause, - primary_region, - ein, - primary_contact_first_name, - primary_contact_last_name, - phone, - country, + + primary_contact_email, + password: hashedPass, + address, city, + state, + country, zip, + + primary_cause, + primary_region, + + ein, 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(); diff --git a/models/donor.model.js b/models/donor.model.js index c8f9d83..c4d01ad 100644 --- a/models/donor.model.js +++ b/models/donor.model.js @@ -1,9 +1,11 @@ +const uuidv4 = require('uuid/v4'); + module.exports = (sequelize, DataTypes) => { const Donor = sequelize.define('donors', { id: { - type: DataTypes.INTEGER, + type: DataTypes.UUID, primaryKey: true, - autoIncrement: true + defaultValue: uuidv4() }, stripe_id: { type: DataTypes.UUID, @@ -28,17 +30,20 @@ module.exports = (sequelize, DataTypes) => { validate: { isEmail: true }, - allowNull: false + allowNull: false, + unique: true }, password: { type: DataTypes.STRING, allowNull: false }, age: DataTypes.INTEGER, - phone: DataTypes.BIGINT, + phone: DataTypes.DataTypes.STRING(20), + address: DataTypes.STRING, city: DataTypes.STRING, state: DataTypes.STRING, + zip: DataTypes.STRING(10), country: DataTypes.STRING }); return Donor; diff --git a/models/organization.model.js b/models/organization.model.js index 0fb6714..1fc58dd 100644 --- a/models/organization.model.js +++ b/models/organization.model.js @@ -1,22 +1,28 @@ +const uuidv4 = require('uuid/v4'); + module.exports = (sequelize, DataTypes) => { const Organization = sequelize.define('organizations', { id: { - type: DataTypes.INTEGER, + type: DataTypes.UUID, primaryKey: true, - autoIncrement: true + defaultValue: uuidv4() }, name: { type: DataTypes.STRING, allowNull: false }, - email: { + short_description: { type: DataTypes.STRING, allowNull: false }, + + primary_contact_email: { type: DataTypes.STRING, validate: { isEmail: true }, - allowNull: false + allowNull: false, + unique: true }, - phone: { + password: { type: DataTypes.STRING, allowNull: false }, + address: { type: DataTypes.STRING, allowNull: false @@ -25,29 +31,27 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.STRING, allowNull: false }, + state: { + type: DataTypes.STRING(5), + allowNull: false + }, country: { type: DataTypes.STRING, + defaultValue: 'USA', allowNull: false }, zip: { - type: DataTypes.STRING, + type: DataTypes.STRING(10), 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_region: { type: DataTypes.STRING, allowNull: false }, - rating: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }, + + total_rating: { type: DataTypes.INTEGER, defaultValue: 0 }, + ein: { - type: DataTypes.STRING, + type: DataTypes.INTEGER, allowNull: false }, estimate_assets: { @@ -58,6 +62,22 @@ module.exports = (sequelize, DataTypes) => { type: DataTypes.INTEGER, 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: { type: DataTypes.STRING, allowNull: false diff --git a/package.json b/package.json index 3e59536..2366917 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "mysql2": "^1.6.4", "sequelize": "^4.42.0", "sequelize-cli": "^5.4.0", - "stripe": "^6.22.0" + "stripe": "^6.22.0", + "uuid": "^3.3.2" }, "devDependencies": { "dotenv-flow": "^0.2.0" diff --git a/seeders/20190122053544-base-orgs.js b/seeders/20190122053544-base-orgs.js index 5b5c235..11cc882 100644 --- a/seeders/20190122053544-base-orgs.js +++ b/seeders/20190122053544-base-orgs.js @@ -5,22 +5,30 @@ module.exports = { return queryInterface.bulkInsert('organizations', [ { name: 'Gopala Goshala', - email: 'kcp1982@yahoo.com', - password: hashedPass, //hashed password 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', + + primary_contact_email: 'kcp1982@yahoo.com', + password: hashedPass, + + address: '14872 Waverly Lane', + city: 'Irvine', + country: 'USA', + state: 'CA', + zip: '92604', + primary_cause: 'Animal', - primary_region, + primary_region: '', + ein, - primary_contact_first_name, - primary_contact_last_name, - phone, - country, - address, - city, - zip, estimate_assets, - estimate_year_operating_cost + estimate_year_operating_cost, + + isNonprofit, + + primary_contact_phone, + primary_contact_first_name, + primary_contact_last_name }, { name,