-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetallesWS.js
84 lines (73 loc) · 2.41 KB
/
detallesWS.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
const conexion=require('./conexion.js');
const sql=require('mssql');
//Consulta de todos los detalles
async function getDetalles(){
try{
let pool=await sql.connect(conexion);
let salida=await pool.request().query('select * from Detalles');
return salida.recordsets;
}catch(err){
console.log(err);
}
}
//Consulta un detalle especifico
async function getDetalle(IDVenta){
try{
let pool=await sql.connect(conexion);
let salida=await pool.request()
.input('IDVenta',sql.Int,IDVenta)
.query('select * from Detalles where IDVenta= @IDVenta');
return salida.recordsets;
}catch(err){
console.log(err);
}
}
//Insert de los detalles
async function newDetalle(detalle){
try{
let pool=await sql.connect(conexion);
let newDetalle=await pool.request()
.input('IDVenta',sql.Int,detalle.IDVenta)
.input('IDProducto',sql.Int,detalle.IDProducto)
.input('CantidadProd',sql.Int,detalle.CantidadProd)
.input('Subtotal',sql.Money,detalle.Subtotal)
.execute('pr_newDetalle');
return newDetalle.recordsets;
} catch (err) {
throw new Error ('Se presentó un error en el procedimiento almacenado agregar detalle');
}
}
//Update de un detalle
async function upDetalle(detalle){
try{
let pool=await sql.connect(conexion);
let upDetalle=await pool.request()
.input('IDVenta',sql.Int,detalle.IDVenta)
.input('IDProducto',sql.Int,detalle.IDProducto)
.input('CantidadProd',sql.Int,detalle.CantidadProd)
.input('Subtotal',sql.Money,detalle.Subtotal)
.execute('pr_upDetalle');
return upDetalle.recordsets;
} catch (err) {
throw new Error ('Se presentó un error en el procedimiento almacenado actualizar detalle');
}
}
//Delete de un detalle
async function delDetalle(IDVenta){
try{
let pool=await sql.connect(conexion);
let delDetalle=await pool.request()
.input('IDVenta',sql.Int,IDVenta)
.execute('pr_delDetalle');
return delDetalle.recordsets;
} catch (err) {
throw new Error ('Se presentó un error en el procedimiento almacenado eliminar detalle');
}
}
module.exports={
getDetalles:getDetalles,
getDetalle:getDetalle,
newDetalle:newDetalle,
upDetalle:upDetalle,
delDetalle:delDetalle
}