diff --git a/app/controllers/grant.controller.js b/app/controllers/grant.controller.js index 28e3612..8e9b3ba 100644 --- a/app/controllers/grant.controller.js +++ b/app/controllers/grant.controller.js @@ -125,7 +125,7 @@ exports.getGrantsByDonorId = async (req, res, next) => { JSON_ARRAYAGG(o.primary_cause) AS causes, JSON_ARRAYAGG(o.primary_region) AS regions from grants as g - inner join GrantOrganizations as go on go.grant_id = g.id + inner join grants_organizations as go on go.grant_id = g.id left join organizations as o on o.id = go.organization_id where donor_id = :donor_id group by g.id, g.name, g.amount, g.monthly, g.num_causes, g.num_regions, g.donor_id; diff --git a/models/Cause.js b/models/Cause.js index 285447f..d199985 100644 --- a/models/Cause.js +++ b/models/Cause.js @@ -1,11 +1,20 @@ module.exports = (sequelize, DataTypes) => { - const Cause = sequelize.define('Cause', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true + const Cause = sequelize.define( + 'Cause', + { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true + }, + name: { type: DataTypes.STRING, allowNull: false, unique: true } }, - name: { type: DataTypes.STRING, allowNull: false, unique: true } - }); + { + freezeTableName: true, + + // define the table's name + tableName: 'causes' + } + ); return Cause; }; diff --git a/models/Charge.js b/models/Charge.js index d73cc87..2af2f85 100644 --- a/models/Charge.js +++ b/models/Charge.js @@ -2,20 +2,29 @@ const PaymentStatus = require('./PaymentStatus'); module.exports = (sequelize, DataTypes) => { - const Charge = sequelize.define('Charge', { - id: { type: DataTypes.UUID, primaryKey: true, allowNull: false }, - description: DataTypes.STRING, - amount: DataTypes.INTEGER, + const Charge = sequelize.define( + 'Charge', + { + id: { type: DataTypes.UUID, primaryKey: true, allowNull: false }, + description: DataTypes.STRING, + amount: DataTypes.INTEGER, - payment_status: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: PaymentStatus(sequelize, DataTypes), - key: 'name' + payment_status: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: PaymentStatus(sequelize, DataTypes), + key: 'name' + } } + }, + { + freezeTableName: true, + + // define the table's name + tableName: 'charges' } - }); + ); return Charge; }; diff --git a/models/Donor.js b/models/Donor.js index 2887376..04d24ac 100644 --- a/models/Donor.js +++ b/models/Donor.js @@ -1,49 +1,58 @@ module.exports = (sequelize, DataTypes) => { - const Donor = sequelize.define('Donor', { - id: { - type: DataTypes.UUID, - allowNull: false, - primaryKey: 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 + const Donor = sequelize.define( + 'Donor', + { + id: { + type: DataTypes.UUID, + allowNull: false, + primaryKey: true }, - allowNull: false, - unique: true - }, - password: { - type: DataTypes.STRING, - allowNull: false - }, - age: DataTypes.INTEGER, - phone: DataTypes.STRING(20), + 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, + unique: true + }, + password: { + type: DataTypes.STRING, + allowNull: false + }, + age: DataTypes.INTEGER, + phone: DataTypes.STRING(20), - address: DataTypes.STRING, - city: DataTypes.STRING, - state: DataTypes.STRING, - zip: DataTypes.STRING(10), - country: DataTypes.STRING - }); + address: DataTypes.STRING, + city: DataTypes.STRING, + state: DataTypes.STRING, + zip: DataTypes.STRING(10), + country: DataTypes.STRING + }, + { + freezeTableName: true, + + // define the table's name + tableName: 'donors' + } + ); return Donor; }; diff --git a/models/Grant.js b/models/Grant.js index 98400be..e03bfe5 100644 --- a/models/Grant.js +++ b/models/Grant.js @@ -1,43 +1,52 @@ const Donor = require('./Donor'); module.exports = (sequelize, DataTypes) => { - const Grant = sequelize.define('Grant', { - 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 - }, + const Grant = sequelize.define( + 'Grant', + { + 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 + }, - donor_id: { - type: DataTypes.UUID, - allowNull: false, - references: { - model: Donor(sequelize, DataTypes), - key: 'id' + donor_id: { + type: DataTypes.UUID, + allowNull: false, + references: { + model: Donor(sequelize, DataTypes), + key: 'id' + } } + }, + { + freezeTableName: true, + + // define the table's name + tableName: 'grants' } - }); + ); Grant.associate = models => { Grant.hasMany(models.Charge, { foreignKey: 'grant_id' }); diff --git a/models/Grant_Organization.js b/models/Grant_Organization.js index 5867db7..25b48a4 100644 --- a/models/Grant_Organization.js +++ b/models/Grant_Organization.js @@ -2,32 +2,41 @@ const Organization = require('./Organization'), Grant = require('./Grant'); module.exports = (sequelize, DataTypes) => { - const GrantOrganization = sequelize.define('GrantOrganization', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true - }, - grant_id: { - type: DataTypes.INTEGER, - allowNull: false, - references: { - model: Grant(sequelize, DataTypes), - key: 'id' + const GrantOrganization = sequelize.define( + 'GrantOrganization', + { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true + }, + grant_id: { + type: DataTypes.INTEGER, + allowNull: false, + references: { + model: Grant(sequelize, DataTypes), + key: 'id' + } + }, + organization_id: { + type: DataTypes.UUID, + allowNull: false, + references: { + model: Organization(sequelize, DataTypes), + key: 'id' + } + }, + amount: { + type: DataTypes.INTEGER, + allowNull: false } }, - organization_id: { - type: DataTypes.UUID, - allowNull: false, - references: { - model: Organization(sequelize, DataTypes), - key: 'id' - } - }, - amount: { - type: DataTypes.INTEGER, - allowNull: false + { + freezeTableName: true, + + // define the table's name + tableName: 'grants_organizations' } - }); + ); return GrantOrganization; }; diff --git a/models/Organization.js b/models/Organization.js index ad5edcc..f251c30 100644 --- a/models/Organization.js +++ b/models/Organization.js @@ -2,121 +2,130 @@ const Cause = require('./Cause'), Region = require('./Region'); module.exports = (sequelize, DataTypes) => { - const Organization = sequelize.define('Organization', { - id: { - type: DataTypes.UUID, - allowNull: false, - primaryKey: true - }, - name: { type: DataTypes.STRING, allowNull: false }, - profile_pic_url: { - type: DataTypes.STRING, - allowNull: true - }, - short_description: { type: DataTypes.STRING, allowNull: false }, - total_received: { - type: DataTypes.INTEGER, - defaultValue: 0 - }, - total_donors: { - type: DataTypes.INTEGER, - defaultValue: 0 - }, - stripe_account_id: { - type: DataTypes.UUID, - defaultValue: null - }, - - primary_contact_email: { - type: DataTypes.STRING, - validate: { - isEmail: true + const Organization = sequelize.define( + 'Organization', + { + id: { + type: DataTypes.UUID, + allowNull: false, + primaryKey: true + }, + name: { type: DataTypes.STRING, allowNull: false }, + profile_pic_url: { + type: DataTypes.STRING, + allowNull: true + }, + short_description: { type: DataTypes.STRING, allowNull: false }, + total_received: { + type: DataTypes.INTEGER, + defaultValue: 0 + }, + total_donors: { + type: DataTypes.INTEGER, + defaultValue: 0 + }, + stripe_account_id: { + type: DataTypes.UUID, + defaultValue: null }, - allowNull: false, - unique: true - }, - password: { - type: DataTypes.STRING, - allowNull: false - }, - address: { - type: DataTypes.STRING, - allowNull: false - }, - city: { - type: DataTypes.STRING, - allowNull: false - }, - state: { - type: DataTypes.STRING(5), - allowNull: false - }, - country: { - type: DataTypes.STRING, - defaultValue: 'USA', - allowNull: false - }, - zip: { - type: DataTypes.STRING(10), - allowNull: false - }, + primary_contact_email: { + type: DataTypes.STRING, + validate: { + isEmail: true + }, + allowNull: false, + unique: true + }, + password: { + type: DataTypes.STRING, + allowNull: false + }, - primary_cause: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: Cause(sequelize, DataTypes), - key: 'name' - } - }, - primary_region: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: Region(sequelize, DataTypes), - key: 'name' + address: { + type: DataTypes.STRING, + allowNull: false + }, + city: { + type: DataTypes.STRING, + allowNull: false + }, + state: { + type: DataTypes.STRING(5), + allowNull: false + }, + country: { + type: DataTypes.STRING, + defaultValue: 'USA', + allowNull: false + }, + zip: { + type: DataTypes.STRING(10), + allowNull: false + }, + + primary_cause: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: Cause(sequelize, DataTypes), + key: 'name' + } + }, + primary_region: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: Region(sequelize, DataTypes), + key: 'name' + } + }, + + total_rating: { type: DataTypes.INTEGER, defaultValue: 0 }, + + ein: { + type: DataTypes.STRING(10), + allowNull: false + }, + estimate_asset_value: { + type: DataTypes.BIGINT, + defaultValue: 0 + }, + estimate_yearly_operating_cost: { + type: DataTypes.BIGINT, + defaultValue: 0 + }, + + is_nonprofit: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: false + }, + is_verified: { + 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 + }, + primary_contact_last_name: { + type: DataTypes.STRING, + allowNull: false } }, + { + freezeTableName: true, - total_rating: { type: DataTypes.INTEGER, defaultValue: 0 }, - - ein: { - type: DataTypes.STRING(10), - allowNull: false - }, - estimate_asset_value: { - type: DataTypes.BIGINT, - defaultValue: 0 - }, - estimate_yearly_operating_cost: { - type: DataTypes.BIGINT, - defaultValue: 0 - }, - - is_nonprofit: { - type: DataTypes.BOOLEAN, - allowNull: false, - defaultValue: false - }, - is_verified: { - 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 - }, - primary_contact_last_name: { - type: DataTypes.STRING, - allowNull: false + // define the table's name + tableName: 'organizations' } - }); + ); return Organization; }; diff --git a/models/PaymentStatus.js b/models/PaymentStatus.js index 8c652c7..b57a1b3 100644 --- a/models/PaymentStatus.js +++ b/models/PaymentStatus.js @@ -1,12 +1,21 @@ -"use strict"; +'use strict'; module.exports = (sequelize, DataTypes) => { - const PaymentStatus = sequelize.define("PaymentStatus", { - name: { - type: DataTypes.STRING, - primaryKey: true, - allowNull: false - } - }); + const PaymentStatus = sequelize.define( + 'PaymentStatus', + { + name: { + type: DataTypes.STRING, + primaryKey: true, + allowNull: false + } + }, + { + freezeTableName: true, - return PaymentStatus; + // define the table's name + tableName: 'paymentstatuses' + } + ); + + return PaymentStatus; }; diff --git a/models/Post.js b/models/Post.js index 1538469..b9901f3 100644 --- a/models/Post.js +++ b/models/Post.js @@ -1,28 +1,37 @@ const Organization = require('./Organization'); module.exports = (sequelize, DataTypes) => { - const Post = sequelize.define('Post', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true - }, - text: { - type: DataTypes.STRING(350), - allowNull: false - }, - organization_id: { - type: DataTypes.UUID, - allowNull: false, - references: { - model: Organization(sequelize, DataTypes), - key: 'id' + const Post = sequelize.define( + 'Post', + { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true + }, + text: { + type: DataTypes.STRING(350), + allowNull: false + }, + organization_id: { + type: DataTypes.UUID, + allowNull: false, + references: { + model: Organization(sequelize, DataTypes), + key: 'id' + } + }, + num_ribbons: { + type: DataTypes.INTEGER, + defaultValue: 0 } }, - num_ribbons: { - type: DataTypes.INTEGER, - defaultValue: 0 + { + freezeTableName: true, + + // define the table's name + tableName: 'posts' } - }); + ); return Post; }; diff --git a/models/Project.js b/models/Project.js index 5ef7b5e..034627b 100644 --- a/models/Project.js +++ b/models/Project.js @@ -5,60 +5,69 @@ const Organization = require('./Organization'), Region = require('./Region'); module.exports = (sequelize, DataTypes) => { - const Project = sequelize.define('Project', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true - }, - total_received: { - type: DataTypes.INTEGER, - defaultValue: 0 - }, - total_donors: { - type: DataTypes.INTEGER, - defaultValue: 0 - }, + const Project = sequelize.define( + 'Project', + { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true + }, + total_received: { + type: DataTypes.INTEGER, + defaultValue: 0 + }, + total_donors: { + type: DataTypes.INTEGER, + defaultValue: 0 + }, - title: { - type: DataTypes.STRING(1000), - allowNull: false - }, - description: DataTypes.STRING, - isComplete: { - type: DataTypes.BOOLEAN, - defaultValue: false - }, + title: { + type: DataTypes.STRING(1000), + allowNull: false + }, + description: DataTypes.STRING, + isComplete: { + type: DataTypes.BOOLEAN, + defaultValue: false + }, - // cause: { - // type: DataTypes.STRING, - // allowNull: false, - // references: { - // model: Cause(sequelize, DataTypes), - // key: 'name' - // } - // }, - // region: { - // type: DataTypes.STRING, - // allowNull: false, - // references: { - // model: Region(sequelize, DataTypes), - // key: 'name' - // } - // }, - organization_id: { - type: DataTypes.UUID, - allowNull: false, - references: { - model: Organization(sequelize, DataTypes), - key: 'id' + // cause: { + // type: DataTypes.STRING, + // allowNull: false, + // references: { + // model: Cause(sequelize, DataTypes), + // key: 'name' + // } + // }, + // region: { + // type: DataTypes.STRING, + // allowNull: false, + // references: { + // model: Region(sequelize, DataTypes), + // key: 'name' + // } + // }, + organization_id: { + type: DataTypes.UUID, + allowNull: false, + references: { + model: Organization(sequelize, DataTypes), + key: 'id' + } + }, + number_people_impacted: { + type: DataTypes.INTEGER, + defaultValue: 0 } }, - number_people_impacted: { - type: DataTypes.INTEGER, - defaultValue: 0 + { + freezeTableName: true, + + // define the table's name + tableName: 'projects' } - }); + ); return Project; }; diff --git a/models/Region.js b/models/Region.js index eef5fee..973a958 100644 --- a/models/Region.js +++ b/models/Region.js @@ -1,11 +1,20 @@ module.exports = (sequelize, DataTypes) => { - const Region = sequelize.define('Region', { - id: { - type: DataTypes.INTEGER, - primaryKey: true, - autoIncrement: true + const Region = sequelize.define( + 'Region', + { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true + }, + name: { type: DataTypes.STRING, allowNull: false, unique: true } }, - name: { type: DataTypes.STRING, allowNull: false, unique: true } - }); + { + freezeTableName: true, + + // define the table's name + tableName: 'regions' + } + ); return Region; }; diff --git a/models/User.js b/models/User.js index 378dc0f..73fcf08 100644 --- a/models/User.js +++ b/models/User.js @@ -1,21 +1,30 @@ 'use strict'; module.exports = (sequelize, DataTypes) => { - const User = sequelize.define('User', { - 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 + const User = sequelize.define( + 'User', + { + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true, + allowNull: false }, - allowNull: false + first_name: DataTypes.STRING, + last_name: DataTypes.STRING, + email: { + type: DataTypes.STRING, + validate: { + isEmail: true + }, + allowNull: false + } + }, + { + freezeTableName: true, + + // define the table's name + tableName: 'users' } - }); + ); return User; };