0

I know there's tons of material on sequelize, but my question is very specific and I can't seem to find the answer anywhere. I'm trying to save the inputs of users for my full stack app, onto my database, using the mvc setup

const restaurants = require('../models').Restaurants;

module.exports ={
  create(req, res){
    return
    Restaurants.create({
      name: req.body.name,
      foodType: req.body.foodType,
      price: req.body.price,
      location: req.body.location
    })

    .then(console.log(req.body))
    .catch(error, function(){
      res.send(error);
    });
  }
}

This code above is not producing any errors, but when I access my routes using my local server and submit an input, it doesn't save any of the data onto my database. I've seen many tutorials that talk about the .sync, and the sequelize instance, but it throws an error when I include that, I think it's because, when I use sequelize init, it automatically creates a file in my models folder called index.js, which I believe already has that code included in it.

Here's what my model file contains

'use strict';
module.exports = (sequelize, DataTypes) => {
  var Restaurants = sequelize.define('Restaurants', {
    name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    foodtype: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    price: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    location: {
      type: DataTypes.STRING,
      allowNull: false,
    },
  }, {});
  Restaurants.associate = function(models) {
    // associations can be defined here
  };
  return Restaurants;
};

Please let me know what I can do. Thank you very much, in advance!

0 Answers0