adding grants progress

This commit is contained in:
Arjun Patel
2019-01-16 23:21:37 -08:00
parent 18abee110a
commit 3e1cec54e0
3 changed files with 37 additions and 5 deletions
+36 -3
View File
@@ -6,12 +6,45 @@ const Grants = db.Grants;
// Create a grant for certain donor
exports.create = (req, res, next) => {
const donor_id = req.params.donor_id;
const { name, amount, causes, regions, organizations } = req.body;
const {
name,
amount,
monthly,
causes_ids,
regions_ids,
organizations_ids
} = req.body;
Grants.create({
name,
amount
});
amount,
monthly,
num_causes: causes_ids.length,
num_regions: regions_ids.length
})
.then(grant => {
const grants_causes_rows = causes_ids.map(cause_id => {
return { cause_id, grant_id: grant.id };
});
const grants_regions_rows = regions_ids.map(region_id => {
return { region_id, grant_id: grant.id };
});
const grants_organizations_rows = organizations_ids.map(
organization_id => {
return { organization_id, grant_id: grant.id };
}
);
Promise.all([
grant.addCauses(grants_causes_rows),
grant.addRegions(grants_regions_rows),
grant.addOrganizations(grants_organizations_rows)
]).then(results => {
res.status(201).json(results);
});
})
.catch(error => next(error));
};
// Find grants with cause and region and charity details by donor_id
-1
View File
@@ -15,7 +15,6 @@ module.exports = (sequelize, DataTypes) => {
},
last_payment: {
type: DataTypes.DATE,
allowNull: false,
default: new Date()
},
monthly: {
+1 -1
View File
@@ -15,7 +15,7 @@ router.get('/', checkAuth, donors.findAll);
router.get('/grants/:donor_id', checkAuth, grants.findByDonorId);
/** Create grants with following body:
* - list of id's selected causes and regions
* - list of id's of selected causes and regions
* - FINAL list of id's of selected organizations
* - donor_id
* */