Skip to content

Instantly share code, notes, and snippets.

@IchrakMansour
Last active July 11, 2018 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IchrakMansour/54aa487b0ee2d94eb68e6b25a3387ce5 to your computer and use it in GitHub Desktop.
Save IchrakMansour/54aa487b0ee2d94eb68e6b25a3387ce5 to your computer and use it in GitHub Desktop.
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