const db = require("../models");
const Ad = db.ads;



// Create and Save a new Tutorial
exports.create = (req, res) => {
    // Validate request
    // if (!req.body.title) {
    //   res.status(400).send({ message: "Content can not be empty!" });
    //   return;
    // }
    console.log(req.files, req.body)
    // Create a Tutorial
    const ad = new Ad({
      title : "hhhhh",
      type : "vente",
      status : "vendu",
      prix : 123,
      date : new Date(),
      images : req.files.map(f=>f.filename)

    });
  
    // Save Tutorial in the database
    ad
      .save(ad)
      .then(data => {
        res.send(data);
      })
      .catch(err => {
        res.status(500).send({
          message:
            err.message || "Some error occurred while creating the Tutorial."
        });
      });
  };



  exports.findAll = (req, res) => {
    
    Ad.find({}, function(err, result) {
      if (err) {
        console.log(err);
      } else {
        res.render('index',{results:result})
      }
    });
  };