tango-app-api-infra 3.0.92-dev → 3.0.94-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.
@@ -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
  {
@@ -185,7 +204,7 @@ export async function installationCard( req, res ) {
185
204
  { 'status': { $ne: 'closed' } },
186
205
  { 'ticketDetails.issueStatus': 'notidentified' },
187
206
  { 'basicDetails.clientId': { $in: req.body.clientId } },
188
- { createdAt: { $lte: new Date( req.body.toDate ) } },
207
+ { createdAt: { $lte: date.end } },
189
208
  ],
190
209
  },
191
210
  },
@@ -197,7 +216,7 @@ export async function installationCard( req, res ) {
197
216
  { 'status': { $ne: 'closed' } },
198
217
  { 'basicDetails.clientId': { $in: req.body.clientId } },
199
218
  { 'ticketDetails.issueStatus': 'identified' },
200
- { createdAt: { $lte: new Date( req.body.toDate ) } },
219
+ { createdAt: { $lte: date.end } },
201
220
  ],
202
221
  },
203
222
  },
@@ -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: 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
+ };