Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var mysql = require('mysql');
var bcrypt = require('bcryptjs');
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'ichrak',
database: 'brillo',
insecureAuth: true
});
connection.connect(function(err) {
if (!err) {
console.log("Database is connected ...");
}
else {
console.log("Error connecting database ... ", err);
}
});
exports.ajouterclient = function(req, res) {
console.log("req",req.body);
var today = new Date();
// bcrypt.hash(req.body.password, 5, function( err, bcryptedPassword) {
//save to db
var clients = {
"Code": req.body.Code,
"Prenom": req.body.Prenom,
"Nom": req.body.Nom,
"FAX": req.body.FAX,
"Telephone": req.body.Telephone,
"Email": req.body.Email,
"Adresse1": req.body.Adresse1,
"Adresse2": req.body.Adresse2,
"created": today,
"modified": today
}
connection.query('INSERT INTO clients SET ?', clients, function(error, results, fields) {
if (error) {
console.log("error ocurred", error);
res.send({
"code": 400,
"failed": "error ocurred"
})
}
else {
// console.log('The solution is: ', results);
res.send({
"code": 200,
"success": "client registered sucessfully"
});
}
//});
// });
})
};
exports.listeclients = function(req, res) {
var Code = req.body.Code;
var Prenom = req.body.Prenom ;
var Nom = req.body.Nom;
var Email = req.body.Email;
var Telephone = req.body.Telephone;
connection.query('SELECT Code, Prenom, Nom, Email, Telephone FROM clients ', function(error, results, fields) {
if(error) throw error;
res.send(JSON.stringify(results));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment