-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
779 lines (534 loc) · 22.6 KB
/
app.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
const { DTOCustomer } = require("./entity/DTOCustomer");
const { DataCustomer } = require("./data/DataCustomer");
const { DataSuppliers } = require("./data/DataSuppliers");
const { DTOSuppliers } = require("./entity/DTOSuppliers");
const { DTOCategory } = require("./entity/DTOCategory");
const { DataCategory } = require("./data/DataCategory");
const { DataProduct } = require("./data/DataProduct");
const { DTOProduct } = require("./entity/DTOProduct");
const { DTOOffer } = require("./entity/DTOOffer");
const { DataOffer } = require("./data/DataOffer");
const { DataRatingsProduct } = require("./data/DataRatingProduct");
const { DataLoginCustomer } = require("./data/DataLoginCustomer");
const { DataAdministrator } = require("./data/DataAdministrator");
const { DTOAdministrator } = require("./entity/DTOAdministrator");
const { DataLoginAdmin } = require("./data/DataLoginAdmin");
const { DTOSale } = require("./entity/DTOSale");
const { DataSale } = require("./data/DataSale");
//#region ADMIN
// async function registerAdmin() {
// for (let index = 1; index < 100; index++) {
// let dtoadmin = new DTOAdministrator();
// dtoadmin.NameAdmin = "User" + index.toString();
// dtoadmin.UserrName = "Username" + index.toString();
// dtoadmin.Passwordd = "password" + index.toString();
// let registercustomer = await DataAdministrator.registerAdmin(dtoadmin);
// if (registercustomer===-1) {
// throw new
// Error("The username already exists");
// }
// if (registercustomer===-2) {
// throw new
// Error("Username must have more than 8 characters");
// }
// if (registercustomer===-3) {
// throw new
// Error("Passwordd must have more than 8 characters");
// }
// console.log("The admin was registered successfully");
// }
// }
// registerAdmin().then()
// async function updateNameAdmin() {
// let dtoadmin = new DTOAdministrator();
// dtoadmin.IdAdministrator = 3;
// dtoadmin.NameAdmin = "User1";
// let updateNameAdmin = await
// DataAdministrator.updateNameAdmin(dtoadmin);
// if (updateNameAdmin===-1) {
// throw new
// Error("The idadmin does not exists");
// }
// console.log("Admin update successfully");
// }
// updateNameAdmin().then()
// async function updatePassword()
// {
// let idadmin=4;
// let newpassword="password44";
// let currentpassword="password4";
// let updatePassword = await
// DataAdministrator.updatePassword(idadmin,newpassword,currentpassword);
// if (updatePassword===-1) {
// throw new Error("Incorrect idadmin and/or password");
// }
// if (updatePassword===-2) {
// throw new
// Error("Passwordd must have more than 8 characters");
// }
// console.log("Password update successfully");
// }
// updatePassword().then()
// async function deleteAdmin() {
// let deleteAdmin = await DataAdministrator.deleteAdmin(2);
// if (deleteAdmin===-1) {
// throw new
// Error("The idadmin does not exists");
// }
// console.log("Administrator delete successfully");
// }
// deleteAdmin().then()
//#region ADMIN
//#region CUSTOMERS
// async function registerCustomer() {
// for (let index = 300; index < 500; index++) {
// let dtocustomer = new DTOCustomer();
// dtocustomer.namecustomer = "User" + index.toString();
// dtocustomer.userrname = "Username" + index.toString();
// dtocustomer.password = "password" + index.toString();
// dtocustomer.streetname = "streetname" + index.toString();
// dtocustomer.streetnumber = "1111" + index.toString();
// dtocustomer.unit_apartament = "1111" + index.toString();
// dtocustomer.city = "City" + index.toString();
// dtocustomer.statee = "Statee" + index.toString();
// dtocustomer.phone = "1111" + index.toString();
// dtocustomer.email = "email" + index.toString() + "@gmail.com";
// let registercustomer = await DataCustomer.registerCustomer(dtocustomer);
// if (registercustomer===-1) {
// throw new
// Error("The username already exists");
// }
// if (registercustomer===-2) {
// throw new
// Error("Username must have more than 8 characters");
// }
// if (registercustomer===-4) {
// throw new
// Error("The email already exists");
// }
// if (registercustomer===-3) {
// throw new
// Error("Passwordd must have more than 8 characters");
// }
// console.log("The customer registered successfully");
// }
// }
// registerCustomer().then()
// async function updateCustomer() {
// let dtocustomer = new DTOCustomer();
// dtocustomer.idcustomer = 3;
// dtocustomer.namecustomer = "User0";
// dtocustomer.streetname = "streetname0" ;
// dtocustomer.streetnumber = "1111";
// dtocustomer.unit_apartament = "1111";
// dtocustomer.city = "City0";
// dtocustomer.statee = "Statee0";
// dtocustomer.phone = "000000" ;
// dtocustomer.email = "email0@gmail.com";
// let updateCustomer = await DataCustomer.updateCustomer(dtocustomer);
// if (updateCustomer===-1) {
// throw new
// Error("The idcustomer does not exists");
// }
// console.log("Customer update successfully");
// }
// updateCustomer().then()
// async function updatePassword() {
// let idcustomer=4;
// let newpassword="password2";
// let currentpassword="password2";
// let updatePassword = await DataCustomer.updatePassword(idcustomer,newpassword,currentpassword);
// if (updatePassword===-1) {
// throw new Error("Incorrect idcustomer and/or password");
// }
// if (updatePassword===-2) {
// throw new
// Error("Passwordd must have more than 8 characters");
// }
// console.log("Password update successfully");
// }
// updatePassword().then()
// async function deleteCustomer() {
// let deleteCustomer = await DataCustomer.deleteCustomer(3);
// if (deleteCustomer===-1) {
// throw new
// Error("The idcustomer does not exists");
// }
// console.log("Customer delete successfully");
// }
// deleteCustomer().then()
// async function getCustomerById() {
// let getCustomerById =
// await DataCustomer.getCustomerById(4);
// console.log(getCustomerById);
// }
// getCustomerById().then()
//#endregion CUSTOMERS
//#region LOGIN ADMIN
// async function loginAdmin() {
// let loginAdmin = await DataLoginAdmin.
// loginAdmin("Username4","password44");
// if (loginAdmin===-1) {
// throw new
// Error("The Password or Username is incorrect");
// }
// console.log(loginAdmin);
// }
// loginAdmin().then()
// async function existLoginUser() {
// let existLoginAdmin =
// await DataLoginAdmin.existLoginAdmin(4,"Username4")
// console.log(existLoginAdmin);
// }
// existLoginUser().then()
// async function logoutAdmin() {
// let logout = await DataLoginAdmin.
// logout(4);
// if (logout===-1) {
// throw new
// Error("The User is not logged in");
// }
// console.log("The User has logged out");
// }
// logoutAdmin().then()
//#endregion LOGIN ADMIN
//#region LOGIN CUSTOMER
// async function loginCustomer() {
// let loginCustomer = await DataLoginCustomer.
// loginCustomer("Username3","password3");
// if (loginCustomer===-1) {
// throw new
// Error("The Password or Username is incorrect");
// }
// console.log(loginCustomer);
// }
// loginCustomer().then()
// async function existLoginCustomer() {
// let existLoginCustomer =
// await DataLoginCustomer.existLoginCustomer(4,"Username2")
// console.log(existLoginCustomer);
// }
// existLoginCustomer().then()
// async function logout() {
// let logout = await DataLoginCustomer.
// logout(4);
// if (logout===-1) {
// throw new
// Error("The User is not logged in");
// }
// console.log("The User has logged out");
// }
// logout().then()
//#endregion LOGIN CUSTOMER
//#region SUPPLIERS
// async function registerSuppliers() {
// for (let index = 1; index < 100; index++) {
// let dtosuppliers = new DTOSuppliers();
// dtosuppliers.SupplierName = "SupplierName" + index.toString();
// dtosuppliers.AddressSupplier = "AddressSupplier" + index.toString();
// dtosuppliers.CitySupplier = "CitySupplier" + index.toString();
// dtosuppliers.StateSupplier = "StateSupplier" + index.toString();
// dtosuppliers.PhoneSupplier = "11111" + index.toString();
// dtosuppliers.EmailSupplier = "EmailSupplier" + index.toString() + "@gmail.com";
// let registerSuppliers = await DataSuppliers.registerSuppliers(dtosuppliers);
// if (registerSuppliers===-1) {
// throw new
// Error("The email already exists");
// }
// console.log("Supplier registered successfully");
// }
// }
// registerSuppliers().then()
// async function updateSuppliers() {
// let dtosuppliers = new DTOSuppliers();
// dtosuppliers.SupplierId = 108;
// dtosuppliers.SupplierName = "SupplierName10";
// dtosuppliers.AddressSupplier = "AddressSupplier10";
// dtosuppliers.CitySupplier = "CitySupplier10" ;
// dtosuppliers.StateSupplier = "StateSupplier10" ;
// dtosuppliers.PhoneSupplier = "11111010" ;
// let updateSuppliers = await DataSuppliers.updateSuppliers(dtosuppliers);
// if (updateSuppliers===-1) {
// throw new
// Error("The idsupplier does not exist");
// }
// console.log("Supplier updated successfully");
// }
// updateSuppliers().then()
//#endregion SUPPLIERS
//#region CATEGORY
// async function registerCategory() {
// let NameCategory = "NameCategory" ;
// let DescrriptionCategory = "DescrriptionCategory" ;
// let registerCategory = await DataCategory.registerCategory(NameCategory,DescrriptionCategory);
// console.log("Category registered successfully");
// }
// registerCategory().then()
// async function updateCategory() {
// let IdCategory = 2 ;
// let NameCategory = "NameCategory0" ;
// let DescrriptionCategory = "DescrriptionCategory0";
// let updateCategory = await DataCategory.updateCategory(IdCategory,NameCategory,DescrriptionCategory);
// if (updateCategory===-1) {
// throw new
// Error("The IdCategory does not exist");
// }
// console.log("Category updated successfully");
// }
// updateCategory().then()
//#endregion CATEGORY
//#region PRODUCT
// async function registerProduct() {
// for (let index = 80 ; index < 200; index++) {
// let dtoproduct=new DTOProduct();
// dtoproduct.NameProduct = "NameProduct" + index.toString();
// dtoproduct.DescriptionProduct = "DescriptionProduct" + index.toString();
// dtoproduct.UrlImg = "UrlImg" + index.toString();
// dtoproduct.PriceProduct = 40 ;
// dtoproduct.Manufacturer = "Manufacturer" + index.toString();
// dtoproduct.CountryOfOrigin = "CountryOfOrigin" + index.toString();
// dtoproduct.StockProduct =0;
// dtoproduct.Entry_date = '2023-05-10';
// dtoproduct.Expiration_date = '2023-10-10';
// dtoproduct.SupplierId = 110;
// dtoproduct.IdCategory = 2;
// let registerProduct = await DataProduct.registerProduct(dtoproduct);
// if (registerProduct===-1) {
// throw new
// Error("The idsupplier does not exists");
// }
// if (registerProduct===-2) {
// throw new
// Error("The idcategory does not exists");
// }
// console.log("Product registered successfully");
// }
// }
// registerProduct().then()
// async function updateProduct() {
// let dtoproduct=new DTOProduct();
// dtoproduct.IdProduct = 61;
// dtoproduct.NameProduct = "NameProduct0";
// dtoproduct.DescriptionProduct = "DescriptionProduct0" ;
// dtoproduct.PriceProduct = 40 ;
// dtoproduct.Manufacturer = "Manufacturer0";
// dtoproduct.CountryOfOrigin = "CountryOfOrigin0" ;
// dtoproduct.Entry_date = new Date(2023,05,8);
// dtoproduct.Expiration_date = new Date(2023,10,10);
// let updateProduct = await DataProduct.updateProduct(dtoproduct);
// if (updateProduct===-1) {
// throw new
// Error("The idproduct does not exists");
// }
// console.log("Product updated successfully");
// }
// updateProduct().then()
// async function deleteProduct() {
// let idproduct=61;
// let deleteProduct = await DataProduct.deleteProduct(idproduct);
// if (deleteProduct===-1) {
// throw new
// Error("The idproduct does not exists");
// }
// console.log("Stock deleted successfully");
// }
// deleteProduct().then()
// async function addStock() {
// let idproduct=62;
// let quantity=3;
// let addStock = await DataProduct.addStock(idproduct,quantity);
// if (addStock===-1) {
// throw new
// Error("The idproduct does not exists");
// }
// console.log("Stock updated successfully");
// }
// addStock().then()
// async function substractStock() {
// let idproduct=62;
// let quantity=2;
// let substractStock = await DataProduct.substractStock(idproduct,quantity);
// if (substractStock===-1) {
// throw new
// Error("The idproduct does not exists");
// }
// console.log("Product updated successfully");
// }
// substractStock().then()
// async function getProductsOfferByCategory() {
// let idcategory=1;
// let getProductsByCategory =
// await DataProduct.getProductsOfferByCategory(idcategory);
// console.log(getProductsByCategory);
// }
// getProductsOfferByCategory().then()
// async function getProductsOffer() {
// let getProductsOffer =
// await DataProduct.getProductsOffer();
// console.log(getProductsOffer);
// }
// getProductsOffer().then()
// async function getSearchProducts() {
// let getSearchProducts =
// await DataProduct.getSearchProducts();
// console.log(getSearchProducts);
// }
// getSearchProducts().then()
// async function getProductById() {
// let getProductById =
// await DataProduct.getProductById(62);
// console.log(getProductById);
// }
// getProductById().then()
// async function getTodayProductsOffers() {
// let getTodayProductsOffers =
// await DataProduct.getTodayProductsOffers();
// console.log(getTodayProductsOffers);
// }
// getTodayProductsOffers().then()
//#endregion PRODUCT
//#region PRODUCT RATINGS
// async function ratingProduct() {
// let rating=3;
// let idproduct=62;
// let idcustomer=9;
// let ratingProduct = await DataRatingsProduct.ratingProduct(idproduct,idcustomer,rating);
// if (ratingProduct===-1) {
// throw new
// Error("The idproduct does not exists");
// }
// if (ratingProduct===-3) {
// throw new
// Error("The idcustomer does not exists");
// }
// if (ratingProduct===-2) {
// throw new
// Error("The rating must be 1 to 5");
// }
// if (ratingProduct===2) {
// console.log("Product updated successfully");
// }
// if (ratingProduct===1) {
// console.log("Product insert successfully");
// }
// }
// ratingProduct().then()
//#endregion PRODUCT RATINGS
//#region OFFERS
// async function registerOffer() {
// let dtoffer=new DTOOffer();
// dtoffer.DescriptionOffer = "DescriptionOffer";
// dtoffer.DiscountPercentage = 20 ;
// dtoffer.Startt_date ='2023-06-09' ;
// dtoffer.End_date ='2023-06-30' ;
// dtoffer.IdProduct=63;
// let registerOffer = await DataOffer.registerOffer(dtoffer);
// if (registerOffer===-1) {
// throw new
// Error("The idproduct does not exists");
// }
// if (registerOffer===-2) {
// throw new
// Error(" The end date must be greater than start date");
// }
// if (registerOffer===-3) {
// throw new
// Error(" The offer already exists");
// }
// if (registerOffer===-4) {
// throw new
// Error("The Product is out of stock");
// }
// console.log("Offer registered successfully");
// }
// registerOffer().then()
// async function updateOffer() {
// let dtoffer=new DTOOffer();
// dtoffer.DescriptionOffer = "DescriptionOffer2";
// dtoffer.DiscountPercentage = 15 ;
// dtoffer.Startt_date ='2023-06-09' ;
// dtoffer.End_date ='2023-06-29' ;
// dtoffer.IdProduct=62;
// let updateOffer = await DataOffer.updateOffer(dtoffer);
// if (updateOffer===-1) {
// throw new
// Error("The idproduct already exists in the offer");
// }
// if (updateOffer===-2) {
// throw new
// Error(" The end date must be greater than start date");
// }
// if (updateOffer===-3) {
// throw new
// Error(" The offer does not exists");
// }
// console.log("Offer updated successfully");
// }
// updateOffer().then()
//#endregion OFFERS
//#region SALE
// async function registerSale() {
// let dtosale=new DTOSale();
// dtosale.PaymentMethod = "Cash";
// dtosale.Observation = "Observation" ;
// dtosale.IdCustomer = 4 ;
// dtosale.Vat =15 ;
// let arraydetailsale=[];
// arraydetailsale.push({quantity:1,priceproduct:41,idproduct:61})
// arraydetailsale.push({quantity:2,priceproduct:43,idproduct:63})
// arraydetailsale.push({quantity:3,priceproduct:44,idproduct:64})
// arraydetailsale.push({quantity:4,priceproduct:45,idproduct:65})
// let registerOnlineSale = await DataSale.registerOnlineSale(dtosale,arraydetailsale);
// if (registerOnlineSale===-1) {
// throw new
// Error(" The customer does not exists");
// }
// console.log(" The sale was registered successfully");
// }
// registerSale().then()
// async function confirmSale() {
// let idsale=1005;
// let confirmSale = await
// DataSale.confirmSale(idsale);
// if (confirmSale===-1) {
// throw new
// Error(" The sale does not exists");
// }
// console.log(" The sale was confirmed successfully");
// }
// confirmSale().then()
// async function deliverSale() {
// let idsale=8;
// let deliverSale = await
// DataSale.deliverSale(idsale);
// if (deliverSale===-1) {
// throw new
// Error(" The sale does not exists");
// }
// console.log(" The sale was delivered successfully");
// }
// deliverSale().then()
// async function cancelSale() {
// let idsale=8;
// let cancelSale = await
// DataSale.cancelSale(idsale);
// if (cancelSale===-1) {
// throw new
// Error(" The sale does not exists");
// }
// console.log(" The sale was canceled successfully");
// }
// cancelSale().then()
// async function getPendingSalesByCustomer() {
// let getPendingSalesByCustomer =
// await DataSale.getPendingSalesByCustomer();
// console.log(getPendingSalesByCustomer);
// }
// getPendingSalesByCustomer().then()
// async function getConfirmedSalesByCustomer() {
// let getConfirmedSalesByCustomer =
// await DataSale.getConfirmedSalesByCustomer();
// console.log(getConfirmedSalesByCustomer);
// }
// getConfirmedSalesByCustomer().then()
//#endregion SALE