/
app.js
740 lines (691 loc) · 24.4 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
const express = require('express');
const app= express();
require('./model/index');
require('./model/indexsql');
const Item = require('./model/item');
const Order=require('./model/order');
const Owner=require('./model/ownerOutlets');
const Ownersql=require('./model/Owner');
const Managersql=require('./model/Manager');
const Employeesql=require('./model/Employee');
const Outlet=require('./model/outlet');
const orderOfOutlet = require('./model/orderofOutlet');
const RawMaterial = require('./model/rawmaterial');
const Menu = require('./model/menu');
const Inventory = require('./model/inventory');
const { ObjectId } = require('mongodb');
const mongoose = require('mongoose');
const Sequelize =require('sequelize');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
const secretKey = 'your_secret_key';
app.use(bodyParser.json());
Managersql.sync();
Ownersql.sync();
Employeesql.sync();
// below function is used for token verifycation
function verifyToken(req, res, next) {
const token = req.headers['authorization'];
if (!token) {
return res.status(401).json({ message: 'Token is missing' });
}
jwt.verify(token, secretKey, (err, decoded) => {
if (err) {
return res.status(401).json({ message: 'Token is invalid' });
}
req.user = decoded;
next();
});
}
// below api is used to log in of owners
app.get('/login',async (req, res) => {
const emailId = req.body.emailId;
const password = req.body.password;
const level = req.body.level;
if ((!emailId )|| (!password)||(!level)){
return res.status(401).json({ message: 'email,password and level all are required' });
}
try{
if(level=="Owner"){
const ownerData= await Ownersql.findByPk(emailId);
if(ownerData===null||ownerData.dataValues===null){
return res.send({"message":"There is no user with such emailId"});
}
const userData =ownerData.dataValues;
const Owner_id=userData.Owner_id;
const expiresIn =3600;
if (userData.password === password) {
const token = jwt.sign({level,Owner_id}, secretKey, { expiresIn });
return res.json({ token });
}
return res.status(401).json({ message: 'Invalid credentials' });
}else if(level=="manager"){
const managerData= await Managersql.findByPk(emailId);
if(managerData===null||managerData.dataValues===null){
return res.send({"message":"There is no user with such emailId"});
}
const userData =managerData.dataValues;
const Manager_id=userData.Manager_id;
const expiresIn =3600;
if (userData.password === password) {
const token = jwt.sign({level,Manager_id}, secretKey, { expiresIn });
return res.json({ token });
}
return res.status(401).json({ message: 'Invalid credentials' });
}else if(level=="employee"){
const employeeData= await Employeesql.findByPk(emailId);
if(employeeData===null||employeeData.dataValues===null){
return res.send({"message":"There is no user with such emailId"});
}
const userData =employeeData.dataValues;
const Employee_id=userData.Employee_id;
const expiresIn =3600;
if (userData.password === password) {
const token = jwt.sign({level,Employee_id}, secretKey, { expiresIn });
return res.json({ token });
}
return res.status(401).json({ message: 'Invalid credentials' });
}else{
return res.send(`There is no role like ${level}`);
}
}catch(error){
res.send(error);
}
});
// This should be done by company
app.post('/create-outlet', verifyToken , async (req, res) => {
// return res.send(req.user);
if(req.user.level!="Owner"){
return res.send("You are not authorised bro");
}
const session = await mongoose.startSession();
session.startTransaction();
console.log(req.user);
try {
const newMenu = new Menu({
newMenu:[]
});
const newPending = new orderOfOutlet({
orders_ids:[]
});
const newServed = new orderOfOutlet({
orders_ids:[]
});
const newTodayServed = new orderOfOutlet({
orders_ids:[]
});
const newInventory = new Inventory({
Inventory:[]
});
const savedMenu = await newMenu.save();
const savedPending = await newPending.save();
const savedServed = await newServed.save();
const savedTodayServed = await newTodayServed.save();
const savedInventory = await newInventory.save();
const newOutlet = new Outlet({
Owner_id : req.user.Owner_id,
Menu_id : savedMenu._id,
Pending_list : savedPending._id,
served_list : savedServed._id,
Todayserved_list : savedTodayServed._id,
inventory_id : savedInventory._id,
});
const savedOutlet = await newOutlet.save();
const _id = req.user.Owner_id;
const updatedOwner = await Owner.findByIdAndUpdate(_id,
{ $push: { Oulets_Ids: savedOutlet._id } },
{ new: true }
);
// console.log(newOutlet);
console.log(_id);
await session.commitTransaction();
session.endSession();
res.json({
message: 'Outlet created and Owner updated successfully',
newOutlet,
updatedOwner
});
} catch (error) {
await session.abortTransaction();
console.error('Error creating outlet and updating owner:', error);
session.endSession();
res.status(500).json({ error: 'Internal Server Error' });
}
});
app.post('/newowner' , verifyToken ,async(req,res)=>{
if(req.user.level!="employee"){
return res.send("Bhosdk kon hai tu ? ");
}
console.log(req.body);
const emailId=req.body.emailId;
const password=req.body.password;
const name=req.body.name;
const contactnumber=req.body.contactnumber;
try{
const userWithSameEmailId= await Ownersql.findByPk(emailId);
if(userWithSameEmailId){
return res.json({"error":"email id already in use"});
}
const newOwner = new Owner();
const genOwner =await newOwner.save();
const ss=String(genOwner._id);
const newUser = await Ownersql.create({
Owner_id :ss,
emailId,
password,
name,
contactnumber
});
console.log(newUser);
res.send(genOwner);
}catch(error){
res.send(error);
}
});
app.get('/myoutlets',verifyToken,async(req,res)=>{
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
try{
const Owner_id=req.user.Owner_id;
// const Owner_id= await Ownersql.findByPk(emailId,{attributes:['Owner_id']});
const outlets =await Owner.findById(Owner_id);
res.send(outlets);
}catch(error){
res.send(error);
}
});
app.get('/mymanagers',verifyToken,async(req,res)=>{
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
try{
const Owner_id=req.user.Owner_id;
// const Owner_id= await Ownersql.findByPk(emailId,{attributes:['Owner_id']});
const outlets =await Owner.findById(Owner_id, 'Manager_Ids');
res.send(outlets.Manager_Ids);
}catch(error){
res.send(error);
}
});
app.post('/addmanager',verifyToken , async(req,res)=>{
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
const Manager_idalreadyinuse = await Managersql.findByPk(req.body.Manager_id);
if(Manager_idalreadyinuse){
return res.send("emailId already in use");
}
// res.send(req.body);
const Manager_id = req.body.Manager_id;
const password = req.body.password;
const name = req.body.name;
const contactnumber = req.body.contactnumber;
const workingAt = req.body.workingAt;
const newManager = await Managersql.create({
Manager_id,
password,
name,
contactnumber,
workingAt
}
);
const updatedownerOutlets =await Owner.findByIdAndUpdate(req.user.Owner_id,
{ $push: { Manager_Ids: newManager.Manager_id } },
{ new: true }
);
res.send("Manager added Successfully");
});
//put all served orders in a seprate collection
// app.post('/ordercompleted',async(req,res)=>{
// try {
// console.log(req.body);
// const newOrder = new Order(req.body);
// const savedOrder = await newOrder.save();
// console.log('Order complted');
// } catch (error) {
// console.error('Error creating and saving Order document:', error);
// }
// return res.send("Saved");
// });
// below apis are relate to menu of a outlet
//handle menu of a particular outlet
app.put('/outlets/menu/:outletId/:itemId', verifyToken,async(req, res) => {
const itemId = req.params.itemId;
const outletId = req.params.outletId;
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
try{
const menuItems= req.body.Menu;
const outlet = await Outlet.findById(outletId);
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if(outlet.Owner_id!=req.user.Owner_id){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
const item = await Item.findById(itemId);
if (!item) {
return res.status(404).json({ error: 'item not found' });
}
item.Name = req.body.item.Name;
item.Description = req.body.item.Description;
item.Price = req.body.item.Price;
item.requirements = req.body.item.requirements;
console.log(item);
const updatedItem = await item.save();
res.json(updatedItem);
} catch (error) {
console.error('Error updating menu:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
//create a new item in menu of a particular outlet
// use session ghanshyam
app.post('/outlets/menu/:outletId',verifyToken, async(req, res) => {
const outletId = req.params.outletId;
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
try{
const session = await mongoose.startSession();
session.startTransaction();
const outlet = await Outlet.findById(outletId,'Menu_id Owner_id');
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if(outlet.Owner_id!=req.user.Owner_id){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
const items = req.body.items;
let i=0;
for(i=0;i<items.length;i++){
const newItem =new Item(items[i]);
const savedItem =await newItem.save();
await Menu.findByIdAndUpdate(
outlet.Menu_id,
{ $push: { Menu: savedItem._id } },
{ new: true }
);
}
session.commitTransaction();
session.endSession();
res.send("outlet menu updated");
} catch (error) {
console.error('Error updating menu:', error);
session.abortTransaction();
session.endSession();
res.status(500).json({ error: 'Internal Server Error' });
}
});
//get menu of a particular outlet
// No authentication
app.get('/outlets/menu/:outletId', async(req, res) => {
const outletId = req.params.outletId;
try{
const outletMenu = await Outlet.findById(outletId ,'Menu_id');
if (!outletMenu) {
return res.status(404).json({ error: 'Outlet not found' });
}
const MenuofOutlet =await Menu.findById(outletMenu.Menu_id).populate('Menu');
console.log(MenuofOutlet);
res.json(MenuofOutlet);
} catch (error) {
console.error('Error in getting menu:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
//set unavailablity
// for manager and owner both
app.put('/outlets/set/:outletId/:itemId',verifyToken, async(req, res) => {
const itemId = req.params.itemId;
const outletId = req.params.outletId;
const set =req.body.set;
try{
if(req.user.level!="Owner"||req.user.level!="manager"){
return res.send("You are not authorised to set availablity");
}
const outlet = await Outlet.findById(outletId);
if((req.user.level=="Owner")&&(outlet.Owner_id!=req.user.Owner_id)){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}else if((req.user.level=="manager")){
const manager =await Managersql.findByPk(req.user.Manager_id,{attributes:['workingAt']});
if(manager.dataValues.workingAt!=outletId){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
}
const item = await Item.findById(itemId);
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if (!item) {
return res.status(404).json({ error: 'item not found' });
}
if(item.Available==0&&set==0){
res.send("already set unavailable");
}else if(item.Available==0&&set==1){
item.Available=1;
item.NotAvailableSince=null;
const updatedItem = await item.save();
res.send("Item is set to available");
}else if(item.Available==1&&set==0){
item.Available=0;
item.NotAvailableSince=Date.now();
const updatedItem = await item.save();
res.send("Item is set to unavailable");
}else{
res.send("already set available");
}
} catch (error) {
console.error('Error updating menu:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
//placeorder as a customer
//no authentication
app.post('/outlets/placeorder/:outletId', async (req, res) => {
const outletId = req.params.outletId;
try {
const session = await mongoose.startSession();
session.startTransaction();
const outlet = await Outlet.findById(outletId,'Pending_list');
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
const newOrder = new Order( req.body.Order);
const savedOrder =await newOrder.save();
await orderOfOutlet.findByIdAndUpdate(
outlet.Pending_list,
{ $push: { orders_ids: savedOrder._id } },
{ new: true }
)
session.commitTransaction();
session.endSession()
res.json(newOrder);
} catch (error) {
console.error('Error pushing object into array:', error);
session.abortTransaction();
session.endSession()
res.status(500).json({ error: 'Internal Server Error' });
}
});
//api to watch pending orders
//use by manager and owner both
app.get('/outlet/pendingorderlist/:outletId', verifyToken ,async(req,res)=>{
const outletId=req.params.outletId;
try{
if(req.user.level!="Owner"||req.user.level!="manager"){
return res.send("You are not authorised to set availablity");
}
const outlet = await Outlet.findById(outletId ,'Pending_list Owner_id');
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if((req.user.level=="Owner")&&(outlet.Owner_id!=req.user.Owner_id)){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}else if((req.user.level=="manager")){
const manager =await Managersql.findByPk(req.user.Manager_id,{attributes:['workingAt']});
if(manager.dataValues.workingAt!=outletId){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
}
const pendingorderlist =await orderOfOutlet.findById(outlet.Pending_list).populate('orders_ids');
console.log(pendingorderlist);
res.json(pendingorderlist);
} catch (error) {
console.error('Error in getting menu:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
//serve an order
//use by manager and owner both
app.post('/outlet/serveorder/:outletId/order',verifyToken ,async(req,res)=>{
const outletId =req.params.outletId;
const orderId =req.body.orderId;
const session = await mongoose.startSession();
session.startTransaction();
try{
if(req.user.level!="Owner"||req.user.level!="manager"){
return res.send("You are not authorised to set availablity");
}
const outlet =await Outlet.findById(outletId,'Pending_list Todayserved_list Owner_id');
if (!outlet){
return res.status(404).json({ error: 'Outlet not found' });
}
if((req.user.level=="Owner")&&(outlet.Owner_id!=req.user.Owner_id)){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}else if((req.user.level=="manager")){
const manager =await Managersql.findByPk(req.user.Manager_id,{attributes:['workingAt']});
if(manager.dataValues.workingAt!=outletId){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
}
const pendinglist =await orderOfOutlet.findByIdAndUpdate(
outlet.Pending_list,
{ $pull: { 'orders_ids': orderId } },
{ new: true }
);
const Todayservedlist =await orderOfOutlet.findByIdAndUpdate(
outlet.Todayserved_list,
{$push: {orders_ids: orderId }}
)
const updatedOrder = await Order.findByIdAndUpdate(
orderId,
{$set :{
'ServingTime': Date.now()
}}
)
session.commitTransaction();
session.endSession();
res.send("pendinglisttoupdate");
}catch (error) {
console.error('Error pushing object into array:', error);
session.abortTransaction();
session.endSession();
res.status(500).json({ error: 'Internal Server Error' });
}
});
//below apis maintain inventory
app.get('/outlet/inventory/:outletId',verifyToken,async (req,res)=>{
const outletId=req.params.outletId;
try{
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
const outlet = await Outlet.findById(outletId ,'inventory_id Owner_id');
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if(outlet.Owner_id!=req.user.Owner_id){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
const todayInventory =await Inventory.findById(outlet.inventory_id).populate("Inventory");
console.log(todayInventory);
res.json(todayInventory);
} catch (error) {
console.error('Error in getting menu:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
// add newitem in inventory
// use by owner
app.post('/outlet/addnewitemtoinventory/:outletId',verifyToken ,async(req,res)=>{
const outletId=req.params.outletId;
const session = await mongoose.startSession();
session.startTransaction();
try{
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
const outlet = await Outlet.findById(outletId ,'inventory_id Owner_id');
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if(outlet.Owner_id!=req.user.Owner_id){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
let i =0;
let raw =req.body.rawMaterial;
for(i=0;i<raw.length;i++){
const newRawMaterial= new RawMaterial(raw[i]);
const savedRawMaterial =await newRawMaterial.save();
const inventory = await Inventory.findByIdAndUpdate(outlet.inventory_id,
{$push: {Inventory: savedRawMaterial._id }}
);
}
console.log(outlet.inventory_id);
session.commitTransaction();
session.endSession();
res.send("inventory");
} catch (error) {
console.error('Error in getting menu:', error);
session.abortTransaction();
session.endSession();
res.status(500).json({ error: 'Internal Server Error' });
}
});
//use by owner to add items
app.put('/outlet/updateinventory/:outletId/:rawMaterialId', verifyToken, async(req,res)=>{
const outletId=req.params.outletId;
const rawMaterialId=req.params.rawMaterialId;
const session = await mongoose.startSession();
session.startTransaction();
try{
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
const outlet = await Outlet.findById(outletId ,'inventory_id Owner_id' );
const rawMaterial = await RawMaterial.findById(rawMaterialId);
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if(outlet.Owner_id!=req.user.Owner_id){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
if (!rawMaterial) {
return res.status(404).json({ error: 'rawMaterial not found' });
}
const updatedRawMaterial = await RawMaterial.findByIdAndUpdate(
rawMaterialId,
{$inc: { "today_Quantity": req.body.quantity, "yesterday_Quantity":req.body.quantity }},
{ new: true }
);
session.commitTransaction();
session.endSession();
res.send(updatedRawMaterial);
} catch (error) {
console.error('Error in getting menu:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
//use by outlet manager and owner both
app.put('/outlet/dailyupdateofinventory/:outletId/:rawMaterialId', verifyToken, async(req,res)=>{
const outletId=req.params.outletId;
const rawMaterialId=req.params.rawMaterialId;
try{
if(req.user.level!="Owner"||req.user.level!="manager"){
return res.send("You are not authorised to set availablity");
}
const outlet = await Outlet.findById(outletId ,'inventory_id Owner_id');
const rawMaterial = await RawMaterial.findById(rawMaterialId);
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if((req.user.level=="Owner")&&(outlet.Owner_id!=req.user.Owner_id)){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}else if((req.user.level=="manager")){
const manager =await Managersql.findByPk(req.user.Manager_id,{attributes:['workingAt']});
if(manager.dataValues.workingAt!=outletId){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}}
if (!rawMaterial) {
return res.status(404).json({ error: 'rawMaterial not found' });
}
const updatedRawMaterial = await RawMaterial.findByIdAndUpdate(
rawMaterialId,
{$set: { "today_Quantity": req.body.quantity}},
{ new: true }
);
res.send(updatedRawMaterial);
} catch (error) {
console.error('Error in getting menu:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
// use by owner
app.get('/outlet/todayservedorders/:outletId',verifyToken ,async(req,res)=>{
const outletId=req.params.outletId;
try{
if(req.user.level!="Owner"){
return res.send("You are not authorised");
}
const outlet = await Outlet.findById(outletId ,'Todayserved_list Owner_id');
if (!outlet) {
return res.status(404).json({ error: 'Outlet not found' });
}
if(outlet.Owner_id!=req.user.Owner_id){
return res.status(404).json({ error: 'You are not authoried to access this outlet'});
}
const todayOrders =await orderOfOutlet.findById(outlet.Todayserved_list).populate("orders_ids");
console.log(todayOrders);
res.json(todayOrders);
} catch (error) {
console.error('Error in getting toayOrders:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
});
// app.get('/outlet/todaypredictedinventoryusage/:outletId',async(req,res)=>{
// const outletId=req.params.outletId;
// try{
// const predictInventory =req.body.predictInventory;
// const outlet = await Outlet.findById(outletId ,'Todayserved_list');
// if (!outlet) {
// return res.status(404).json({ error: 'Outlet not found' });
// }
// let todayOrdersids =await orderOfOutlet.findById(outlet.Todayserved_list);
// todayOrdersids =todayOrdersids.orders_ids;
// console.log(todayOrdersids);
// let i=0;
// const itemsFrequency = new Map();
// const ObjectIds = new Map();
// let todaySale=0;
// for(i=0;i<todayOrdersids.length;i++){
// let orderItems =await Order.findById(todayOrdersids[i],"Items");
// orderItems=orderItems.Items;
// for (const item of orderItems) {
// todaySale+=item.Price*item.Quantity;
// if (itemsFrequency.has(String(item.item_id))) {
// itemsFrequency.set(String(item.item_id), itemsFrequency.get(String(item.item_id)) + item.Quantity);
// } else {
// ObjectIds.set(String(item.item_id),item.item_id);
// itemsFrequency.set(String(item.item_id), 1);
// }
// }
// }
// let result=[];
// for (const [key, value] of itemsFrequency.entries()) {
// result.push({ key, value });
// }
// let todayAnalysis ={
// todaySale,
// result
// };
// console.log(itemsFrequency);
// if(predictInventory==0){
// res.json(todayAnalysis);
// }
// let rr=[];
// for(i=0;i<result.length;i++){
// // let itemsRequirements =await Item.findById(ObjectIds[result[i]],'requirements');
// rr.push([result[i]].key);
// }
// res.json(result);
// }catch (error){
// console.error('Error in getting toayOrders:', error);
// res.status(500).json({ error: 'Internal Server Error' });
// }
// });
app.listen(3000,() =>{
console.log('i m listening');
});