Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. const express = require('express');
  2. const app = express();
  3. const port = 3000;
  4. // para importar la cofiguración de la BD
  5. const connection = require('./conf');
  6. const bodyParser = require('body-parser');
  7. // Support JSON-encoded bodies
  8. app.use(bodyParser.json());
  9. // Support URL-encoded bodies
  10. app.use(bodyParser.urlencoded({
  11. extended: true
  12. }));
  13.  
  14.  
  15.  
  16. app.put('/api/movie/:id', (req, res) => {
  17. console.log("PUT /api/movie", req.body)
  18. const idMovie = req.params.id;
  19. const formData = req.body;
  20. connection.query('UPDATE movie SET ? WHERE id = ?', [formData, idMovie], err => {
  21. if (err) {
  22. // If an error has occurred, then the user is informed of the error
  23. console.log(err);
  24. res.status(500).send("Error editing a movie");
  25. } else {
  26. // If everything went well, we send a status "ok".
  27. res.sendStatus(200);
  28. }
  29. });
  30. });
  31.  
  32.  
  33.  
  34. app.listen(port, function() {
  35. // if (err) {
  36. //throw new Error('Something bad happened...');
  37. // }
  38.  
  39. console.log(`Server is listening on ${port}`);
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement