From 0880a36ade870b876a9fb0b7eb3cadc2b62c7d7c Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Thu, 14 Mar 2019 03:56:01 -0700 Subject: [PATCH] working proper seeding --- app/controllers/donor/donor.controller.js | 4 +- .../organization/organization.controller.js | 5 +- models/donor.model.js | 6 +- models/organization.model.js | 7 +- seeders/20190122051334-base-user.js | 4 +- seeders/20190122053544-base-orgs.js | 127 +++++++++--------- 6 files changed, 80 insertions(+), 73 deletions(-) diff --git a/app/controllers/donor/donor.controller.js b/app/controllers/donor/donor.controller.js index 7a87242..d8cb320 100644 --- a/app/controllers/donor/donor.controller.js +++ b/app/controllers/donor/donor.controller.js @@ -1,6 +1,7 @@ const db = require('../../config/db.config.js'), bcrypt = require('bcrypt-nodejs'), - errorMaker = require('../../helpers/error.maker'); + errorMaker = require('../../helpers/error.maker'), + uuidv4 = require('uuid/v4'); const Donor = db.Donor; @@ -23,6 +24,7 @@ exports.create = (req, res, next) => { return next(error); } else { Donor.create({ + id: uuidv4(), first_name: req.body.first_name, middle_name: req.body.middle_name, last_name: req.body.last_name, diff --git a/app/controllers/organization/organization.controller.js b/app/controllers/organization/organization.controller.js index 184e990..2a940ae 100644 --- a/app/controllers/organization/organization.controller.js +++ b/app/controllers/organization/organization.controller.js @@ -1,6 +1,7 @@ const db = require('../../config/db.config.js'), bcrypt = require('bcrypt-nodejs'), - errorMaker = require('../../helpers/error.maker'); + errorMaker = require('../../helpers/error.maker'), + uuidv4 = require('uuid/v4'); const { Grant, Cause, Region, Organization } = db; @@ -74,6 +75,7 @@ exports.create = async (req, res, next) => { // Store hash in DB const org = await Organization.create({ + id: uuidv4(), name, short_description, @@ -107,6 +109,7 @@ exports.create = async (req, res, next) => { org }); } catch (error) { + console.log(error); await transaction.rollback(); next(error); } diff --git a/models/donor.model.js b/models/donor.model.js index c4d01ad..5c66b9d 100644 --- a/models/donor.model.js +++ b/models/donor.model.js @@ -1,11 +1,9 @@ -const uuidv4 = require('uuid/v4'); - module.exports = (sequelize, DataTypes) => { const Donor = sequelize.define('donors', { id: { type: DataTypes.UUID, - primaryKey: true, - defaultValue: uuidv4() + allowNull: false, + primaryKey: true }, stripe_id: { type: DataTypes.UUID, diff --git a/models/organization.model.js b/models/organization.model.js index 155b5dc..c76bbbf 100644 --- a/models/organization.model.js +++ b/models/organization.model.js @@ -1,13 +1,12 @@ -const uuidv4 = require('uuid/v4'), - Cause = require('./cause.model'), +const Cause = require('./cause.model'), Region = require('./region.model'); module.exports = (sequelize, DataTypes) => { const Organization = sequelize.define('organizations', { id: { type: DataTypes.UUID, - primaryKey: true, - defaultValue: uuidv4() + allowNull: false, + primaryKey: true }, name: { type: DataTypes.STRING, allowNull: false }, short_description: { type: DataTypes.STRING, allowNull: false }, diff --git a/seeders/20190122051334-base-user.js b/seeders/20190122051334-base-user.js index 6c8b8ff..3775f28 100644 --- a/seeders/20190122051334-base-user.js +++ b/seeders/20190122051334-base-user.js @@ -1,5 +1,6 @@ 'use strict'; -const bcrypt = require('bcrypt-nodejs'); +const bcrypt = require('bcrypt-nodejs'), + uuidv4 = require('uuid/v4'); // DOESNT WORK AS NEED TO HASH PASSWORD TO DB module.exports = { @@ -8,6 +9,7 @@ module.exports = { return queryInterface.bulkInsert('donors', [ { + id: uuidv4(), first_name: 'Arjun', last_name: 'Patel', email: 'patelarjun50@gmail.com', diff --git a/seeders/20190122053544-base-orgs.js b/seeders/20190122053544-base-orgs.js index 65802e5..76a0813 100644 --- a/seeders/20190122053544-base-orgs.js +++ b/seeders/20190122053544-base-orgs.js @@ -1,5 +1,6 @@ 'use strict'; -const bcrypt = require('bcrypt-nodejs'); +const bcrypt = require('bcrypt-nodejs'), + uuidv4 = require('uuid/v4'); module.exports = { up: async (queryInterface, Sequelize) => { @@ -7,6 +8,7 @@ module.exports = { return queryInterface.bulkInsert('organizations', [ { + id: uuidv4(), name: 'Gopala Goshala', 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', @@ -33,70 +35,71 @@ module.exports = { primary_contact_first_name: 'Kamlesh', primary_contact_last_name: 'Patel', + created_at: new Date(), + updated_at: new Date() + }, + { + id: uuidv4(), + name: 'The Pollination Project', + short_description: + 'Every day of the year, we give a grant to changemakers across the globe.', + + primary_contact_email: 'ajay@gmail.com', + password: hashedPass, + + address: '2031 Carry Drive', + city: 'San Francisco', + country: 'USA', + state: 'CA', + zip: '92604', + + primary_cause: 'Human Services', + primary_region: 'Africa', + + ein: '63-6088665', + estimate_asset_value: 200000, + estimate_yearly_operating_cost: 40000, + + is_nonprofit: true, + + primary_contact_phone: '6254581254', + primary_contact_first_name: 'Ajay', + primary_contact_last_name: 'Datta', + + created_at: new Date(), + updated_at: new Date() + }, + { + id: uuidv4(), + name: 'Cancer Global Perspective', + short_description: + 'Your tax-deductible donation funds lifesaving research, treatment and care — and would mean so much to someone fighting cancer. Please donate today.', + + primary_contact_email: 'cancersupport@gmail.com', + password: hashedPass, + + address: '82912 Larry Page Drive', + city: 'Holmes', + country: 'USA', + state: 'AZ', + zip: '92604', + + primary_cause: 'Animal', + primary_region: 'South Asia', + + ein: '63-6088665', + estimate_asset_value: 200000, + estimate_yearly_operating_cost: 40000, + + is_nonprofit: true, + + primary_contact_phone: '6254581254', + primary_contact_first_name: 'Leo', + primary_contact_last_name: 'Rosen', + created_at: new Date(), updated_at: new Date() } - // , - // { - // name: 'The Pollination Project', - // short_description: - // 'Every day of the year, we give a grant to changemakers across the globe.', - - // primary_contact_email: 'ajay@gmail.com', - // password: hashedPass, - - // address: '2031 Carry Drive', - // city: 'San Francisco', - // country: 'USA', - // state: 'CA', - // zip: '92604', - - // primary_cause: 'Human Services', - // primary_region: 'Africa', - - // ein: '63-6088665', - // estimate_asset_value: 200000, - // estimate_yearly_operating_cost: 40000, - - // isNonprofit: true, - - // primary_contact_phone: '6254581254', - // primary_contact_first_name: 'Ajay', - // primary_contact_last_name: 'Datta', - - // created_at: new Date(), - // updated_at: new Date() - // }, - // { - // name: 'Cancer Global Perspective', - // short_description: - // 'Your tax-deductible donation funds lifesaving research, treatment and care — and would mean so much to someone fighting cancer. Please donate today.', - - // primary_contact_email: 'cancersupport@gmail.com', - // password: hashedPass, - - // address: '82912 Larry Page Drive', - // city: 'Holmes', - // country: 'USA', - // state: 'AZ', - // zip: '92604', - - // primary_cause: 'Animal', - // primary_region: 'South Asia', - - // ein: '63-6088665', - // estimate_asset_value: 200000, - // estimate_yearly_operating_cost: 40000, - - // isNonprofit: true, - - // primary_contact_phone: '6254581254', - // primary_contact_first_name: 'Leo', - // primary_contact_last_name: 'Rosen', - - // created_at: new Date(), - // updated_at: new Date() - // } ]); },