August 2016
Intermediate to advanced
376 pages
6h 33m
English
The next step is to create the controls for the models User and Band:
controllers folder, create a new file called User.js and add the following code: var models = require('../models/index');
var User = require('../models/user');
// Create Users
exports.create = function(req, res) {
// create a new instance of the Users model with request body
models.User.create({
name: req.body.name,
email: req.body.email
}).then(function(user) {
res.json(user);
});
};
// List Users
exports.list = function(req, res) {
// List all users
models.User.findAll({}).then(function(users) {
res.json(users);
});
};
Note that the first line of the file imports the index model; this file is the basis for creation of all the ...