Created
December 3, 2019 22:37
-
-
Save angelique-w/773d090d430eadb7db4dadbb1fd9e321 to your computer and use it in GitHub Desktop.
quête express 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
const port = 3000; | |
const connection = require('./conf'); | |
const bodyParser = require('body-parser'); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ | |
extended: true | |
})); | |
app.put('/api/movies/:id', (req, res) => { | |
const idMovie = req.params.id; | |
const formData = req.body; | |
connection.query('UPDATE movie SET ? WHERE id = ?', [formData, idMovie], err => { | |
if (err) { | |
console.log(err); | |
res.status(500).send("Erreur lors de la modification d'un film"); | |
} else { | |
res.sendStatus(200); | |
} | |
}); | |
}); | |
app.listen(port, (err) => { | |
if (err) { | |
throw new Error('Sometthing bad happened...'); | |
} | |
console.log(`Server is listening on ${port}`); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment