condensing the controllers for accessing each model separately

This commit is contained in:
Arjun Patel
2019-03-17 00:13:40 -07:00
parent 5587c296e4
commit 6306d3b1a7
27 changed files with 360 additions and 402 deletions
+2 -5
View File
@@ -3,13 +3,10 @@ const express = require('express'),
checkAuth = require('../middleware/check-auth'),
roles = require('../helpers/roles');
const controllers = require('../controllers/admin');
const { organization } = require('../controllers');
// Manual verification of a charity
// TODO: Add checkAuth(roles.ADMIN) back into middleware
router.put(
'/org/:charity_id',
controllers.organization.verifyOrg
);
router.put('/org/:charity_id', organization.verifyCharity);
module.exports = router;
+1 -1
View File
@@ -2,7 +2,7 @@ const express = require('express'),
router = express.Router(),
checkAuth = require('../middleware/check-auth');
const auth = require('../controllers/auth.controller.js');
const { auth } = require('../controllers');
// Check database for donor and get token with donor role
router.post('/donor/login', auth.donorLogin);
+9 -13
View File
@@ -3,34 +3,30 @@ const express = require('express'),
checkAuth = require('../middleware/check-auth'),
roles = require('../helpers/roles');
const controllers = require('../controllers/donor');
const { donor, grant, stripe, organization } = require('../controllers');
// POST donor signup
router.post('/', controllers.donor.create);
router.post('/', donor.createDonor);
// GET all Donors
router.get('/', checkAuth(roles.ADMIN), controllers.donor.findAll);
router.get('/', checkAuth(roles.ADMIN), donor.getAllDonors);
// GET grants with causes, regions, charities by donor_id
router.get('/grants/', checkAuth(roles.DONOR), controllers.grant.findByDonorId);
router.get('/grants/', checkAuth(roles.DONOR), grant.findGrantsByDonorId);
/** POST Create grants with following body:
* - List of id's of selected causes, regions, charities
* - Monthly: true or false
* - donor_id
* */
router.post(
'/grants/',
checkAuth(roles.DONOR),
controllers.grant.create
);
router.post('/grants/', checkAuth(roles.DONOR), grant.createGrant);
// DELETE a grant of a donor
router.delete(
'/grants/',
checkAuth(roles.DONOR),
controllers.stripe.deleteGrant,
controllers.grant.delete
stripe.deleteGrant,
grant.deleteGrant
);
// POST to get suggested organizations to distribute to
@@ -38,14 +34,14 @@ router.delete(
router.post(
'/organizations/',
checkAuth(roles.DONOR),
controllers.organization.findSuggested
organization.findSuggestedCharities
);
// GET min and optimal amount to choose
router.get(
'/organizations/amounts',
checkAuth(roles.DONOR),
controllers.organization.findAmounts
organization.findOptimalBundleAmounts
);
// // Retrieve a single Donor by Id
+6 -10
View File
@@ -3,19 +3,15 @@ const express = require('express'),
checkAuth = require('../middleware/check-auth'),
roles = require('../helpers/roles');
const controllers = require('../controllers/organization');
const { organization, cause, region } = require('../controllers');
// Charity signup route
router.post('/', controllers.organization.create);
router.post('/', organization.createOrganization);
// Add cause
router.post('/cause', checkAuth(roles.ORGANIZATION), controllers.cause.create);
// // Add cause
// router.post('/cause', checkAuth(roles.ORGANIZATION), cause.createCause);
// Add region
router.post(
'/region',
checkAuth(roles.ORGANIZATION),
controllers.region.create
);
// // Add region
// router.post('/region', checkAuth(roles.ORGANIZATION), region.createRegion);
module.exports = router;
+13 -9
View File
@@ -1,27 +1,31 @@
const express = require('express'),
router = express.Router();
const controllers = require('../controllers/public');
const sgController = require('../controllers/sendgrid.controller');
const {
sendgrid,
cause,
region,
organization,
user
} = require('../controllers');
// Retrieve all causes
router.get('/causes', controllers.cause.findAll);
router.get('/causes', cause.getAllCauses);
// Retrieve all regions
router.get('/regions', controllers.region.findAll);
router.get('/regions', region.getAllRegions);
// Retrieve all organizations
router.get('/organizations', controllers.organization.findAll);
router.get('/organizations', organization.getAllOrganizations);
// Retrieve charities based on inputted search
// TODO: fix sql injection attack
router.get('/organizations/:search', controllers.organization.searchOrgs);
router.get('/organizations/:search', organization.searchOrganizations);
// Add user email to database from the landing page
router.post('/users/landing', controllers.user.addEmail);
router.post('/users/landing', user.addEmail);
// Test sending an email
router.post('/email/test', sgController.testEmail);
router.post('/email/test', sendgrid.testEmail);
module.exports = router;
-14
View File
@@ -1,14 +0,0 @@
const express = require('express'),
router = express.Router(),
checkAuth = require('../middleware/check-auth'),
roles = require('../helpers/roles');
const controller = require('../controllers/donor/stripe.controller');
// POST create one time or monthly charge for grant
router.post('/donor/grant', checkAuth(roles.DONOR), controller.grantCharge);
// DELETE grant's plan under subscription
router.delete('/donor/grant', checkAuth(roles.DONOR), controller.deleteGrant);
module.exports = router;