refactoring models and create grant to async await

This commit is contained in:
Arjun Patel
2019-03-16 23:49:11 -07:00
parent e5c204890e
commit 5587c296e4
6 changed files with 97 additions and 79 deletions
+11 -6
View File
@@ -1,3 +1,5 @@
const Donor = require('./Donor');
module.exports = (sequelize, DataTypes) => {
const Grant = sequelize.define('Grant', {
id: {
@@ -25,16 +27,19 @@ module.exports = (sequelize, DataTypes) => {
num_regions: {
type: DataTypes.INTEGER,
allowNull: false
},
donor_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: Donor(sequelize, DataTypes),
key: 'id'
}
}
});
Grant.associate = models => {
Grant.belongsToMany(models.Organization, {
through: 'grants_organizations',
foreignKey: 'grant_id',
otherKey: 'organization_id'
});
Grant.hasMany(models.Charge, { foreignKey: 'grant_id' });
};