-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
130 lines (107 loc) · 3.86 KB
/
index.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
const path = require("path");
const ProductManager = require("./productManager");
const projectProducts = async () => {
console.log('INICIANDO EL PROYECTO PRODUCT MANAGER');
try {
const pathBase = path.join(__dirname, "db.json")
const manager = new ProductManager(pathBase);
console.log("Sin productos:");
let products = await manager.getProducts();
console.log(products);
console.log("-----------------------------------------------");
//Agrego producto
console.log("Añado los productos:");
await manager.addProduct(product1); //valido
await manager.addProduct(product2); //NO valido -> le falta stock
await manager.addProduct(product3); //NO valido -> le falta descripcion
await manager.addProduct(product4); //valido
console.log("-----------------------------------------------");
console.log("Todos los productos:");
products = await manager.getProducts();
console.log(products);
console.log("-----------------------------------------------");
console.log("Intento agregar producto con codigo ya existente");
await manager.addProduct(product5);
console.log("-----------------------------------------------");
console.log("Busco producto con id 2");
await manager.getProductById(2);
console.log("-----------------------------------------------");
console.log("Busco producto con id 7, que no existe");
await manager.getProductById(7);
console.log("-----------------------------------------------");
console.log("Actualizo producto con algunos datos");
await manager.updateProduct(1,{
description: "Harina Leudante",
price: 35});
console.log("-----------------------------------------------");
console.log("Actualizo producto con todos los datos, pero solo con dos modificaciones");
await manager.updateProduct(2,{
title: "Queso",
description: "Queso roquefort",
price: 45,
thumbnail: "sin imagen",
code: "ABC004",
stock: 32
});
console.log("-----------------------------------------------");
console.log("Actualizo producto que no existe");
await manager.updateProduct(9,{
description: "Harina Leudante",
price: 35});
console.log("-----------------------------------------------");
products = await manager.getProducts();
console.log(products);
console.log("-----------------------------------------------");
console.log("Elimino producto con id 2");
await manager.deleteProduct(2);
console.log("-----------------------------------------------");
console.log("Elimino producto con id 7 que no existe");
await manager.deleteProduct(7);
console.log("-----------------------------------------------");
products = await manager.getProducts();
console.log(products);
} catch (error) {
console.log("projectUsers ~ error:", error);
}
console.log('FIN');
}
projectProducts();
/*Productos*/
let product1 = {
title: "Harina",
description: "Harina 000",
price: 25,
thumbnail: "sin imagen",
code: "ABC001",
stock: 15
}
let product2 = {
title: "Leche",
description: "Leche deslactosada",
price: 30,
thumbnail: "sin imagen",
code: "ABC002"
}
let product3 = {
title: "Gaseosa",
price: 15,
thumbnail: "sin imagen",
code: "ABC003",
stock: 10
}
let product4 = {
title: "Queso",
description: "Queso provolone",
price: 45,
thumbnail: "sin imagen",
code: "ABC004",
stock: 12
}
let product5 = {
title: "Agua",
description: "Agua sin gas",
price: 14,
thumbnail: "sin imagen",
code: "ABC004",
stock: 11
}