cleanup and working seed data
This commit is contained in:
@@ -7,7 +7,6 @@ module.exports = models => {
|
|||||||
Organization,
|
Organization,
|
||||||
Charge,
|
Charge,
|
||||||
PaymentPlan,
|
PaymentPlan,
|
||||||
OrgBank,
|
|
||||||
GrantsOrganizations
|
GrantsOrganizations
|
||||||
} = models;
|
} = models;
|
||||||
|
|
||||||
@@ -41,6 +40,4 @@ module.exports = models => {
|
|||||||
Grant.hasOne(PaymentPlan, {
|
Grant.hasOne(PaymentPlan, {
|
||||||
foreignKey: 'grant_id'
|
foreignKey: 'grant_id'
|
||||||
});
|
});
|
||||||
|
|
||||||
Organization.hasOne(OrgBank);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const Sequelize = require('sequelize'),
|
|||||||
UserModel = require('../../models/user.model.js'),
|
UserModel = require('../../models/user.model.js'),
|
||||||
PaymentPlanModel = require('../../models/paymentplan.model'),
|
PaymentPlanModel = require('../../models/paymentplan.model'),
|
||||||
ChargeModel = require('../../models/charge.model'),
|
ChargeModel = require('../../models/charge.model'),
|
||||||
OrgBankModel = require('../../models/orgBank.model'),
|
|
||||||
GrantsOrganizationsModel = require('../../models/grantsOrganizations.model'),
|
GrantsOrganizationsModel = require('../../models/grantsOrganizations.model'),
|
||||||
associate = require('./associate');
|
associate = require('./associate');
|
||||||
|
|
||||||
@@ -46,7 +45,6 @@ const Organization = OrganizationModel(sequelize, Sequelize);
|
|||||||
const User = UserModel(sequelize, Sequelize);
|
const User = UserModel(sequelize, Sequelize);
|
||||||
const Charge = ChargeModel(sequelize, Sequelize);
|
const Charge = ChargeModel(sequelize, Sequelize);
|
||||||
const PaymentPlan = PaymentPlanModel(sequelize, Sequelize);
|
const PaymentPlan = PaymentPlanModel(sequelize, Sequelize);
|
||||||
const OrgBank = OrgBankModel(sequelize, Sequelize);
|
|
||||||
const GrantsOrganizations = GrantsOrganizationsModel(sequelize, Sequelize);
|
const GrantsOrganizations = GrantsOrganizationsModel(sequelize, Sequelize);
|
||||||
db.Donor = Donor;
|
db.Donor = Donor;
|
||||||
db.Grant = Grant;
|
db.Grant = Grant;
|
||||||
@@ -56,7 +54,6 @@ db.Organization = Organization;
|
|||||||
db.User = User;
|
db.User = User;
|
||||||
db.Charge = Charge;
|
db.Charge = Charge;
|
||||||
db.PaymentPlan = PaymentPlan;
|
db.PaymentPlan = PaymentPlan;
|
||||||
db.OrgBank = OrgBank;
|
|
||||||
db.GrantsOrganizations = GrantsOrganizations;
|
db.GrantsOrganizations = GrantsOrganizations;
|
||||||
|
|
||||||
// make associations with created models
|
// make associations with created models
|
||||||
|
|||||||
@@ -15,16 +15,16 @@ exports.create = async (req, res, next) => {
|
|||||||
|
|
||||||
address,
|
address,
|
||||||
city,
|
city,
|
||||||
state,
|
|
||||||
country,
|
country,
|
||||||
|
state,
|
||||||
zip,
|
zip,
|
||||||
|
|
||||||
primary_cause,
|
primary_cause,
|
||||||
primary_region,
|
primary_region,
|
||||||
|
|
||||||
ein,
|
ein,
|
||||||
estimate_assets,
|
estimate_asset_value,
|
||||||
estimate_year_operating_cost,
|
estimate_yearly_operating_cost,
|
||||||
|
|
||||||
isNonprofit,
|
isNonprofit,
|
||||||
|
|
||||||
@@ -82,16 +82,16 @@ exports.create = async (req, res, next) => {
|
|||||||
|
|
||||||
address,
|
address,
|
||||||
city,
|
city,
|
||||||
state,
|
|
||||||
country,
|
country,
|
||||||
|
state,
|
||||||
zip,
|
zip,
|
||||||
|
|
||||||
primary_cause,
|
primary_cause,
|
||||||
primary_region,
|
primary_region,
|
||||||
|
|
||||||
ein,
|
ein,
|
||||||
estimate_assets,
|
estimate_asset_value,
|
||||||
estimate_year_operating_cost,
|
estimate_yearly_operating_cost,
|
||||||
|
|
||||||
isNonprofit,
|
isNonprofit,
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
Insert seed data:
|
||||||
|
- 3 orgs (password: test)
|
||||||
|
- 1 donor (password: test)
|
||||||
|
- basic causes
|
||||||
|
- basic regions
|
||||||
|
- 1 charity bundle
|
||||||
|
|
||||||
|
`npx sequelize db:seed:all`
|
||||||
|
|
||||||
|
|
||||||
|
Revert seed data insert:
|
||||||
|
|
||||||
|
`npx sequelize db:seed:undo:all`
|
||||||
|
|
||||||
|
|
||||||
|
Drop all tables:
|
||||||
|
|
||||||
|
`npm run drop:local:{operating_system}` where `operating_system` is `mac` or `windows`
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
module.exports = (sequelize, DataTypes) => {
|
|
||||||
const OrgBank = sequelize.define('org_bank', {
|
|
||||||
id: {
|
|
||||||
type: DataTypes.INTEGER,
|
|
||||||
primaryKey: true,
|
|
||||||
autoIncrement: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return OrgBank;
|
|
||||||
};
|
|
||||||
@@ -74,7 +74,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.BIGINT,
|
type: DataTypes.BIGINT,
|
||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
estimate_year_operating_cost: {
|
estimate_yearly_operating_cost: {
|
||||||
type: DataTypes.BIGINT,
|
type: DataTypes.BIGINT,
|
||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const bcrypt = require('bcrypt-nodejs');
|
|||||||
// DOESNT WORK AS NEED TO HASH PASSWORD TO DB
|
// DOESNT WORK AS NEED TO HASH PASSWORD TO DB
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: async (queryInterface, Sequelize) => {
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
|
||||||
var hash = bcrypt.hashSync('test', null);
|
var hash = bcrypt.hashSync('test', null);
|
||||||
|
|
||||||
return queryInterface.bulkInsert('donors', [
|
return queryInterface.bulkInsert('donors', [
|
||||||
@@ -27,7 +26,7 @@ module.exports = {
|
|||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
down: (queryInterface, Sequelize) => {
|
||||||
return queryInterface.bulkDelete('donors', {
|
return queryInterface.bulkDelete('donors', {
|
||||||
email: 'patel.arjun50@gmail.com'
|
email: 'patelarjun50@gmail.com'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
const bcrypt = require('bcrypt-nodejs');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
up: (queryInterface, Sequelize) => {
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
var hashedPass = await bcrypt.hashSync('test', null);
|
||||||
|
|
||||||
return queryInterface.bulkInsert('organizations', [
|
return queryInterface.bulkInsert('organizations', [
|
||||||
{
|
{
|
||||||
name: 'Gopala Goshala',
|
name: 'Gopala Goshala',
|
||||||
@@ -18,7 +21,7 @@ module.exports = {
|
|||||||
zip: '92604',
|
zip: '92604',
|
||||||
|
|
||||||
primary_cause: 'Animal',
|
primary_cause: 'Animal',
|
||||||
primary_region: 'North India',
|
primary_region: 'South Asia',
|
||||||
|
|
||||||
ein: '63-6088665',
|
ein: '63-6088665',
|
||||||
estimate_asset_value: 200000,
|
estimate_asset_value: 200000,
|
||||||
@@ -26,56 +29,82 @@ module.exports = {
|
|||||||
|
|
||||||
isNonprofit: true,
|
isNonprofit: true,
|
||||||
|
|
||||||
primary_contact_phone,
|
primary_contact_phone: '9493873423',
|
||||||
primary_contact_first_name,
|
primary_contact_first_name: 'Kamlesh',
|
||||||
primary_contact_last_name
|
primary_contact_last_name: 'Patel',
|
||||||
},
|
|
||||||
{
|
created_at: new Date(),
|
||||||
name,
|
updated_at: new Date()
|
||||||
email,
|
|
||||||
password: hashedPass, //hashed password
|
|
||||||
short_description,
|
|
||||||
primary_cause,
|
|
||||||
primary_region,
|
|
||||||
ein,
|
|
||||||
primary_contact_first_name,
|
|
||||||
primary_contact_last_name,
|
|
||||||
phone,
|
|
||||||
country,
|
|
||||||
address,
|
|
||||||
city,
|
|
||||||
zip,
|
|
||||||
estimate_assets,
|
|
||||||
estimate_year_operating_cost
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
email,
|
|
||||||
password: hashedPass, //hashed password
|
|
||||||
short_description,
|
|
||||||
primary_cause,
|
|
||||||
primary_region,
|
|
||||||
ein,
|
|
||||||
primary_contact_first_name,
|
|
||||||
primary_contact_last_name,
|
|
||||||
phone,
|
|
||||||
country,
|
|
||||||
address,
|
|
||||||
city,
|
|
||||||
zip,
|
|
||||||
estimate_assets,
|
|
||||||
estimate_year_operating_cost
|
|
||||||
}
|
}
|
||||||
|
// ,
|
||||||
|
// {
|
||||||
|
// 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: '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: '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()
|
||||||
|
// }
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
down: (queryInterface, Sequelize) => {
|
||||||
return queryInterface.bulkDelete('organizations', {
|
return queryInterface.bulkDelete('organizations', [
|
||||||
[Sequelize.Op.or]: [
|
{ primary_contact_email: 'kcp1982@yahoo.com' },
|
||||||
{ name: 'Gopala Goshala' },
|
{ primary_contact_email: 'ajay@gmail.com' },
|
||||||
{ name: 'Water Organization India' },
|
{ primary_contact_email: 'cancersupport@gmail.com' }
|
||||||
{ name: "Pete's Animals" }
|
]);
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) => {
|
|
||||||
var sequelize = queryInterface.sequelize;
|
|
||||||
const causes = [1, 2],
|
|
||||||
regions = [1],
|
|
||||||
organizations = [1, 2, 3];
|
|
||||||
|
|
||||||
return Promise.all([
|
|
||||||
sequelize.query(
|
|
||||||
`INSERT INTO grants (id, name, amount, monthly, last_payment, num_causes, num_regions, created_at, updated_at, donor_id)
|
|
||||||
VALUES (1, 'Max Impact in the South', 1000, 1, :last_payment, 2, 1, :created_at, :updated_at, (select id from donors where email='patel.arjun50@gmail.com'))`,
|
|
||||||
{
|
|
||||||
replacements: {
|
|
||||||
last_payment: new Date(),
|
|
||||||
created_at: new Date(),
|
|
||||||
updated_at: new Date()
|
|
||||||
},
|
|
||||||
type: sequelize.QueryTypes.INSERT
|
|
||||||
}
|
|
||||||
),
|
|
||||||
sequelize.query(
|
|
||||||
`INSERT INTO grants_causes (grant_id, cause_id, created_at, updated_at)
|
|
||||||
VALUES ((select id from grants where id=1), select id from causes where name='Animal Care', :created_at, :updated_at),
|
|
||||||
((select id from grants where id=1), select id from causes where name='Water', :created_at, :updated_at)`,
|
|
||||||
{
|
|
||||||
replacements: {
|
|
||||||
created_at: new Date(),
|
|
||||||
updated_at: new Date()
|
|
||||||
},
|
|
||||||
type: sequelize.QueryTypes.INSERT
|
|
||||||
}
|
|
||||||
),
|
|
||||||
sequelize.query(
|
|
||||||
`INSERT INTO grants_regions (grant_id, cause_id, created_at, updated_at)
|
|
||||||
VALUES ((select id from grants where id=1), select id from causes where name='Animal Care', :created_at, :updated_at),
|
|
||||||
((select id from grants where id=1), select id from causes where name='Water', :created_at, :updated_at)`,
|
|
||||||
{
|
|
||||||
replacements: {
|
|
||||||
created_at: new Date(),
|
|
||||||
updated_at: new Date()
|
|
||||||
},
|
|
||||||
type: sequelize.QueryTypes.INSERT
|
|
||||||
}
|
|
||||||
),
|
|
||||||
sequelize.query(
|
|
||||||
`INSERT INTO grants_causes (grant_id, cause_id, created_at, updated_at)
|
|
||||||
VALUES ((select id from grants where id=1), select id from causes where name='Animal Care', :created_at, :updated_at),
|
|
||||||
((select id from grants where id=1), select id from causes where name='Water', :created_at, :updated_at)`,
|
|
||||||
{
|
|
||||||
replacements: {
|
|
||||||
created_at: new Date(),
|
|
||||||
updated_at: new Date()
|
|
||||||
},
|
|
||||||
type: sequelize.QueryTypes.INSERT
|
|
||||||
}
|
|
||||||
)
|
|
||||||
]);
|
|
||||||
},
|
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.bulkDelete('grants', null, {});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -30,7 +30,9 @@ app.use((req, res, next) => {
|
|||||||
db.sequelize
|
db.sequelize
|
||||||
.authenticate()
|
.authenticate()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Connection has been established successfully: ' + process.env.NODE_ENV);
|
console.log(
|
||||||
|
'Connection has been established successfully: ' + process.env.NODE_ENV
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('Unable to connect to the database:', err);
|
console.error('Unable to connect to the database:', err);
|
||||||
@@ -38,9 +40,18 @@ db.sequelize
|
|||||||
|
|
||||||
//force: true will drop the table if it already exists
|
//force: true will drop the table if it already exists
|
||||||
const drop_tables = process.env.DROP_TABLES || false;
|
const drop_tables = process.env.DROP_TABLES || false;
|
||||||
db.sequelize.sync({ force: drop_tables }).then(() => {
|
if (drop_tables) {
|
||||||
console.log(`Drop and Resync with { force: ${drop_tables} }`);
|
db.sequelize
|
||||||
});
|
.query('SET FOREIGN_KEY_CHECKS = 0', null, { raw: true })
|
||||||
|
.then(function() {
|
||||||
|
db.sequelize.sync({ force: true }).then(function() {
|
||||||
|
console.log('Dropped all of the tables');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
db.sequelize.sync({ force: false }).then(() => {
|
||||||
|
console.log(`Drop and Resync with { force: ${drop_tables} }`);
|
||||||
|
});
|
||||||
|
|
||||||
//main route for api; perhaps for api docs frontend
|
//main route for api; perhaps for api docs frontend
|
||||||
app.get('/', function(req, res, next) {
|
app.get('/', function(req, res, next) {
|
||||||
@@ -87,7 +98,7 @@ app.use((error, req, res, next) => {
|
|||||||
var server = app.listen(port, function() {
|
var server = app.listen(port, function() {
|
||||||
var host = server.address();
|
var host = server.address();
|
||||||
var port = server.address().port;
|
var port = server.address().port;
|
||||||
|
|
||||||
//server is successful
|
//server is successful
|
||||||
console.log(`App listening at port: ${port}`);
|
console.log(`App listening at port: ${port}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user