basic seed files and restructuring
This commit is contained in:
+10
-10
@@ -1,14 +1,14 @@
|
||||
const Sequelize = require('sequelize'),
|
||||
DonorModel = require('../models/donor.model.js'),
|
||||
GrantModel = require('../models/grant.model.js'),
|
||||
CauseModel = require('../models/cause.model.js'),
|
||||
RegionModel = require('../models/region.model.js'),
|
||||
OrganizationModel = require('../models/organization.model.js'),
|
||||
UserModel = require('../models/user.model.js'),
|
||||
PaymentPlanModel = require('../models/paymentplan.model'),
|
||||
ChargeModel = require('../models/charge.model'),
|
||||
OrgBankModel = require('../models/orgBank.model'),
|
||||
GrantsOrganizationsModel = require('../models/grantsOrganizations.model'),
|
||||
DonorModel = require('../../models/donor.model.js'),
|
||||
GrantModel = require('../../models/grant.model.js'),
|
||||
CauseModel = require('../../models/cause.model.js'),
|
||||
RegionModel = require('../../models/region.model.js'),
|
||||
OrganizationModel = require('../../models/organization.model.js'),
|
||||
UserModel = require('../../models/user.model.js'),
|
||||
PaymentPlanModel = require('../../models/paymentplan.model'),
|
||||
ChargeModel = require('../../models/charge.model'),
|
||||
OrgBankModel = require('../../models/orgBank.model'),
|
||||
GrantsOrganizationsModel = require('../../models/grantsOrganizations.model'),
|
||||
associate = require('./associate');
|
||||
|
||||
const connection_uri = process.env.JAWSDB_MARIA_URL;
|
||||
|
||||
@@ -4,7 +4,7 @@ module.exports = {
|
||||
development: {
|
||||
username: 'root',
|
||||
password: 'water',
|
||||
database: 'ucharify',
|
||||
database: 'base',
|
||||
host: 'localhost',
|
||||
dialect: 'mysql'
|
||||
},
|
||||
@@ -54,11 +54,8 @@ exports.create = async (req, res, next) => {
|
||||
});
|
||||
|
||||
// cause or region not found
|
||||
if (!causes.length) {
|
||||
await Cause.create({ name: primary_cause }, { transaction });
|
||||
}
|
||||
if (!regions.length) {
|
||||
await Region.create({ name: primary_region }, { transaction });
|
||||
if (!causes.length || !regions.length) {
|
||||
throw errorMaker(400, `No valid cause or region`);
|
||||
}
|
||||
|
||||
const saltRounds = await bcrypt.genSaltSync(10);
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.changeColumn('organizations', 'rating', {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 5,
|
||||
allowNull: false
|
||||
});
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.changeColumn('organizations', 'rating', {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,35 +0,0 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('users', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
first_name: Sequelize.STRING,
|
||||
last_name: Sequelize.STRING,
|
||||
email: {
|
||||
type: Sequelize.STRING,
|
||||
validate: {
|
||||
isEmail: true
|
||||
},
|
||||
allowNull: false
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: new Date()
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: new Date()
|
||||
}
|
||||
});
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('users');
|
||||
}
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.addColumn('donors', 'stripe_id', {
|
||||
type: Sequelize.UUID,
|
||||
defaultValue: null
|
||||
});
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
/*
|
||||
Add reverting commands here.
|
||||
Return a promise to correctly handle asynchronicity.
|
||||
|
||||
Example:
|
||||
return queryInterface.dropTable('users');
|
||||
*/
|
||||
}
|
||||
};
|
||||
@@ -1,33 +0,0 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.createTable('charges', {
|
||||
id: {
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
primaryKey: true,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
amount: {
|
||||
allowNull: false,
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: new Date()
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: new Date()
|
||||
}
|
||||
});
|
||||
},
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.dropTable('charges');
|
||||
}
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.addColumn('payment_plans', 'sub_item_id', {
|
||||
type: Sequelize.UUID,
|
||||
unique: true
|
||||
});
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
/*
|
||||
Add reverting commands here.
|
||||
Return a promise to correctly handle asynchronicity.
|
||||
|
||||
Example:
|
||||
return queryInterface.dropTable('users');
|
||||
*/
|
||||
}
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Cause = sequelize.define('causes', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: { type: DataTypes.STRING, allowNull: false }
|
||||
});
|
||||
return Cause;
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Charge = sequelize.define('charges', {
|
||||
id: { type: DataTypes.UUID, primaryKey: true, allowNull: false },
|
||||
description: DataTypes.STRING,
|
||||
amount: DataTypes.INTEGER
|
||||
});
|
||||
|
||||
return Charge;
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Donor = sequelize.define('donors', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
stripe_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: null,
|
||||
unique: true
|
||||
},
|
||||
subscription_id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: null,
|
||||
unique: true
|
||||
},
|
||||
first_name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
last_name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
validate: {
|
||||
isEmail: true
|
||||
},
|
||||
allowNull: false
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
age: DataTypes.INTEGER,
|
||||
phone: DataTypes.BIGINT,
|
||||
address: DataTypes.STRING,
|
||||
city: DataTypes.STRING,
|
||||
state: DataTypes.STRING,
|
||||
country: DataTypes.STRING
|
||||
});
|
||||
return Donor;
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Grant = sequelize.define('grants', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
amount: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
monthly: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false
|
||||
},
|
||||
num_causes: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
num_regions: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
return Grant;
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const GrantsOrganizations = sequelize.define('grants_organizations', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
amount: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
return GrantsOrganizations;
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const Sequelize = require('sequelize');
|
||||
const basename = path.basename(__filename);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/../config/config.json')[env];
|
||||
const db = {};
|
||||
|
||||
let sequelize;
|
||||
if (config.use_env_variable) {
|
||||
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
||||
} else {
|
||||
sequelize = new Sequelize(config.database, config.username, config.password, config);
|
||||
}
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => {
|
||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||
})
|
||||
.forEach(file => {
|
||||
const model = sequelize['import'](path.join(__dirname, file));
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
module.exports = db;
|
||||
@@ -1,10 +0,0 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const OrgBank = sequelize.define('org_bank', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
}
|
||||
});
|
||||
return OrgBank;
|
||||
};
|
||||
@@ -1,71 +0,0 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Organization = sequelize.define('organizations', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
validate: {
|
||||
isEmail: true
|
||||
},
|
||||
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: {
|
||||
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 },
|
||||
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;
|
||||
};
|
||||
@@ -1,25 +0,0 @@
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const PaymentPlan = sequelize.define('payment_plans', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
plan_id: {
|
||||
unique: true,
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false
|
||||
},
|
||||
amount: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
sub_item_id: {
|
||||
type: DataTypes.UUID,
|
||||
unique: true
|
||||
}
|
||||
});
|
||||
|
||||
return PaymentPlan;
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Region = sequelize.define('regions', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: { type: DataTypes.STRING, allowNull: false }
|
||||
});
|
||||
return Region;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const User = sequelize.define('users', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
allowNull: false
|
||||
},
|
||||
first_name: DataTypes.STRING,
|
||||
last_name: DataTypes.STRING,
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
validate: {
|
||||
isEmail: true
|
||||
},
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
return User;
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// DOESNT WORK AS NEED TO HASH PASSWORD TO DB
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkInsert('donors', [
|
||||
{
|
||||
first_name: 'Arjun',
|
||||
email: '[email protected]',
|
||||
password: 'test',
|
||||
last_name: 'Patel',
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
}
|
||||
]);
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkDelete('donors', {
|
||||
email: '[email protected]'
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkInsert('causes', [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Animal Care',
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Water',
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
}
|
||||
]);
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkDelete('causes');
|
||||
}
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkInsert('regions', [
|
||||
{
|
||||
id: 1,
|
||||
name: 'North India',
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
}
|
||||
]);
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkDelete('regions', { name: 'North India' });
|
||||
}
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
up: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkInsert('organizations', [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Gopala Goshala',
|
||||
short_description: 'We are committed to animal shelter!',
|
||||
primary_cause: 'Animal Care',
|
||||
primary_region: 'North India',
|
||||
rating: 9.2,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Water Organization India',
|
||||
short_description: 'We love water! So should you!',
|
||||
primary_cause: 'Water',
|
||||
primary_region: 'North India',
|
||||
rating: 8,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Pete's Animals",
|
||||
short_description: 'Help us protect animals!',
|
||||
primary_cause: 'Animal Care',
|
||||
primary_region: 'North India',
|
||||
rating: 7.5,
|
||||
created_at: new Date(),
|
||||
updated_at: new Date()
|
||||
}
|
||||
]);
|
||||
},
|
||||
|
||||
down: (queryInterface, Sequelize) => {
|
||||
return queryInterface.bulkDelete('organizations', {
|
||||
[Sequelize.Op.or]: [
|
||||
{ name: 'Gopala Goshala' },
|
||||
{ name: 'Water Organization India' },
|
||||
{ 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='[email protected]'))`,
|
||||
{
|
||||
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, {});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user