From 008800acdf0d0bf052afeb05810ffb4acca50ca5 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Sun, 20 Jan 2019 22:51:08 -0800 Subject: [PATCH] fixing get to post for org suggestions --- app/controllers/donor/grant.controller.js | 5 +++-- app/controllers/donor/organization.controller.js | 10 +++++----- app/controllers/general/index.js | 2 +- app/models/grant.model.js | 3 ++- app/models/organization.model.js | 3 ++- app/routes/donor.route.js | 4 ++-- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/controllers/donor/grant.controller.js b/app/controllers/donor/grant.controller.js index 30c003e..8b8ef66 100644 --- a/app/controllers/donor/grant.controller.js +++ b/app/controllers/donor/grant.controller.js @@ -25,6 +25,7 @@ exports.create = (req, res, next) => { }) .then(result => { res.status(201).json({ + result, message: 'Grant Created' }); }) @@ -58,8 +59,8 @@ exports.delete = (req, res, next) => { message = 'Grant Deleted'; } res.status(201).json({ - message, - result + result, + message }); }) .catch(error => next(error)); diff --git a/app/controllers/donor/organization.controller.js b/app/controllers/donor/organization.controller.js index c9e85fd..7537534 100644 --- a/app/controllers/donor/organization.controller.js +++ b/app/controllers/donor/organization.controller.js @@ -7,7 +7,7 @@ const log10 = val => { 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) => { const { amount, causes, regions } = req.body; @@ -23,12 +23,12 @@ exports.findSuggested = (req, res, next) => { replacements: { causes, regions, max_orgs }, type: db.Sequelize.QueryTypes.SELECT }) - .then(orgs => { + .then(organizations => { res.status(200).json({ - orgs, - num_items: orgs.length, + organizations, + num_items: organizations.length, max_orgs, - distribution: amount / orgs.length + distribution: amount / organizations.length }); }) .catch(error => next(error)); diff --git a/app/controllers/general/index.js b/app/controllers/general/index.js index 29d05c1..904f222 100644 --- a/app/controllers/general/index.js +++ b/app/controllers/general/index.js @@ -1,5 +1,5 @@ module.exports = { cause: require('./cause.controller'), - region: require('./cause.controller'), + region: require('./region.controller'), organization: require('./organization.controller') }; diff --git a/app/models/grant.model.js b/app/models/grant.model.js index 076cc47..453ed5f 100644 --- a/app/models/grant.model.js +++ b/app/models/grant.model.js @@ -7,7 +7,8 @@ module.exports = (sequelize, DataTypes) => { }, name: { type: DataTypes.STRING, - allowNull: false + allowNull: false, + unique: true }, amount: { type: DataTypes.INTEGER, diff --git a/app/models/organization.model.js b/app/models/organization.model.js index 0cb749b..4bb080b 100644 --- a/app/models/organization.model.js +++ b/app/models/organization.model.js @@ -8,7 +8,8 @@ module.exports = (sequelize, DataTypes) => { name: { type: DataTypes.STRING, allowNull: false }, short_description: DataTypes.STRING, 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; }; diff --git a/app/routes/donor.route.js b/app/routes/donor.route.js index 232fa7f..9dec5d8 100644 --- a/app/routes/donor.route.js +++ b/app/routes/donor.route.js @@ -23,9 +23,9 @@ router.post('/grants/:donor_id', checkAuth, controllers.grant.create); // DELECT a grant of a donor 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" -router.get( +router.post( '/organizations/', checkAuth, controllers.organization.findSuggested