-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientesWS.js
135 lines (119 loc) · 4.3 KB
/
clientesWS.js
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const conexion=require('./conexion.js');
const sql=require('mssql');
//Consulta de todos los clientes
async function getClientes(){
try{
let pool=await sql.connect(conexion);
let salida=await pool.request().query('select * from Clientes');
return salida.recordsets;
}catch(err){
console.log(err);
}
}
//Consulta un cliente especifico
async function getCliente(IDCliente){
try{
let pool=await sql.connect(conexion);
let salida=await pool.request()
.input('IDCliente',sql.Int,IDCliente)
.query('select * from Clientes where IDCliente= @IDCliente');
return salida.recordsets;
}catch(err){
console.log(err);
}
}
//Insert de los productos
async function newCliente(cliente){
try{
let pool=await sql.connect(conexion);
let newCliente=await pool.request()
// .input('IDServicio',sql.Int,servicio.IDServicio)
.input('NombreCliente',sql.VarChar,cliente.NombreCliente)
.input('ApePatCliente',sql.VarChar,cliente.ApePatCliente)
.input('ApeMatCliente',sql.VarChar,cliente.ApeMatCliente)
.input('CorreoCliente',sql.VarChar,cliente.CorreoCliente)
.input('TelefonoCliente',sql.VarChar,cliente.TelefonoCliente)
.input('Username',sql.VarChar,cliente.Username)
.input('Contraseña',sql.VarChar,cliente.Contraseña)
.execute('pr_newCliente');
return newCliente.recordsets;
} catch (err) {
throw new Error ('Se presentó un error en el procedimiento almacenado agregar cliente');
}
}
//Update de un cliente
async function upCliente(cliente){
try{
let pool=await sql.connect(conexion);
let upCliente=await pool.request()
.input('IDCliente',sql.Int,cliente.IDCliente)
.input('NombreCliente',sql.VarChar,cliente.NombreCliente)
.input('ApePatCliente',sql.VarChar,cliente.ApePatCliente)
.input('ApeMatCliente',sql.VarChar,cliente.ApeMatCliente)
.input('CorreoCliente',sql.VarChar,cliente.CorreoCliente)
.input('TelefonoCliente',sql.VarChar,cliente.TelefonoCliente)
.input('Username',sql.VarChar,cliente.Username)
.input('Contraseña',sql.VarChar,cliente.Contraseña)
.execute('pr_upCliente');
return upCliente.recordsets;
} catch (err) {
throw new Error ('Se presentó un error en el procedimiento almacenado actualizar cliente');
}
}
//Delete de un cliente
async function delCliente(IDCliente){
try{
let pool=await sql.connect(conexion);
let delCliente=await pool.request()
.input('IDCliente',sql.Int,IDCliente)
.execute('pr_delCliente');
return delCliente.recordsets;
} catch (err) {
throw new Error ('Se presentó un error en el procedimiento almacenado eliminar cliente');
}
}
//CAMBIOS EN CLASE CLIENTESWS
//Funcion para obtener cliente por correo y contraseña
async function getClienteMov(cliente){
try{
let pool=await sql.connect(conexion);
let salida=await pool.request()
.input('CorreoCliente',sql.VarChar,cliente.CorreoCliente)
.input('Contraseña', sql.VarChar,cliente.Contraseña)
.query('select * from Clientes where CorreoCliente= @CorreoCliente AND Contraseña= @Contraseña');
return salida.recordsets;
}catch(err){
console.log(err);
}
}
//Funcion para obtener cliente por ID
async function getClienteInf(cliente){
try{
let pool=await sql.connect(conexion);
let salida=await pool.request()
.input('IDCliente',sql.Int,cliente.IDCliente)
.query('select * from Clientes where IDCliente= @IDCliente');
return salida.recordsets;
}catch(err){
console.log(err);
}
}
async function getIDClientes(){
try{
let pool=await sql.connect(conexion);
let salida=await pool.request().query('select IDCliente from Clientes');
return salida.recordsets;
}catch(err){
console.log(err);
}
}
module.exports={
getClientes:getClientes,
getCliente:getCliente,
newCliente:newCliente,
upCliente:upCliente,
delCliente:delCliente,
getClienteMov:getClienteMov,
getClienteInf:getClienteInf,
getIDClientes:getIDClientes
}