making needed changes to make the table names strict
This commit is contained in:
@@ -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;
|
||||
|
||||
+11
-2
@@ -1,11 +1,20 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Cause = sequelize.define('Cause', {
|
||||
const Cause = sequelize.define(
|
||||
'Cause',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: { type: DataTypes.STRING, allowNull: false, unique: true }
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'causes'
|
||||
}
|
||||
);
|
||||
return Cause;
|
||||
};
|
||||
|
||||
+11
-2
@@ -2,7 +2,9 @@
|
||||
const PaymentStatus = require('./PaymentStatus');
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Charge = sequelize.define('Charge', {
|
||||
const Charge = sequelize.define(
|
||||
'Charge',
|
||||
{
|
||||
id: { type: DataTypes.UUID, primaryKey: true, allowNull: false },
|
||||
description: DataTypes.STRING,
|
||||
amount: DataTypes.INTEGER,
|
||||
@@ -15,7 +17,14 @@ module.exports = (sequelize, DataTypes) => {
|
||||
key: 'name'
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'charges'
|
||||
}
|
||||
);
|
||||
|
||||
return Charge;
|
||||
};
|
||||
|
||||
+11
-2
@@ -1,5 +1,7 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Donor = sequelize.define('Donor', {
|
||||
const Donor = sequelize.define(
|
||||
'Donor',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
@@ -43,7 +45,14 @@ module.exports = (sequelize, DataTypes) => {
|
||||
state: DataTypes.STRING,
|
||||
zip: DataTypes.STRING(10),
|
||||
country: DataTypes.STRING
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'donors'
|
||||
}
|
||||
);
|
||||
|
||||
return Donor;
|
||||
};
|
||||
|
||||
+11
-2
@@ -1,7 +1,9 @@
|
||||
const Donor = require('./Donor');
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Grant = sequelize.define('Grant', {
|
||||
const Grant = sequelize.define(
|
||||
'Grant',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
@@ -37,7 +39,14 @@ module.exports = (sequelize, DataTypes) => {
|
||||
key: 'id'
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'grants'
|
||||
}
|
||||
);
|
||||
|
||||
Grant.associate = models => {
|
||||
Grant.hasMany(models.Charge, { foreignKey: 'grant_id' });
|
||||
|
||||
@@ -2,7 +2,9 @@ const Organization = require('./Organization'),
|
||||
Grant = require('./Grant');
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const GrantOrganization = sequelize.define('GrantOrganization', {
|
||||
const GrantOrganization = sequelize.define(
|
||||
'GrantOrganization',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
@@ -28,6 +30,13 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'grants_organizations'
|
||||
}
|
||||
);
|
||||
return GrantOrganization;
|
||||
};
|
||||
|
||||
+11
-2
@@ -2,7 +2,9 @@ const Cause = require('./Cause'),
|
||||
Region = require('./Region');
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Organization = sequelize.define('Organization', {
|
||||
const Organization = sequelize.define(
|
||||
'Organization',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
@@ -117,6 +119,13 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'organizations'
|
||||
}
|
||||
);
|
||||
return Organization;
|
||||
};
|
||||
|
||||
+12
-3
@@ -1,12 +1,21 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const PaymentStatus = sequelize.define("PaymentStatus", {
|
||||
const PaymentStatus = sequelize.define(
|
||||
'PaymentStatus',
|
||||
{
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'paymentstatuses'
|
||||
}
|
||||
);
|
||||
|
||||
return PaymentStatus;
|
||||
};
|
||||
|
||||
+11
-2
@@ -1,7 +1,9 @@
|
||||
const Organization = require('./Organization');
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Post = sequelize.define('Post', {
|
||||
const Post = sequelize.define(
|
||||
'Post',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
@@ -23,6 +25,13 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'posts'
|
||||
}
|
||||
);
|
||||
return Post;
|
||||
};
|
||||
|
||||
+11
-2
@@ -5,7 +5,9 @@ const Organization = require('./Organization'),
|
||||
Region = require('./Region');
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Project = sequelize.define('Project', {
|
||||
const Project = sequelize.define(
|
||||
'Project',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
@@ -58,7 +60,14 @@ module.exports = (sequelize, DataTypes) => {
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'projects'
|
||||
}
|
||||
);
|
||||
|
||||
return Project;
|
||||
};
|
||||
|
||||
+11
-2
@@ -1,11 +1,20 @@
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const Region = sequelize.define('Region', {
|
||||
const Region = sequelize.define(
|
||||
'Region',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
},
|
||||
name: { type: DataTypes.STRING, allowNull: false, unique: true }
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'regions'
|
||||
}
|
||||
);
|
||||
return Region;
|
||||
};
|
||||
|
||||
+11
-2
@@ -1,6 +1,8 @@
|
||||
'use strict';
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const User = sequelize.define('User', {
|
||||
const User = sequelize.define(
|
||||
'User',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
@@ -16,6 +18,13 @@ module.exports = (sequelize, DataTypes) => {
|
||||
},
|
||||
allowNull: false
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
freezeTableName: true,
|
||||
|
||||
// define the table's name
|
||||
tableName: 'users'
|
||||
}
|
||||
);
|
||||
return User;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user