Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. exports.create = (req, res) => {
  2. // Save to MySQL database
  3. Student.create({
  4.  
  5. Name:req.body.Name
  6. }).then(student => {
  7. // Send created customer to client
  8. res.send(student);
  9. });
  10. };
  11.  
  12. // FETCH all Customers
  13. exports.findAll = (req, res) => {
  14. Student.findAll().then(students => {
  15. // Send all customers to Client
  16. res.send(students);
  17. });
  18. };
  19.  
  20. // Find a Customer by Id
  21. exports.findById = (req, res) => {
  22. Student.findOne({where: {id: req.params.studentId}})
  23. .then(student => {
  24. res.send(student);
  25. })
  26. };
  27.  
  28. // Update a Customer
  29. exports.update = (req, res) => {
  30. const id = req.params.studentId;
  31. Student.update( { Name:req.body.Name},
  32. { where: {id: req.params.studentId} }
  33. ).then(() => {
  34. res.status(200).send("updated
  35. successfully with id = " + id);
  36. });
  37. };
  38.  
  39. // Delete a Customer by Id
  40. exports.delete = (req, res) => {
  41. const id = req.params.studentId;
  42. Student.destroy({
  43. where: { id: id }
  44. }).then(() => {
  45. res.status(200).send('deleted successfully with id = ' + id);
  46. });
  47. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement