function crud(app, path, controller) {
app.get(path, controller.get);
app.post(path, controller.post);
app.delete(`${path}/:id`, controller.delete);
app.put(`${path}/:id`, controller.put);
}
class NotesController {
get(req, res) {
db.listNotes().then(data => res.send(data));
}
post(req, res) {
db.createNote(req.body).then(data => res.send(data));
}
delete(req, res) {
db.deleteNote(req.params.id).then(data => res.send(data));
}
put(req, res) {
db.updateNote(req.params.id).then(data => res.send(data));
}
}
crud(app, '/notes', new NotesController);
crud(app, '/users', new UsersController);
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
passport.use(new LocalStrategy({
usernameField: 'remodal[email]',
passwordField: 'remodal[password]'
}, function(username, password, callback) {
console.log(username, password);
}));
app.post('/login', passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/login'
}));
({
shouldDeps: [
{ elem: 'control'},
{ elem: 'content'},
{ mods: { action: 'article'} },
{ block: 'modal', mods : { theme : 'islands', autoclosable : true }},
'button',
'content',
'menu',
{ block: 'i-bem', elem: 'dom' }
]
}, { tech: 'js', mustDeps: { elem: 'content', tech: 'bemhtml' } })
list: function(callback) {
pool.getConnection(function(err, connection) {
connection.query( 'SELECT * FROM tasks', function(err, rows) {
callback(rows);
connection.release();
});
});
},
var tasks = require('./tasks');
var list = tasks.list(function (rows) {
console.log(rows);
});