refactoring models and create grant to async await
This commit is contained in:
@@ -45,11 +45,5 @@ module.exports = (sequelize, DataTypes) => {
|
||||
country: DataTypes.STRING
|
||||
});
|
||||
|
||||
Donor.associate = models => {
|
||||
Donor.hasMany(models.Grant, {
|
||||
foreignKey: 'donor_id'
|
||||
});
|
||||
};
|
||||
|
||||
return Donor;
|
||||
};
|
||||
|
||||
+11
-6
@@ -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' });
|
||||
};
|
||||
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
const Organization = require('./Organization'),
|
||||
Grant = require('./Grant');
|
||||
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const GrantsOrganizations = sequelize.define('Grants_Organizations', {
|
||||
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
|
||||
}
|
||||
});
|
||||
return GrantsOrganizations;
|
||||
return GrantOrganization;
|
||||
};
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ module.exports = (sequelize, DataTypes) => {
|
||||
}
|
||||
},
|
||||
number_people_impacted: {
|
||||
type: DataTypes.STRING,
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 0
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user