restaurant.js 773 B

123456789101112131415161718192021222324
  1. const { Restaurant } = require('../models/restaurant.model');
  2. //get all users
  3. exports.getAllRestaurants = async (req, res, next) => {
  4. Restaurant.find({}).then((data) => { res.status(200).json(data) })
  5. .catch(() => { res.status(500).json({ success: false, message: 'Erreur dans le serveur' }) })
  6. };
  7. //post user
  8. exports.postAllRestaurants = async (req, res, next) => {
  9. const ticket = new Restaurant({
  10. index: req.body.index,
  11. name: req.body.name,
  12. adress: req.body.adress,
  13. longitude: req.body.longitude,
  14. latitude: req.body.latitude
  15. });
  16. ticket.save().then( () => { res.status(201).json({ success: true, message: 'Restaurant ajouté avec succès!'})})
  17. .catch( (error) => { res.status(400).send( error )});
  18. };