diff --git a/app/config/db.config.js b/app/config/db.config.js index c697549..0f33f0d 100644 --- a/app/config/db.config.js +++ b/app/config/db.config.js @@ -1,6 +1,6 @@ const Sequelize = require('sequelize'), - DonorsModel = require('./models/donors.model.js'), - CampaignsModel = require('./models/campaigns.model.js'); + DonorsModel = require('../models/donors.model.js'), + CampaignsModel = require('../models/campaigns.model.js'); const host = 'am1shyeyqbxzy8gc.cbetxkdyhwsb.us-east-1.rds.amazonaws.com', diff --git a/app/controllers/donors.controller.js b/app/controllers/donors.controller.js index d257a93..5d0dd91 100644 --- a/app/controllers/donors.controller.js +++ b/app/controllers/donors.controller.js @@ -1,50 +1,58 @@ const db = require('../config/db.config.js'); const Donors = db.donors; -// Post a Customer +// Post a Donor exports.create = (req, res) => { // Save to MySQL database Donors.create({ - firstname: req.body.firstname, - lastname: req.body.lastname, - age: req.body.age - }).then(customer => { - // Send created customer to client - res.send(customer); + first_name: req.body.first_name, + middle_name: req.body.middle_name, + last_name: req.body.last_name, + email: req.body.email, + age: req.body.age, + phone: req.body.phone, + address: req.body.address, + city: req.body.city, + state: req.body.state, + country: req.body.country + }).then(donor => { + // Send created donor to client + res.send(donor); }); }; -// FETCH all Customers +// FETCH all Donors exports.findAll = (req, res) => { - Donors.findAll().then(customers => { - // Send all customers to Client - res.send(customers); + Donors.findAll().then(donors => { + // Send all donors to Client + res.send(donors); }); }; -// Find a Customer by Id +// Find a Donor by Id exports.findById = (req, res) => { - Donors.findById(req.params.customerId).then(customer => { - res.send(customer); + Donors.findById(req.params.donor_id).then(donor => { + res.send(donor); }) }; -// Update a Customer -exports.update = (req, res) => { - const id = req.params.customerId; - Donors.update( { firstname: req.body.firstname, lastname: req.body.lastname, age: req.body.age }, - { where: {id: req.params.customerId} } - ).then(() => { - res.status(200).send("updated successfully a customer with id = " + id); - }); -}; - -// Delete a Customer by Id +// Delete a Donor by Id exports.delete = (req, res) => { - const id = req.params.customerId; + const id = req.params.donor_id; Donors.destroy({ where: { id: id } }).then(() => { - res.status(200).send('deleted successfully a customer with id = ' + id); + res.status(200).send('deleted successfully a donor with id = ' + id); }); -}; \ No newline at end of file +}; + + +// // 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 }, +// { where: {id: req.params.donorId} } +// ).then(() => { +// res.status(200).send("updated successfully a donor with id = " + id); +// }); +// }; \ No newline at end of file diff --git a/app/models/donors.model.js b/app/models/donors.model.js index eb32163..adebd74 100644 --- a/app/models/donors.model.js +++ b/app/models/donors.model.js @@ -9,11 +9,12 @@ module.exports = (sequelize, DataTypes) => { middle_name: DataTypes.STRING, last_name: DataTypes.STRING, email: DataTypes.STRING, - phone: DataTypes.STRING, + age: DataTypes.INTEGER, + phone: DataTypes.INTEGER, address: DataTypes.STRING, city: DataTypes.STRING, state: DataTypes.STRING, - country: DataTypes.STRING, + country: DataTypes.STRING }, { freezeTableName: true, diff --git a/app/routes/donors.route.js b/app/routes/donors.route.js index 45f2b68..b39734c 100644 --- a/app/routes/donors.route.js +++ b/app/routes/donors.route.js @@ -1,6 +1,6 @@ module.exports = function(app) { - const donors = require('../controller/donors.controller.js'); + const donors = require('../controllers/donors.controller.js'); // Create a new Donor app.post('/api/donors', donors.create); @@ -10,10 +10,10 @@ module.exports = function(app) { // Retrieve a single Donor by Id app.get('/api/donors/:DonorId', donors.findById); - - // Update a Donor with Id - app.put('/api/donors/:DonorId', donors.update); - + // Delete a Donor with Id app.delete('/api/donors/:DonorId', donors.delete); + + // // Update a Donor with Id + // app.put('/api/donors/:DonorId', donors.update); } \ No newline at end of file diff --git a/server.js b/server.js index 85262ee..4122275 100644 --- a/server.js +++ b/server.js @@ -30,14 +30,14 @@ router.get('/', function (req, res, next) { }); //adding routes to Express app -require('./app/route/donors.route.js')(app); +require('./app/routes/donors.route.js')(app); // Create a Server var server = app.listen(port, function () { - var host = server.address().address - var port = server.address().port + var host = server.address().address; + var port = server.address().port; //server is successful - console.log("App listening at http://%s:%s", host, port) + console.log(`App listening at port: ${port}`) }) \ No newline at end of file