fixing get to post for org suggestions

This commit is contained in:
Arjun Patel
2019-01-20 22:51:08 -08:00
parent f5dd981152
commit 008800acdf
6 changed files with 15 additions and 12 deletions
+3 -2
View File
@@ -25,6 +25,7 @@ exports.create = (req, res, next) => {
}) })
.then(result => { .then(result => {
res.status(201).json({ res.status(201).json({
result,
message: 'Grant Created' message: 'Grant Created'
}); });
}) })
@@ -58,8 +59,8 @@ exports.delete = (req, res, next) => {
message = 'Grant Deleted'; message = 'Grant Deleted';
} }
res.status(201).json({ res.status(201).json({
message, result,
result message
}); });
}) })
.catch(error => next(error)); .catch(error => next(error));
@@ -7,7 +7,7 @@ const log10 = val => {
return Math.log(val) / Math.log(10); return Math.log(val) / Math.log(10);
}; };
// GET suggested organizations based on chosen causes + regions // POST to get suggested organizations based on chosen causes + regions
exports.findSuggested = (req, res, next) => { exports.findSuggested = (req, res, next) => {
const { amount, causes, regions } = req.body; const { amount, causes, regions } = req.body;
@@ -23,12 +23,12 @@ exports.findSuggested = (req, res, next) => {
replacements: { causes, regions, max_orgs }, replacements: { causes, regions, max_orgs },
type: db.Sequelize.QueryTypes.SELECT type: db.Sequelize.QueryTypes.SELECT
}) })
.then(orgs => { .then(organizations => {
res.status(200).json({ res.status(200).json({
orgs, organizations,
num_items: orgs.length, num_items: organizations.length,
max_orgs, max_orgs,
distribution: amount / orgs.length distribution: amount / organizations.length
}); });
}) })
.catch(error => next(error)); .catch(error => next(error));
+1 -1
View File
@@ -1,5 +1,5 @@
module.exports = { module.exports = {
cause: require('./cause.controller'), cause: require('./cause.controller'),
region: require('./cause.controller'), region: require('./region.controller'),
organization: require('./organization.controller') organization: require('./organization.controller')
}; };
+2 -1
View File
@@ -7,7 +7,8 @@ module.exports = (sequelize, DataTypes) => {
}, },
name: { name: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false allowNull: false,
unique: true
}, },
amount: { amount: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
+2 -1
View File
@@ -8,7 +8,8 @@ module.exports = (sequelize, DataTypes) => {
name: { type: DataTypes.STRING, allowNull: false }, name: { type: DataTypes.STRING, allowNull: false },
short_description: DataTypes.STRING, short_description: DataTypes.STRING,
primary_cause: { type: DataTypes.STRING, allowNull: false }, primary_cause: { type: DataTypes.STRING, allowNull: false },
primary_region: { type: DataTypes.STRING, allowNull: false } primary_region: { type: DataTypes.STRING, allowNull: false },
rating: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }
}); });
return Organization; return Organization;
}; };
+2 -2
View File
@@ -23,9 +23,9 @@ router.post('/grants/:donor_id', checkAuth, controllers.grant.create);
// DELECT a grant of a donor // DELECT a grant of a donor
router.delete('/grants/:grant_id', checkAuth, controllers.grant.delete); router.delete('/grants/:grant_id', checkAuth, controllers.grant.delete);
// GET suggested organizations to distribute to // POST to get suggested organizations to distribute to
// running "the algorithm" // running "the algorithm"
router.get( router.post(
'/organizations/', '/organizations/',
checkAuth, checkAuth,
controllers.organization.findSuggested controllers.organization.findSuggested