tango-app-api-infra 3.0.92-dev → 3.0.93-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-infra",
3
- "version": "3.0.92-dev",
3
+ "version": "3.0.93-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
 
2
- import { countDocumentsStore } from '../services/store.service.js';
2
+ import { aggregateStore, countDocumentsStore } from '../services/store.service.js';
3
3
  import { logger, download, getUTC } from 'tango-app-api-middleware';
4
4
  import { aggregateTangoTicket } from '../services/tangoTicket.service.js';
5
5
  import { findinfraReason } from '../services/infraReason.service.js';
@@ -11,6 +11,20 @@ export async function infraCard( req, res ) {
11
11
  try {
12
12
  let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
13
13
  let storeCount = await countDocumentsStore( { 'clientId': { $in: req.body.clientId }, 'createdAt': { $lte: date.end }, 'edge.firstFile': true, 'status': 'active' } );
14
+ let totalstores = await aggregateStore( [ {
15
+ $match: {
16
+ '$and': [
17
+ { 'clientId': { $in: req.body.clientId } },
18
+ { 'edge.firstFile': true },
19
+ { 'status': 'active' },
20
+ { 'createdAt': { $lte: date.end } },
21
+ ],
22
+ },
23
+ } ] );
24
+ let totalnumberstores = [];
25
+ for ( let store of totalstores ) {
26
+ totalnumberstores.push( store.storeId );
27
+ }
14
28
  let infraStoreCount = await aggregateTangoTicket( [
15
29
  {
16
30
  $match: {
@@ -18,6 +32,7 @@ export async function infraCard( req, res ) {
18
32
  { issueType: 'infra' },
19
33
  { status: { $ne: 'closed' } },
20
34
  { 'basicDetails.clientId': { $in: req.body.clientId } },
35
+ { 'basicDetails.storeId': { $in: totalnumberstores } },
21
36
  // { createdAt: { $gte: date.start } },
22
37
  { createdAt: { $lte: date.end } },
23
38
  ],
@@ -54,6 +69,7 @@ export async function infraCard( req, res ) {
54
69
  { status: { $ne: 'closed' } },
55
70
  { 'ticketDetails.issueStatus': 'identified' },
56
71
  { 'basicDetails.clientId': { $in: req.body.clientId } },
72
+ { 'basicDetails.storeId': { $in: totalnumberstores } },
57
73
  // { createdAt: { $gte: date.start } },
58
74
  { createdAt: { $lte: date.end } },
59
75
  ],
@@ -171,11 +187,14 @@ export async function installationCard( req, res ) {
171
187
  } );
172
188
  let installedCount = await countDocumentsStore( {
173
189
  'clientId': { $in: req.body.clientId },
174
- 'edge.firstFile': true, 'status': 'active', 'createdAt': { $lte: date.end },
190
+ 'edge.firstFile': true,
191
+ 'status': 'active',
192
+ 'createdAt': { $lte: date.end },
175
193
  } );
176
194
  let deactiveCount = await countDocumentsStore( {
177
195
  'clientId': { $in: req.body.clientId },
178
196
  'status': 'deactive',
197
+ 'createdAt': { $lte: date.end },
179
198
  } );
180
199
  let yettoInstallCount = await aggregateTangoTicket( [
181
200
  {
@@ -285,18 +304,36 @@ export async function infraIssuesTable( req, res ) {
285
304
  try {
286
305
  let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
287
306
  let issueStatus = [ 'identified' ];
288
- if ( req.body.filterIssue == 'Issues Not Identified' ) {
307
+ if ( req.body.infrafilterIssue == 'Issues Not Identified' ) {
289
308
  issueStatus = [ 'notidentified' ];
290
309
  };
291
- if ( req.body.filterIssue == 'All Issues' ) {
310
+ if ( req.body.infrafilterIssue == 'All Issues' ) {
292
311
  issueStatus = [ 'notidentified', 'identified' ];
293
312
  };
313
+ if ( req.body.infrafilterIssue == 'Live Stores' ) {
314
+ issueStatus = [ 'notidentified', 'identified' ];
315
+ };
316
+ let totalstores = await aggregateStore( [ {
317
+ $match: {
318
+ '$and': [
319
+ { 'clientId': { $in: req.body.clientId } },
320
+ { 'edge.firstFile': true },
321
+ { 'status': 'active' },
322
+ { 'createdAt': { $lte: date.end } },
323
+ ],
324
+ },
325
+ } ] );
326
+ let totalnumberstores = [];
327
+ for ( let store of totalstores ) {
328
+ totalnumberstores.push( store.storeId );
329
+ }
294
330
  let query = [ {
295
331
  $match: {
296
332
  $and: [
297
333
  { issueType: 'infra' },
298
334
  { status: { $ne: 'closed' } },
299
335
  { 'basicDetails.clientId': { $in: req.body.clientId } },
336
+ { 'basicDetails.storeId': { $in: totalnumberstores } },
300
337
  { 'ticketDetails.issueStatus': { $in: issueStatus } },
301
338
  // { createdAt: { $gte: date.start } },
302
339
  { createdAt: { $lte: date.end } },
@@ -369,10 +406,49 @@ export async function infraIssuesTable( req, res ) {
369
406
  },
370
407
  },
371
408
  ];
372
- if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'Identified Issues' && req.body.filterIssue != 'Issues Not Identified'&&req.body.filterIssue != 'All Issues' ) {
409
+ let storesQuery = [];
410
+ if ( req.body.infrafilterIssue == 'Total Stores' ) {
411
+ storesQuery.push( {
412
+ $match: {
413
+ '$and': [
414
+ { 'clientId': { $in: req.body.clientId } },
415
+ { 'edge.firstFile': true },
416
+ { 'status': 'active' },
417
+ { 'createdAt': { $lte: date.end } },
418
+ ],
419
+ },
420
+ },
421
+ );
422
+ }
423
+ if ( req.body.infrafilterIssue == 'Live Stores' ) {
424
+ let infrastores = await aggregateTangoTicket( query );
425
+ let infraissueStore = [];
426
+ for ( let store of infrastores ) {
427
+ infraissueStore.push( store.storeId );
428
+ }
429
+ let result = [];
430
+ for ( let data of totalnumberstores ) {
431
+ if ( infraissueStore.length > 0 && !infraissueStore.includes( data ) ) {
432
+ result.push( data );
433
+ }
434
+ }
435
+ storesQuery.push(
436
+ {
437
+ $match: {
438
+ '$and': [
439
+ { 'storeId': { $in: result } },
440
+ ],
441
+ },
442
+ },
443
+ );
444
+ }
445
+ if ( req.body.infrafilterIssue && req.body.infrafilterIssue != '' &&
446
+ req.body.infrafilterIssue != 'Identified Issues' &&
447
+ req.body.infrafilterIssue != 'Issues Not Identified' &&
448
+ req.body.infrafilterIssue != 'All Issues' ) {
373
449
  query.push( {
374
450
  $match: {
375
- primaryIssue: req.body.filterIssue,
451
+ primaryIssue: req.body.infrafilterIssue,
376
452
  },
377
453
  } );
378
454
  }
@@ -385,6 +461,14 @@ export async function infraIssuesTable( req, res ) {
385
461
  ],
386
462
  },
387
463
  } );
464
+ storesQuery.push( {
465
+ $match: {
466
+ $or: [
467
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
468
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
469
+ ],
470
+ },
471
+ } );
388
472
  }
389
473
  if ( req.body.filter && req.body.filter.length > 0 ) {
390
474
  query.push(
@@ -399,16 +483,32 @@ export async function infraIssuesTable( req, res ) {
399
483
  query.push( {
400
484
  $sort: { [req.body.sortColumName]: req.body.sortBy },
401
485
  } );
486
+ storesQuery.push( {
487
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
488
+ } );
489
+ }
490
+ let count;
491
+ if ( req.body.infrafilterIssue == 'Live Stores' || req.body.infrafilterIssue == 'Total Stores' ) {
492
+ count = await aggregateStore( storesQuery );
493
+ } else {
494
+ count = await aggregateTangoTicket( query );
402
495
  }
403
- let count = await aggregateTangoTicket( query );
404
- console.log( count.length );
405
496
  if ( req.body.limit && req.body.offset && !req.body.export ) {
406
497
  query.push(
407
498
  { $skip: ( req.body.offset - 1 ) * req.body.limit },
408
499
  { $limit: Number( req.body.limit ) },
409
500
  );
501
+ storesQuery.push(
502
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
503
+ { $limit: Number( req.body.limit ) },
504
+ );
505
+ }
506
+ let result;
507
+ if ( req.body.infrafilterIssue == 'Live Stores' || req.body.infrafilterIssue == 'Total Stores' ) {
508
+ result = await aggregateStore( storesQuery );
509
+ } else {
510
+ result = await aggregateTangoTicket( query );
410
511
  }
411
- let result = await aggregateTangoTicket( query );
412
512
  if ( req.body.export && result.length > 0 ) {
413
513
  const exportdata = [];
414
514
  result.forEach( ( element ) => {
@@ -440,69 +540,151 @@ export async function infraIssuesTable( req, res ) {
440
540
  }
441
541
  export async function InstallationIssuesTable( req, res ) {
442
542
  try {
443
- let query = [
444
- {
445
- $match: {
446
- $and: [
447
- { issueType: 'installation' },
448
- { 'status': { $ne: 'closed' } },
449
- { 'basicDetails.clientId': { $in: req.body.clientId } },
450
- // { createdAt: { $gte: new Date( req.body.fromDate ) } },
451
- { createdAt: { $lte: new Date( req.body.toDate ) } },
452
- ],
453
- },
543
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
544
+ let query = [];
545
+ query.push( {
546
+ $match: {
547
+ $and: [
548
+ { issueType: 'installation' },
549
+ { 'status': { $ne: 'closed' } },
550
+
551
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
552
+ { createdAt: { $lte: new Date( date.end ) } },
553
+ ],
454
554
  },
455
- {
456
- $project: {
457
- createdAt: 1,
458
- clientName: '$basicDetails.clientName',
459
- storeId: '$basicDetails.storeId',
460
- clientId: '$basicDetails.clientId',
461
- storeName: '$basicDetails.storeName',
462
- status: 1,
463
- primaryIssue: {
464
- $filter: {
465
- input: '$ticketActivity',
466
- as: 'item',
467
- cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
468
- },
555
+ } );
556
+ if ( req.body.installtionfilterIssue == 'yettoInstallStores' ) {
557
+ query.push( { $match: { 'ticketDetails.issueStatus': 'notidentified' } } );
558
+ }
559
+ if ( req.body.installtionfilterIssue == 'installFailedStores' ) {
560
+ query.push( { $match: { 'ticketDetails.issueStatus': 'identified' } } );
561
+ }
562
+ query.push( {
563
+ $project: {
564
+ createdAt: 1,
565
+ clientName: '$basicDetails.clientName',
566
+ storeId: '$basicDetails.storeId',
567
+ clientId: '$basicDetails.clientId',
568
+ storeName: '$basicDetails.storeName',
569
+ status: 1,
570
+ primaryIssue: {
571
+ $filter: {
572
+ input: '$ticketActivity',
573
+ as: 'item',
574
+ cond: { $eq: [ '$$item.actionType', 'issueUpdate' ] },
469
575
  },
470
576
  },
471
577
  },
472
- {
473
- $unwind: {
474
- path: '$primaryIssue', preserveNullAndEmptyArrays: true,
475
- },
578
+ },
579
+ {
580
+ $unwind: {
581
+ path: '$primaryIssue', preserveNullAndEmptyArrays: true,
476
582
  },
477
- {
478
- $unwind: {
479
- path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
583
+ },
584
+ {
585
+ $unwind: {
586
+ path: '$primaryIssue.reasons', preserveNullAndEmptyArrays: true,
587
+ },
588
+ },
589
+ {
590
+ $project: {
591
+ createdAt: 1,
592
+ clientName: 1,
593
+ storeId: 1,
594
+ clientId: 1,
595
+ storeName: 1,
596
+ status: 1,
597
+ primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
598
+ },
599
+ },
600
+ {
601
+ $group: {
602
+ _id: '$storeId',
603
+ createdAt: { $first: '$createdAt' },
604
+ clientName: { $first: '$clientName' },
605
+ storeId: { $first: '$storeId' },
606
+ clientId: { $first: '$clientId' },
607
+ storeName: { $first: '$storeName' },
608
+ status: { $last: '$status' },
609
+ primaryIssue: { $last: '$primaryIssue' },
610
+ },
611
+ },
612
+ );
613
+ let storesQuery = [];
614
+
615
+ if ( req.body.installtionfilterIssue == 'onboardedStores' ) {
616
+ storesQuery.push( {
617
+ $match: {
618
+ '$and': [
619
+ { 'clientId': { $in: req.body.clientId } },
620
+ { 'createdAt': { $lte: date.end } },
621
+ ],
480
622
  },
481
623
  },
482
- {
483
- $project: {
484
- createdAt: 1,
485
- clientName: 1,
486
- storeId: 1,
487
- clientId: 1,
488
- storeName: 1,
489
- status: 1,
490
- primaryIssue: { $ifNull: [ '$primaryIssue.reasons.primaryIssue', '-' ] },
624
+ );
625
+ }
626
+ if ( req.body.installtionfilterIssue == 'installedStores' ) {
627
+ storesQuery.push( {
628
+ $match: {
629
+ '$and': [
630
+ { 'clientId': { $in: req.body.clientId } },
631
+ { 'edge.firstFile': true },
632
+ { 'status': 'active' },
633
+ { 'createdAt': { $lte: date.end } },
634
+ ],
491
635
  },
492
636
  },
493
- {
494
- $group: {
495
- _id: '$storeId',
496
- createdAt: { $first: '$createdAt' },
497
- clientName: { $first: '$clientName' },
498
- storeId: { $first: '$storeId' },
499
- clientId: { $first: '$clientId' },
500
- storeName: { $first: '$storeName' },
501
- status: { $last: '$status' },
502
- primaryIssue: { $last: '$primaryIssue' },
637
+ );
638
+ }
639
+ if ( req.body.installtionfilterIssue == 'inactiveStores' ) {
640
+ storesQuery.push( {
641
+ $match: {
642
+ '$and': [
643
+ { 'clientId': { $in: req.body.clientId } },
644
+ { 'status': 'deactive' },
645
+ { 'createdAt': { $lte: date.end } },
646
+ ],
503
647
  },
504
648
  },
505
- ];
649
+ );
650
+ }
651
+ storesQuery.push( {
652
+ $lookup: {
653
+ from: 'clients',
654
+ let: { clientId: '$clientId' },
655
+ pipeline: [
656
+ {
657
+ $match: {
658
+ $expr: {
659
+ $and: [
660
+ { $eq: [ '$clientId', '$$clientId' ] },
661
+ ],
662
+ },
663
+ },
664
+
665
+ },
666
+ {
667
+ $project: {
668
+ clientName: 1,
669
+ },
670
+ },
671
+ ], as: 'client',
672
+ },
673
+ },
674
+ {
675
+ $unwind: { path: '$client', preserveNullAndEmptyArrays: true },
676
+ },
677
+ {
678
+ $project: {
679
+ clientName: '$client.clientName',
680
+ storeId: 1,
681
+ clientId: 1,
682
+ storeName: 1,
683
+ status: 1,
684
+ },
685
+ },
686
+ );
687
+
506
688
  if ( req.body.searchValue && req.body.searchValue !== '' ) {
507
689
  query.push( {
508
690
  $match: {
@@ -514,11 +696,20 @@ export async function InstallationIssuesTable( req, res ) {
514
696
  ],
515
697
  },
516
698
  } );
699
+ storesQuery.push( {
700
+ $match: {
701
+ $or: [
702
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
703
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
704
+ { clientName: { $regex: req.body.searchValue, $options: 'i' } },
705
+ ],
706
+ },
707
+ } );
517
708
  }
518
- if ( req.body.filterIssue && req.body.filterIssue != '' ) {
709
+ if ( req.body.installtionfilterIssue && req.body.installtionfilterIssue != '' && req.body.installtionfilterIssue != 'yettoInstallStores' && req.body.installtionfilterIssue != 'installFailedStores' ) {
519
710
  query.push( {
520
711
  $match: {
521
- primaryIssue: req.body.filterIssue,
712
+ primaryIssue: req.body.installtionfilterIssue,
522
713
  },
523
714
  } );
524
715
  }
@@ -526,16 +717,34 @@ export async function InstallationIssuesTable( req, res ) {
526
717
  query.push( {
527
718
  $sort: { [req.body.sortColumName]: req.body.sortBy },
528
719
  } );
720
+ storesQuery.push( {
721
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
722
+ } );
529
723
  }
530
- let count = await aggregateTangoTicket( query );
724
+ let count;
725
+ if ( req.body.installtionfilterIssue != 'onboardedStores' && req.body.installtionfilterIssue != 'installedStores' && req.body.installtionfilterIssue != 'inactiveStores' ) {
726
+ count = await aggregateTangoTicket( query );
727
+ } else {
728
+ count = await aggregateStore( storesQuery );
729
+ }
730
+
531
731
  if ( req.body.limit && req.body.offset && !req.body.export ) {
532
732
  query.push(
533
733
  { $skip: ( req.body.offset - 1 ) * req.body.limit },
534
734
  { $limit: Number( req.body.limit ) },
535
735
  );
736
+ storesQuery.push(
737
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
738
+ { $limit: Number( req.body.limit ) },
739
+ );
740
+ }
741
+ let storesList;
742
+ if ( req.body.installtionfilterIssue != 'onboardedStores' && req.body.installtionfilterIssue != 'installedStores' && req.body.installtionfilterIssue != 'inactiveStores' ) {
743
+ storesList = await aggregateTangoTicket( query );
744
+ } else {
745
+ storesList = await aggregateStore( storesQuery );
536
746
  }
537
747
 
538
- let storesList = await aggregateTangoTicket( query );
539
748
  if ( storesList.length == 0 ) {
540
749
  return res.sendError( 'no data', 204 );
541
750
  }
@@ -725,10 +934,30 @@ export async function hourWiseDownstores( req, res ) {
725
934
  if ( req.body.filterIssue == 'All Issues' ) {
726
935
  issueStatus = [ 'notidentified', 'identified' ];
727
936
  };
937
+ if ( req.body.filterIssue == 'Live Stores' ) {
938
+ issueStatus = [ 'notidentified', 'identified' ];
939
+ };
940
+
941
+ let totalstores = await aggregateStore( [ {
942
+ $match: {
943
+ '$and': [
944
+ { 'clientId': req.body.clientId },
945
+ { 'edge.firstFile': true },
946
+ { 'status': 'active' },
947
+ { 'createdAt': { $lte: new Date( req.body.toDate ) } },
948
+ ],
949
+ },
950
+ } ] );
951
+
952
+ let totalnumberstores = [];
953
+ for ( let store of totalstores ) {
954
+ totalnumberstores.push( store.storeId );
955
+ }
728
956
  let query = [ {
729
957
  $match: {
730
958
  $and: [
731
959
  { 'basicDetails.clientId': req.body.clientId },
960
+ { 'basicDetails.storeId': { $in: totalnumberstores } },
732
961
  { 'status': { $ne: 'closed' } },
733
962
  { issueType: 'infra' },
734
963
  { 'ticketDetails.issueStatus': { $in: issueStatus } },
@@ -775,6 +1004,42 @@ export async function hourWiseDownstores( req, res ) {
775
1004
  },
776
1005
  },
777
1006
  ];
1007
+ let storesQuery = [];
1008
+ if ( req.body.filterIssue == 'Total Stores' ) {
1009
+ storesQuery.push( {
1010
+ $match: {
1011
+ '$and': [
1012
+ { 'clientId': req.body.clientId },
1013
+ { 'edge.firstFile': true },
1014
+ { 'status': 'active' },
1015
+ { 'createdAt': { $lte: new Date( req.body.toDate ) } },
1016
+ ],
1017
+ },
1018
+ },
1019
+ );
1020
+ }
1021
+ if ( req.body.filterIssue == 'Live Stores' ) {
1022
+ let infrastores = await aggregateTangoTicket( query );
1023
+ let infraissueStore = [];
1024
+ for ( let store of infrastores ) {
1025
+ infraissueStore.push( store.storeId );
1026
+ }
1027
+ let result = [];
1028
+ for ( let data of totalnumberstores ) {
1029
+ if ( infraissueStore.length > 0 && !infraissueStore.includes( data ) ) {
1030
+ result.push( data );
1031
+ }
1032
+ }
1033
+ storesQuery.push(
1034
+ {
1035
+ $match: {
1036
+ '$and': [
1037
+ { 'storeId': { $in: result } },
1038
+ ],
1039
+ },
1040
+ },
1041
+ );
1042
+ }
778
1043
  if ( req.body.searchValue && req.body.searchValue !== '' ) {
779
1044
  query.push( {
780
1045
  $match: {
@@ -784,33 +1049,63 @@ export async function hourWiseDownstores( req, res ) {
784
1049
  ],
785
1050
  },
786
1051
  } );
1052
+ storesQuery.push( {
1053
+ $match: {
1054
+ $or: [
1055
+ { storeName: { $regex: req.body.searchValue, $options: 'i' } },
1056
+ { storeId: { $regex: req.body.searchValue, $options: 'i' } },
1057
+ ],
1058
+ },
1059
+ } );
787
1060
  }
788
1061
  if ( req.body.sortColumName && req.body.sortColumName != '' && req.body.sortBy && req.body.sortBy != '' ) {
789
1062
  query.push( {
790
1063
  $sort: { [req.body.sortColumName]: req.body.sortBy },
791
1064
  } );
1065
+ storesQuery.push( {
1066
+ $sort: { [req.body.sortColumName]: req.body.sortBy },
1067
+ } );
792
1068
  }
793
- if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'Identified Issues' && req.body.filterIssue != 'Issues Not Identified'&&req.body.filterIssue != 'All Issues' ) {
1069
+ if ( req.body.filterIssue && req.body.filterIssue != '' &&
1070
+ req.body.filterIssue != 'Identified Issues' &&
1071
+ req.body.filterIssue != 'Issues Not Identified' &&
1072
+ req.body.filterIssue != 'All Issues' ) {
794
1073
  query.push( {
795
1074
  $match: {
796
1075
  primaryIssue: req.body.filterIssue,
797
1076
  },
798
1077
  } );
799
1078
  }
800
- let count = await aggregateTangoTicket( query );
1079
+
1080
+ let count;
1081
+ if ( req.body.filterIssue == 'Live Stores' || req.body.filterIssue == 'Total Stores' ) {
1082
+ count = await aggregateStore( storesQuery );
1083
+ } else {
1084
+ count = await aggregateTangoTicket( query );
1085
+ }
801
1086
  if ( req.body.limit && req.body.offset && !req.body.export ) {
802
1087
  query.push(
803
1088
  { $skip: ( req.body.offset - 1 ) * req.body.limit },
804
1089
  { $limit: Number( req.body.limit ) },
805
1090
  );
1091
+ storesQuery.push(
1092
+ { $skip: ( req.body.offset - 1 ) * req.body.limit },
1093
+ { $limit: Number( req.body.limit ) },
1094
+ );
1095
+ }
1096
+ let storesList;
1097
+ if ( req.body.filterIssue == 'Live Stores' || req.body.filterIssue == 'Total Stores' ) {
1098
+ storesList = await aggregateStore( storesQuery );
1099
+ } else {
1100
+ storesList = await aggregateTangoTicket( query );
806
1101
  }
807
- let storeslist = await aggregateTangoTicket( query );
808
- if ( storeslist.length == 0 ) {
1102
+
1103
+ if ( storesList.length == 0 ) {
809
1104
  return res.sendError( 'no data', 204 );
810
1105
  }
811
1106
  let data = {};
812
1107
  let result = [];
813
- for ( const store of storeslist ) {
1108
+ for ( const store of storesList ) {
814
1109
  data.storeId = store.storeId;
815
1110
  data.storeName = store.storeName;
816
1111
  data.primaryIssue = store.primaryIssue;
@@ -904,3 +1199,245 @@ function downStoresCheck( data, inputData ) {
904
1199
  }
905
1200
  } );
906
1201
  }
1202
+ export async function ticketCountSplit( req, res ) {
1203
+ try {
1204
+ const inputData = req.body;
1205
+ let filter = [
1206
+ // { issueDate: { $gte: new Date( inputData.fromDate ) } },
1207
+ { issueDate: { $lte: new Date( inputData.toDate ) } },
1208
+ {
1209
+ 'basicDetails.clientId': { $in: inputData.clientId },
1210
+ },
1211
+ { issueType: { $in: [ 'highcount', 'lowcount' ] } },
1212
+
1213
+ ];
1214
+ if ( inputData?.issueType && inputData?.issueType?.length > 0 ) {
1215
+ filter.push( {
1216
+ issueType: { $in: inputData.issueType },
1217
+ } );
1218
+ }
1219
+ const query = [
1220
+ {
1221
+ $match: {
1222
+ $and: filter,
1223
+ },
1224
+
1225
+ },
1226
+ {
1227
+ $project: {
1228
+ open: {
1229
+ $cond: [
1230
+ {
1231
+ $eq: [ '$status', 'open' ],
1232
+ }, 1, 0,
1233
+ ],
1234
+ },
1235
+ inprogress: {
1236
+ $cond: [
1237
+ { $eq: [ '$status', 'inprogress' ] }, 1, 0,
1238
+ ],
1239
+ },
1240
+ closed: {
1241
+ $cond: [
1242
+ { $eq: [ '$status', 'closed' ] }, 1, 0,
1243
+ ],
1244
+ },
1245
+ },
1246
+ },
1247
+ {
1248
+ $group: {
1249
+ _id: null,
1250
+ total: { $sum: 1 },
1251
+ open: { $sum: '$open' },
1252
+ inprogress: { $sum: '$inprogress' },
1253
+ closed: { $sum: '$closed' },
1254
+ },
1255
+ },
1256
+ {
1257
+ $project: {
1258
+ _id: 0,
1259
+ open: { $ifNull: [ '$open', 0 ] },
1260
+ inprogress: { $ifNull: [ '$inprogress', 0 ] },
1261
+ closed: { $ifNull: [ '$closed', 0 ] },
1262
+ total: 1,
1263
+ },
1264
+ },
1265
+ ];
1266
+ const result = await aggregateTangoTicket( query );
1267
+ if ( result.length == 0 ) {
1268
+ return res.sendError( 'No Data Found', 204 );
1269
+ }
1270
+ return res.sendSuccess( { result: result[0] } );
1271
+ } catch ( error ) {
1272
+ logger.error( { error: error, function: 'ticketCountSplit' } );
1273
+ res.sendError( 'Internal Server Error', 500 );
1274
+ }
1275
+ };
1276
+ export async function overViewTable( req, res ) {
1277
+ try {
1278
+ const inputData = req.body;
1279
+ const limit = inputData.limit || 10;
1280
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
1281
+ let filter = [
1282
+ // { issueDate: { $gte: new Date( inputData.fromDate ) } },
1283
+ { issueDate: { $lte: new Date( inputData.toDate ) } },
1284
+ { issueType: { $in: [ 'highcount', 'lowcount' ] } },
1285
+ {
1286
+ 'basicDetails.clientId': { $in: inputData.clientId },
1287
+ },
1288
+
1289
+ ];
1290
+ if ( inputData?.issueType && inputData?.issueType?.length > 0 ) {
1291
+ filter.push( {
1292
+ issueType: { $in: inputData.issueType },
1293
+ } );
1294
+ }
1295
+ const query = [
1296
+ {
1297
+ $match: {
1298
+ $and: filter,
1299
+ },
1300
+
1301
+ },
1302
+ {
1303
+ $project: {
1304
+ _id: 0,
1305
+ clientName: '$basicDetails.clientName',
1306
+ storeId: '$basicDetails.storeId',
1307
+ storeName: '$basicDetails.storeName',
1308
+ issueType: 1,
1309
+ status: 1,
1310
+ clientId: '$basicDetails.clientId',
1311
+
1312
+ },
1313
+ },
1314
+ ];
1315
+ if ( inputData.searchValue ) {
1316
+ filter.push( {
1317
+
1318
+ $or: [
1319
+ { 'basicDetails.clientName': { $regex: req.body.searchValue, $options: 'i' } },
1320
+ { 'basicDetails.storeId': { $regex: req.body.searchValue, $options: 'i' } },
1321
+ { 'basicDetails.storeName': { $regex: req.body.searchValue, $options: 'i' } },
1322
+ { 'status': { $regex: req.body.searchValue, $options: 'i' } },
1323
+ ],
1324
+
1325
+ } );
1326
+ }
1327
+ if ( inputData.sortColumName ) {
1328
+ const sortBy = inputData.sortBy || -1;
1329
+ query.push( {
1330
+ $sort: {
1331
+ [inputData.sortColumName == 'storeId' ? 'basicDetails.storeId' :
1332
+ inputData.sortColumName == 'clientName' ? 'basicDetails.clientName' :
1333
+ inputData.sortColumName == 'storeName' ? 'basicDetails.storeName' : inputData.sortColumName]: sortBy,
1334
+ },
1335
+ } );
1336
+ }
1337
+
1338
+
1339
+ const count = await aggregateTangoTicket( query );
1340
+
1341
+ query.push(
1342
+ { $skip: offset },
1343
+ { $limit: limit },
1344
+ );
1345
+
1346
+ const result = await aggregateTangoTicket( query );
1347
+ if ( result.length == 0 ) {
1348
+ return res.sendError( 'No Data Found', 204 );
1349
+ }
1350
+ if ( inputData.isExport ) {
1351
+ const resultChunk = await chunkArray( count, 10 );
1352
+ const promises = resultChunk.map( async ( chunk ) => {
1353
+ const list = [];
1354
+ for ( let i = 0; i < chunk.length; i++ ) {
1355
+ list.push( {
1356
+ 'Client Name': chunk[i]?.clientName,
1357
+ 'Store ID': chunk[i]?.storeId,
1358
+ 'Store Name': chunk[i]?.storeName,
1359
+ 'Status': chunk[i]?.status,
1360
+ } );
1361
+ }
1362
+ return list;
1363
+ } );
1364
+ const temp = await Promise.all( promises );
1365
+ const exportResult = temp.flat();
1366
+ await download( exportResult, res );
1367
+ return;
1368
+ }
1369
+ return res.sendSuccess( { result: result, count: count.length } );
1370
+ } catch ( error ) {
1371
+ logger.error( { error: error, function: 'overViewTable' } );
1372
+ res.sendError( 'Internal Server Error', 500 );
1373
+ }
1374
+ };
1375
+ export async function ticketCount( req, res ) {
1376
+ try {
1377
+ const inputData = req.body;
1378
+
1379
+ let filter = [
1380
+ { issueDate: { $lte: new Date( inputData.toDate ) } },
1381
+ {
1382
+ issueType: { $in: [ 'highcount', 'lowcount' ] },
1383
+ },
1384
+
1385
+ ];
1386
+ if ( inputData.clientId && inputData?.clientId?.length > 0 ) {
1387
+ filter.push( {
1388
+ 'basicDetails.clientId': { $in: inputData.clientId },
1389
+ } );
1390
+ }
1391
+ const query = [
1392
+ {
1393
+ $match: {
1394
+ $and: filter,
1395
+ },
1396
+
1397
+ },
1398
+ {
1399
+ $project: {
1400
+ high: {
1401
+ $cond: [
1402
+ {
1403
+ $eq: [ '$issueType', 'highcount' ],
1404
+ }, 1, 0,
1405
+ ],
1406
+ },
1407
+ low: {
1408
+ $cond: [
1409
+ { $eq: [ '$issueType', 'lowcount' ] }, 1, 0,
1410
+ ],
1411
+ },
1412
+ },
1413
+ },
1414
+ {
1415
+ $group: {
1416
+ _id: null,
1417
+ highCount: { $sum: '$high' },
1418
+ LowCount: { $sum: '$low' },
1419
+ total: { $sum: 1 },
1420
+
1421
+ },
1422
+ },
1423
+ {
1424
+ $project: {
1425
+ _id: 0,
1426
+ highCount: 1,
1427
+ LowCount: 1,
1428
+ total: 1,
1429
+ },
1430
+ },
1431
+
1432
+ ];
1433
+
1434
+ const result = await aggregateTangoTicket( query );
1435
+ if ( result.length == 0 ) {
1436
+ return res.sendError( 'No Data Found', 204 );
1437
+ }
1438
+ return res.sendSuccess( { result: result[0] } );
1439
+ } catch ( error ) {
1440
+ logger.error( { error: error, function: 'ticketCount' } );
1441
+ res.sendError( 'Internal Server Error', 500 );
1442
+ }
1443
+ };
@@ -921,7 +921,59 @@ function inWords( num ) {
921
921
 
922
922
  return str.toLowerCase().split( ' ' ).map( ( word ) => word.charAt( 0 ).toUpperCase() + word.slice( 1 ) ).join( ' ' );
923
923
  }
924
+ export async function allCounts( req, res ) {
925
+ try {
926
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
927
+ let countQuery=[
928
+ {
929
+ $match: {
930
+ $and: [
931
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
932
+ { createdAt: { $gte: date.start } },
933
+ { createdAt: { $lte: date.end } },
934
+ ],
935
+ },
936
+ },
937
+ {
938
+ $project: {
939
+ issueType: 1,
940
+ installationCount: {
941
+ $cond: [ { $and: [ { $eq: [ '$issueType', 'installation' ] } ] }, 1, 0,
942
+ ],
943
+ },
944
+ infraCount: {
945
+ $cond: [ { $and: [ { $eq: [ '$issueType', 'infra' ] } ] }, 1, 0,
946
+ ],
947
+ },
948
+ datamismatchCount: {
949
+ $cond: [ { $or: [ { $eq: [ '$issueType', 'highcount' ] }, { $eq: [ '$issueType', 'lowcount' ] } ] }, 1, 0,
950
+ ],
951
+ },
952
+ matCount: {
953
+ $cond: [ { $and: [ { $eq: [ '$issueType', 'mat' ] } ] }, 1, 0,
954
+ ],
955
+ },
956
+ },
957
+ },
958
+ {
959
+ $group: {
960
+ _id: null,
961
+ installationCount: { $sum: '$installationCount' },
962
+ infraCount: { $sum: '$infraCount' },
963
+ datamismatchCount: { $sum: '$datamismatchCount' },
964
+ matCount: { $sum: '$matCount' },
965
+
924
966
 
967
+ },
968
+ },
969
+ ];
970
+ let result = await aggregateTangoTicket( countQuery );
971
+ res.sendSuccess( result );
972
+ } catch ( error ) {
973
+ logger.error( { error: error, function: 'allCounts' } );
974
+ return res.sendError( error, 500 );
975
+ }
976
+ }
925
977
 
926
978
  export async function infraTable( req, res ) {
927
979
  try {
@@ -293,7 +293,6 @@ export async function edgeAppLogTable( req, res ) {
293
293
  for ( const obj of timeSlots ) {
294
294
  obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
295
295
  obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
296
-
297
296
  let internetSpeedQuery = {
298
297
  'size': 1,
299
298
  'query': {
@@ -306,7 +305,7 @@ export async function edgeAppLogTable( req, res ) {
306
305
  },
307
306
  {
308
307
  'term': {
309
- 'store_id.keyword': req.body.storeId,
308
+ 'storeId.keyword': req.body.storeId,
310
309
  },
311
310
  },
312
311
  {
@@ -331,9 +330,9 @@ export async function edgeAppLogTable( req, res ) {
331
330
  ],
332
331
  };
333
332
  let speedTest = await getOpenSearchData( 'edgeapp_systemlogs', internetSpeedQuery );
334
-
335
333
  if ( speedTest.body.hits && speedTest.body.hits.hits.length > 0 && speedTest.body.hits.hits[0]._source ) {
336
- obj.Internetspeed = speedTest.body.hits.hits[0]._source.data.upload_Speed;
334
+ const megabytes = bytesToMB( speedTest.body.hits.hits[0]._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 );
335
+ obj.Internetspeed = megabytes+ ' MB/sec';
337
336
  } else {
338
337
  obj.Internetspeed = '';
339
338
  }
@@ -420,7 +419,7 @@ export async function edgeAppLogTable( req, res ) {
420
419
  },
421
420
  {
422
421
  'term': {
423
- 'store_id.keyword': req.body.storeId,
422
+ 'storeId.keyword': req.body.storeId,
424
423
  },
425
424
  },
426
425
  {
@@ -457,6 +456,9 @@ export async function edgeAppLogTable( req, res ) {
457
456
  return res.sendError( error, 500 );
458
457
  }
459
458
  }
459
+ function bytesToMB( bytes ) {
460
+ return bytes / ( 1024 * 1024 );
461
+ }
460
462
  function generateTimeSlots( startHour, endHour, interval, req ) {
461
463
  try {
462
464
  const timeSlots = [];
@@ -511,7 +513,7 @@ export async function viewedgeAppLog( req, res ) {
511
513
  },
512
514
  {
513
515
  'term': {
514
- 'store_id.keyword': req.body.storeId,
516
+ 'storeId.keyword': req.body.storeId,
515
517
  },
516
518
  },
517
519
  {
@@ -572,6 +574,7 @@ export async function viewedgeAppLog( req, res ) {
572
574
  ],
573
575
  };
574
576
  const appQuitTime = await getOpenSearchData( 'edgeapp_systemlogs', appQuitTimeQuery );
577
+
575
578
  let appCrashTimeQuery = {
576
579
  'size': 1,
577
580
  'query': {
@@ -621,7 +624,7 @@ export async function viewedgeAppLog( req, res ) {
621
624
  },
622
625
  {
623
626
  'term': {
624
- 'store_id.keyword': req.body.storeId,
627
+ 'storeId.keyword': req.body.storeId,
625
628
  },
626
629
  },
627
630
  {
@@ -724,7 +727,7 @@ export async function viewedgeAppLog( req, res ) {
724
727
  },
725
728
  {
726
729
  'term': {
727
- 'store_id.keyword': req.body.storeId,
730
+ 'storeId.keyword': req.body.storeId,
728
731
  },
729
732
  },
730
733
  {
@@ -995,7 +998,6 @@ export async function streamwiseDowntime( req, res ) {
995
998
 
996
999
  let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
997
1000
  if ( streamwiseDowntime.length > 0 ) {
998
- console.log( streamwiseDowntime );
999
1001
  for ( let stream of streamwiseDowntime ) {
1000
1002
  if ( stream.stream === req.body.stream ) {
1001
1003
  obj.downTime= stream.down_time;
@@ -753,3 +753,55 @@ export async function storeInfraList( req, res ) {
753
753
  return res.sendError( error, 500 );
754
754
  }
755
755
  }
756
+ export async function pendingTicket( req, res ) {
757
+ try {
758
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
759
+ let countQuery=[
760
+ {
761
+ $match: {
762
+ $and: [
763
+ { 'basicDetails.clientId': { $in: req.body.clientId } },
764
+ { createdAt: { $lte: date.end } },
765
+ ],
766
+ },
767
+ },
768
+ {
769
+ $project: {
770
+ issueType: 1,
771
+ installationCount: {
772
+ $cond: [ { $and: [ { $eq: [ '$issueType', 'installation' ] }, { $ne: [ '$status', 'closed' ] }, { $eq: [ '$ticketDetails.issueStatus', 'notidentified' ] } ] }, 1, 0,
773
+ ],
774
+ },
775
+ infraCount: {
776
+ $cond: [ { $and: [ { $eq: [ '$issueType', 'infra' ] }, { $ne: [ '$status', 'closed' ] }, { $eq: [ '$ticketDetails.issueStatus', 'notidentified' ] } ] }, 1, 0,
777
+ ],
778
+ },
779
+ datamismatchCount: {
780
+ $cond: [ { $and: [ { $or: [ { $eq: [ '$issueType', 'highcount' ] }, { $eq: [ '$issueType', 'lowcount' ] } ] }, { $eq: [ '$status', 'closed' ] } ] }, 1, 0,
781
+ ],
782
+ },
783
+ matCount: {
784
+ $cond: [ { $and: [ { $eq: [ '$issueType', 'mat' ] }, { $eq: [ '$status', 'open' ] } ] }, 1, 0,
785
+ ],
786
+ },
787
+ },
788
+ },
789
+ {
790
+ $group: {
791
+ _id: null,
792
+ installationCount: { $sum: '$installationCount' },
793
+ infraCount: { $sum: '$infraCount' },
794
+ datamismatchCount: { $sum: '$datamismatchCount' },
795
+ matCount: { $sum: '$matCount' },
796
+
797
+
798
+ },
799
+ },
800
+ ];
801
+ let result = await aggregateTangoTicket( countQuery );
802
+ res.sendSuccess( result );
803
+ } catch ( error ) {
804
+ logger.error( { error: error, function: 'pendingTicket' } );
805
+ return res.sendError( error, 500 );
806
+ }
807
+ }
@@ -1,7 +1,7 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
4
- import { infraCard, installationCard, InstallationIssuesTable, infraIssuesTable, hourWiseDownClients, hourWiseDownstores } from '../controllers/clientInfra.controller.js';
4
+ import { infraCard, installationCard, InstallationIssuesTable, infraIssuesTable, hourWiseDownClients, hourWiseDownstores, ticketCountSplit, overViewTable, ticketCount } from '../controllers/clientInfra.controller.js';
5
5
 
6
6
  export const clientInfraRouter = express.Router();
7
7
 
@@ -31,4 +31,15 @@ clientInfraRouter.post( '/hourWiseDownstores', isAllowedSessionHandler, authoriz
31
31
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
32
32
  } ), hourWiseDownstores );
33
33
 
34
-
34
+ clientInfraRouter.post( '/ticket-count', isAllowedSessionHandler, authorize( {
35
+ userType: [ 'client', 'tango' ], access: [
36
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
37
+ } ), ticketCount );
38
+ clientInfraRouter.post( '/ticket-count-split', isAllowedSessionHandler, authorize( {
39
+ userType: [ 'client', 'tango' ], access: [
40
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
41
+ } ), ticketCountSplit );
42
+ clientInfraRouter.post( '/overview-table', isAllowedSessionHandler, authorize( {
43
+ userType: [ 'client', 'tango' ], access: [
44
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
45
+ } ), overViewTable );
@@ -4,7 +4,7 @@ import { isAllowedSessionHandler, authorize, validate } from 'tango-app-api-midd
4
4
  import { validateDetails, bulkvalidateDetails, validateTicket, bulkvalidateTicket, validateTicketstatus, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
5
  import { createTicket, bulkcreateTicket, updateStatus, createReason, PrimaryReasons, matTable, removeAttachment,
6
6
  secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments, getInfraIssues,
7
- updateInstallationTicket, emailUserList, saveInfraEmailConfig, invoice, infraTable, storeFilter, assignTicket, installationTable } from '../controllers/infra.controllers.js';
7
+ updateInstallationTicket, emailUserList, saveInfraEmailConfig, invoice, allCounts, infraTable, storeFilter, assignTicket, installationTable } from '../controllers/infra.controllers.js';
8
8
  import { getInfraIssueValid } from '../dtos/infra.dtos.js';
9
9
 
10
10
 
@@ -60,6 +60,10 @@ infraRouter.post( '/saveInfraEmailConfig', isAllowedSessionHandler, authorize( {
60
60
  { featureName: 'settings', name: 'configuration', permissions: [ 'isEdit', 'isView' ] } ],
61
61
  } ), saveInfraEmailConfig );
62
62
  infraRouter.post( '/invoice', invoice );
63
+ infraRouter.post( '/allCounts', isAllowedSessionHandler, authorize( {
64
+ userType: [ 'client', 'tango' ], access: [
65
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
66
+ } ), allCounts );
63
67
  infraRouter.post( '/infraTable', isAllowedSessionHandler, authorize( {
64
68
  userType: [ 'client', 'tango' ], access: [
65
69
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
@@ -1,6 +1,6 @@
1
1
  import express from 'express';
2
2
  import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
3
- import { userTakeTicket, userTicketList, activeTicketList, basicDetails, workHistory, storeInfraList } from '../controllers/userInfra.controller.js';
3
+ import { userTakeTicket, userTicketList, activeTicketList, basicDetails, workHistory, pendingTicket, storeInfraList } from '../controllers/userInfra.controller.js';
4
4
 
5
5
  export const userInfraRouter = express.Router();
6
6
 
@@ -30,5 +30,9 @@ userInfraRouter.post( '/storeInfraList', isAllowedSessionHandler, authorize( {
30
30
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] },
31
31
  ],
32
32
  } ), storeInfraList );
33
-
33
+ userInfraRouter.post( '/pendingTicket', isAllowedSessionHandler, authorize( {
34
+ userType: [ 'tango', 'client' ], access: [
35
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] },
36
+ ],
37
+ } ), pendingTicket );
34
38