1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| class Client {
constructor() {
this.client = {}
this.errorMessage = [];
this.warningMessage = [];
}
profilClean(client) {
this._id = client?parseInt(client.id)||0:0;
this._login = lib.cleanVar(client.login, ['lower']) || '';
this._password = lib.cleanVar(client.password) || '';
this._activated = parseInt(client.activated)===1?1:0;
this._comment = lib.cleanVar(client.comment) || '';
}
recordUser() {
var _this = this;
connection.query(mysql.format(req_sel1,[_this._login]), function(err, rows) {
if (err) {
if (lib.isDevEnv())
console.log(err);
else
lib.sendMailErrorCode({"title": "Échec lors de la recherche du login : " + _this._login, "message": __lineFunction }, __lineFunction);
return false;
} else if (rows.length==0) {
connection.query(mysql.format(req_client_ins2,[req.session.user.idSociete, _this._comment, _this._activated]), function(err, rows) {
if (err||rows.affectedRows==0) {
if (lib.isDevEnv())
console.log(err);
else
lib.sendMailErrorCode({"title": "Échec lors de l\'enregistrement du client' : " + _this._login, "message": __lineFunction }, __lineFunction);
return false;
} else {
_this._id = rows.insertId;
return true;
}
})
} else if (rows.length>0) {
var row = rows[0];
if (row.id==_this.id&&row.idSociete==req.session.user.idSociete) {
connection.query(mysql.format(req_user_upd4,[_this._comment, _this._activated, _this._id, req.session.user.idSociete]), function(err, rows) {
if (err) {
if (lib.isDevEnv())
console.log(err);
else
lib.sendMailErrorCode({"title": "Échec lors de la mise à jour du client : " + _this._login, "message": __lineFunction }, __lineFunction);
return false;
} else if (rows.affectedRows==0) {
_this._errorMessage.push('Échec de la modification de la fichier client : ' + _this._login);
return false;
} else return true;
})
} else {
_this._errorMessage.push("L'adresse email '" + _this._login + "' est déjà utilisée.");
return false;
}
}
})
}
recordAdress() {
/*...*/
}
}
var client = new Client();
client.profilClean(data.client)
client.recordUser(); |
Partager