Base methods for Donors model
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const Sequelize = require('sequelize'),
|
const Sequelize = require('sequelize'),
|
||||||
DonorsModel = require('./models/donors.model.js'),
|
DonorsModel = require('../models/donors.model.js'),
|
||||||
CampaignsModel = require('./models/campaigns.model.js');
|
CampaignsModel = require('../models/campaigns.model.js');
|
||||||
|
|
||||||
|
|
||||||
const host = 'am1shyeyqbxzy8gc.cbetxkdyhwsb.us-east-1.rds.amazonaws.com',
|
const host = 'am1shyeyqbxzy8gc.cbetxkdyhwsb.us-east-1.rds.amazonaws.com',
|
||||||
|
|||||||
@@ -1,50 +1,58 @@
|
|||||||
const db = require('../config/db.config.js');
|
const db = require('../config/db.config.js');
|
||||||
const Donors = db.donors;
|
const Donors = db.donors;
|
||||||
|
|
||||||
// Post a Customer
|
// Post a Donor
|
||||||
exports.create = (req, res) => {
|
exports.create = (req, res) => {
|
||||||
// Save to MySQL database
|
// Save to MySQL database
|
||||||
Donors.create({
|
Donors.create({
|
||||||
firstname: req.body.firstname,
|
first_name: req.body.first_name,
|
||||||
lastname: req.body.lastname,
|
middle_name: req.body.middle_name,
|
||||||
age: req.body.age
|
last_name: req.body.last_name,
|
||||||
}).then(customer => {
|
email: req.body.email,
|
||||||
// Send created customer to client
|
age: req.body.age,
|
||||||
res.send(customer);
|
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) => {
|
exports.findAll = (req, res) => {
|
||||||
Donors.findAll().then(customers => {
|
Donors.findAll().then(donors => {
|
||||||
// Send all customers to Client
|
// Send all donors to Client
|
||||||
res.send(customers);
|
res.send(donors);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Find a Customer by Id
|
// Find a Donor by Id
|
||||||
exports.findById = (req, res) => {
|
exports.findById = (req, res) => {
|
||||||
Donors.findById(req.params.customerId).then(customer => {
|
Donors.findById(req.params.donor_id).then(donor => {
|
||||||
res.send(customer);
|
res.send(donor);
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update a Customer
|
// Delete a Donor by Id
|
||||||
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
|
|
||||||
exports.delete = (req, res) => {
|
exports.delete = (req, res) => {
|
||||||
const id = req.params.customerId;
|
const id = req.params.donor_id;
|
||||||
Donors.destroy({
|
Donors.destroy({
|
||||||
where: { id: id }
|
where: { id: id }
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
res.status(200).send('deleted successfully a customer with id = ' + id);
|
res.status(200).send('deleted successfully a donor with id = ' + id);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// // 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);
|
||||||
|
// });
|
||||||
|
// };
|
||||||
@@ -9,11 +9,12 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
middle_name: DataTypes.STRING,
|
middle_name: DataTypes.STRING,
|
||||||
last_name: DataTypes.STRING,
|
last_name: DataTypes.STRING,
|
||||||
email: DataTypes.STRING,
|
email: DataTypes.STRING,
|
||||||
phone: DataTypes.STRING,
|
age: DataTypes.INTEGER,
|
||||||
|
phone: DataTypes.INTEGER,
|
||||||
address: DataTypes.STRING,
|
address: DataTypes.STRING,
|
||||||
city: DataTypes.STRING,
|
city: DataTypes.STRING,
|
||||||
state: DataTypes.STRING,
|
state: DataTypes.STRING,
|
||||||
country: DataTypes.STRING,
|
country: DataTypes.STRING
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
freezeTableName: true,
|
freezeTableName: true,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
|
|
||||||
const donors = require('../controller/donors.controller.js');
|
const donors = require('../controllers/donors.controller.js');
|
||||||
|
|
||||||
// Create a new Donor
|
// Create a new Donor
|
||||||
app.post('/api/donors', donors.create);
|
app.post('/api/donors', donors.create);
|
||||||
@@ -10,10 +10,10 @@ module.exports = function(app) {
|
|||||||
|
|
||||||
// Retrieve a single Donor by Id
|
// Retrieve a single Donor by Id
|
||||||
app.get('/api/donors/:DonorId', donors.findById);
|
app.get('/api/donors/:DonorId', donors.findById);
|
||||||
|
|
||||||
// Update a Donor with Id
|
|
||||||
app.put('/api/donors/:DonorId', donors.update);
|
|
||||||
|
|
||||||
// Delete a Donor with Id
|
// Delete a Donor with Id
|
||||||
app.delete('/api/donors/:DonorId', donors.delete);
|
app.delete('/api/donors/:DonorId', donors.delete);
|
||||||
|
|
||||||
|
// // Update a Donor with Id
|
||||||
|
// app.put('/api/donors/:DonorId', donors.update);
|
||||||
}
|
}
|
||||||
@@ -30,14 +30,14 @@ router.get('/', function (req, res, next) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//adding routes to Express app
|
//adding routes to Express app
|
||||||
require('./app/route/donors.route.js')(app);
|
require('./app/routes/donors.route.js')(app);
|
||||||
|
|
||||||
// Create a Server
|
// Create a Server
|
||||||
var server = app.listen(port, function () {
|
var server = app.listen(port, function () {
|
||||||
|
|
||||||
var host = server.address().address
|
var host = server.address().address;
|
||||||
var port = server.address().port
|
var port = server.address().port;
|
||||||
|
|
||||||
//server is successful
|
//server is successful
|
||||||
console.log("App listening at http://%s:%s", host, port)
|
console.log(`App listening at port: ${port}`)
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user