organize general routes
This commit is contained in:
@@ -3,11 +3,11 @@ const db = require('../config/db.config.js'),
|
||||
jwt = require('jsonwebtoken'),
|
||||
errorMaker = require('../helpers/error.maker');
|
||||
|
||||
const Donors = db.Donors;
|
||||
const Donor = db.Donor;
|
||||
|
||||
// Find a Donor by email + login with JWT
|
||||
exports.login = (req, res, next) => {
|
||||
Donors.findAll({
|
||||
Donor.findAll({
|
||||
where: {
|
||||
email: req.body.email
|
||||
}
|
||||
|
||||
+8
-8
@@ -2,12 +2,12 @@ const db = require('../../config/db.config.js'),
|
||||
bcrypt = require('bcrypt-nodejs'),
|
||||
errorMaker = require('../../helpers/error.maker');
|
||||
|
||||
const Donors = db.Donors;
|
||||
const Donor = db.Donor;
|
||||
|
||||
// Create/post a Donor
|
||||
exports.create = (req, res, next) => {
|
||||
// see if user already in db
|
||||
Donors.findAll({
|
||||
Donor.findAll({
|
||||
where: {
|
||||
email: req.body.email
|
||||
}
|
||||
@@ -22,7 +22,7 @@ exports.create = (req, res, next) => {
|
||||
if (error) {
|
||||
return next(error);
|
||||
} else {
|
||||
Donors.create({
|
||||
Donor.create({
|
||||
first_name: req.body.first_name,
|
||||
middle_name: req.body.middle_name,
|
||||
last_name: req.body.last_name,
|
||||
@@ -50,9 +50,9 @@ exports.create = (req, res, next) => {
|
||||
.catch(error => next(error));
|
||||
};
|
||||
|
||||
// FETCH all Donors
|
||||
// FETCH all Donor
|
||||
exports.findAll = (req, res, next) => {
|
||||
Donors.findAll().then(donors => {
|
||||
Donor.findAll().then(donors => {
|
||||
// Send all donors to Client
|
||||
res.status(200).json({
|
||||
donors,
|
||||
@@ -63,7 +63,7 @@ exports.findAll = (req, res, next) => {
|
||||
|
||||
// Find a Donor by Id
|
||||
exports.findById = (req, res) => {
|
||||
Donors.findById(req.params.donor_id).then(donor => {
|
||||
Donor.findById(req.params.donor_id).then(donor => {
|
||||
res.send(donor);
|
||||
});
|
||||
};
|
||||
@@ -71,7 +71,7 @@ exports.findById = (req, res) => {
|
||||
// Delete a Donor by Id
|
||||
exports.delete = (req, res) => {
|
||||
const id = req.params.donor_id;
|
||||
Donors.destroy({
|
||||
Donor.destroy({
|
||||
where: { id: id }
|
||||
}).then(() => {
|
||||
res.status(200).send('deleted successfully a donor with id = ' + id);
|
||||
@@ -81,7 +81,7 @@ exports.delete = (req, res) => {
|
||||
// // Update a Donor
|
||||
// exports.update = (req, res) => {
|
||||
// const id = req.params.donor_id;
|
||||
// Donors.update( { firstname: req.body.firstname, lastname: req.body.lastname, age: req.body.age },
|
||||
// Donor.update( { firstname: req.body.firstname, lastname: req.body.lastname, age: req.body.age },
|
||||
// { where: {id: req.params.donorId} }
|
||||
// ).then(() => {
|
||||
// res.status(200).send("updated successfully a donor with id = " + id);
|
||||
+6
-6
@@ -1,14 +1,14 @@
|
||||
const db = require('../../config/db.config.js'),
|
||||
errorMaker = require('../../helpers/error.maker');
|
||||
|
||||
const { Grants, Causes, Regions, Organizations } = db;
|
||||
const { Grant, Cause, Region, Organization } = db;
|
||||
|
||||
// Create a grant for certain donor
|
||||
exports.create = (req, res, next) => {
|
||||
const donor_id = req.params.donor_id;
|
||||
const { name, amount, monthly, causes, regions, organizations } = req.body;
|
||||
|
||||
Grants.create({
|
||||
Grant.create({
|
||||
donor_id,
|
||||
name,
|
||||
amount,
|
||||
@@ -33,16 +33,16 @@ exports.create = (req, res, next) => {
|
||||
|
||||
// Find grants with causes, regions, and organizations by donor_id
|
||||
exports.findByDonorId = (req, res, next) => {
|
||||
Grants.findAll({
|
||||
Grant.findAll({
|
||||
where: {
|
||||
donor_id: req.params.donor_id
|
||||
},
|
||||
include: [Causes, Regions, Organizations]
|
||||
include: [Cause, Region, Organization]
|
||||
})
|
||||
.then(grants => {
|
||||
res.status(200).json({
|
||||
grants,
|
||||
number_grants: grants.length
|
||||
number_items: grants.length
|
||||
});
|
||||
})
|
||||
.catch(error => next(error));
|
||||
@@ -51,7 +51,7 @@ exports.findByDonorId = (req, res, next) => {
|
||||
exports.delete = (req, res, next) => {
|
||||
const grant_id = req.params.grant_id;
|
||||
|
||||
Grants.destroy({ where: { id: grant_id } })
|
||||
Grant.destroy({ where: { id: grant_id } })
|
||||
.then(result => {
|
||||
var message = 'Already Deleted';
|
||||
if (result) {
|
||||
@@ -0,0 +1,16 @@
|
||||
const db = require('../../config/db.config.js'),
|
||||
errorMaker = require('../../helpers/error.maker');
|
||||
|
||||
const { Grant, Cause, Region, Organization } = db;
|
||||
|
||||
// FETCH all causes
|
||||
exports.findAll = (req, res, next) => {
|
||||
Cause.findAll()
|
||||
.then(causes => {
|
||||
res.status(200).json({
|
||||
causes,
|
||||
number_items: causes.length
|
||||
});
|
||||
})
|
||||
.catch(error => next(error));
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
cause: require('./cause.controller'),
|
||||
region: require('./cause.controller'),
|
||||
organization: require('./organization.controller')
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
const db = require('../../config/db.config.js'),
|
||||
errorMaker = require('../../helpers/error.maker');
|
||||
|
||||
const { Grant, Cause, Region, Organization } = db;
|
||||
|
||||
// FETCH all organizations
|
||||
exports.findAll = (req, res, next) => {
|
||||
Organization.findAll()
|
||||
.then(organizations => {
|
||||
res.status(200).json({
|
||||
organizations,
|
||||
number_items: organizations.length
|
||||
});
|
||||
})
|
||||
.catch(error => next(error));
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
const db = require('../../config/db.config.js'),
|
||||
errorMaker = require('../../helpers/error.maker');
|
||||
|
||||
const { Grant, Cause, Region, Organization } = db;
|
||||
|
||||
// FETCH all regions
|
||||
exports.findAll = (req, res, next) => {
|
||||
Region.findAll()
|
||||
.then(regions => {
|
||||
res.status(200).json({
|
||||
regions,
|
||||
number_items: regions.length
|
||||
});
|
||||
})
|
||||
.catch(error => next(error));
|
||||
};
|
||||
Reference in New Issue
Block a user