Skip to content

Commit

Permalink
Actualizacion
Browse files Browse the repository at this point in the history
  • Loading branch information
ff committed Jun 27, 2021
1 parent 454863e commit 558b0e0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
2 changes: 2 additions & 0 deletions connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ module.exports = () => {
port: GlobalEnv.portdb,
password: GlobalEnv.passwordDb,
database: GlobalEnv.database,
wait_timeout : 28800,
connect_timeout :10
});
};
19 changes: 14 additions & 5 deletions controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Usuario = require("../models/Usuarios");
const bcrypt = require("bcrypt");
const dbConnection = require("../connect");
const connect = require("../connect");
const connection = dbConnection();


Expand All @@ -25,11 +26,14 @@ function registerUser(req, res) {
const user = req.body.transaction;
const saltRounds = 10;
const newUsuario = new Usuario(user);
newUsuario.us_id = "kljdadjldjsajk"

bcrypt.hash(newUsuario.password, saltRounds).then((hash) => {
bcrypt.hash(newUsuario.us_contrasena, saltRounds).then((hash) => {
connection.connect()
connection.query(
"INSERT INTO usuario values(?,?,?,?)", [newUsuario.id, newUsuario.nombre, newUsuario.email, hash],
"INSERT INTO Usuario (us_id,us_nombres,us_celular,us_correo,us_departamento,us_provincia,us_distrito,us_contrasena) values(?,?,?,?,?,?,?,?)" , [newUsuario.us_id,newUsuario.us_nombres,newUsuario.us_celular, newUsuario.us_correo, newUsuario.us_departamento,newUsuario.us_provincia,newUsuario.us_distrito, hash],
(err, result) => {
console.log(err)
if (err) {
return res.status(200).send({
status: "FAILED",
Expand All @@ -41,10 +45,15 @@ function registerUser(req, res) {
message: "Usuario registrado correctamente",
});
}

}
);

});

)
console.log(connection.state)
;

},
);
}

function loginUser(req, res) {
Expand Down
21 changes: 11 additions & 10 deletions models/Usuarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
class Usuario {

constructor(user) {
this.id = user.id,
this.nombres = user.nombres,
this.apellidos = user.apellidos,
this.celular = user.celular,
this.departamento = user.departamento,
this.provincia = user.provincia,
this.distrito = user.distrito,
this.clasificacion = user.clasificacion,
this.email = user.email,
this.password = user.password
this.us_id = user.us_id,
this.us_nombres = user.us_nombres,
//this.us_apellidos = user.us_apellidos,
this.us_celular = user.us_celular,
this.us_correo = user.us_correo,
this.us_departamento = user.us_departamento,
this.us_provincia = user.us_provincia,
this.us_distrito = user.us_distrito,
this.us_contrasena = user.us_contrasena,
this.us_calificacion = user.us_calificacion

// this.createAt = user.createAt || new Date()
}
}
Expand Down
2 changes: 1 addition & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ api.all("*", function(req, res, next) {
});

api.get("/", function(req, res) {
res.send("Web service Trabaja Perú (:");
res.send("Web service Trabaja Perú");
});

api.post("/user", user);
Expand Down

0 comments on commit 558b0e0

Please sign in to comment.