tango-app-api-infra 3.3.0-alpha.1 → 3.3.3-beta.1

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/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # README #
2
-
3
- This README would normally document whatever steps are necessary to get your application up and running.
4
-
5
- ### What is this repository for? ###
6
-
7
- * Quick summary
8
- * Version
9
- * [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
10
-
11
- ### How do I get set up? ###
12
-
13
- * Summary of set up
14
- * Configuration
15
- * Dependencies
16
- * Database configuration
17
- * How to run tests
18
- * Deployment instructions
19
-
20
- ### Contribution guidelines ###
21
-
22
- * Writing tests
23
- * Code review
24
- * Other guidelines
25
-
26
- ### Who do I talk to? ###
27
-
28
- * Repo owner or admin
1
+ # README #
2
+
3
+ This README would normally document whatever steps are necessary to get your application up and running.
4
+
5
+ ### What is this repository for? ###
6
+
7
+ * Quick summary
8
+ * Version
9
+ * [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
10
+
11
+ ### How do I get set up? ###
12
+
13
+ * Summary of set up
14
+ * Configuration
15
+ * Dependencies
16
+ * Database configuration
17
+ * How to run tests
18
+ * Deployment instructions
19
+
20
+ ### Contribution guidelines ###
21
+
22
+ * Writing tests
23
+ * Code review
24
+ * Other guidelines
25
+
26
+ ### Who do I talk to? ###
27
+
28
+ * Repo owner or admin
29
29
  * Other community or team contact
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "tango-app-api-infra",
3
- "version": "3.3.0-alpha.1",
4
- "description": "infra",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "start": "nodemon --exec \"eslint --fix . && node index.js\""
9
- },
10
- "engines": {
11
- "node": ">=18.10.0"
12
- },
13
- "author": "praveenraj",
14
- "license": "ISC",
15
- "dependencies": {
16
- "aws-sdk": "^2.1571.0",
17
- "cors": "^2.8.5",
18
- "dayjs": "^1.11.10",
19
- "dotenv": "^16.4.5",
20
- "excel4node": "^1.8.2",
21
- "express": "^4.18.3",
22
- "express-fileupload": "^1.5.0",
23
- "handlebars": "^4.7.8",
24
- "html-pdf-node": "^1.0.8",
25
- "joi-to-swagger": "^6.2.0",
26
- "mongodb": "^6.4.0",
27
- "nodemon": "^3.1.0",
28
- "swagger-ui-express": "^5.0.0",
29
- "tango-api-schema": "^2.0.115",
30
- "tango-app-api-middleware": "^3.1.26",
31
- "winston": "^3.12.0",
32
- "winston-daily-rotate-file": "^5.0.0"
33
- },
34
- "devDependencies": {
35
- "eslint": "^8.57.0",
36
- "eslint-config-google": "^0.14.0",
37
- "eslint-config-semistandard": "^17.0.0",
38
- "eslint-config-standard": "^17.1.0",
39
- "eslint-plugin-import": "^2.29.1",
40
- "eslint-plugin-promise": "^6.1.1"
41
- }
42
- }
1
+ {
2
+ "name": "tango-app-api-infra",
3
+ "version": "3.3.3-beta.1",
4
+ "description": "infra",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "start": "nodemon --exec \"eslint --fix . && node index.js\""
9
+ },
10
+ "engines": {
11
+ "node": ">=18.10.0"
12
+ },
13
+ "author": "praveenraj",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "aws-sdk": "^2.1571.0",
17
+ "cors": "^2.8.5",
18
+ "dayjs": "^1.11.10",
19
+ "dotenv": "^16.4.5",
20
+ "excel4node": "^1.8.2",
21
+ "express": "^4.18.3",
22
+ "express-fileupload": "^1.5.0",
23
+ "handlebars": "^4.7.8",
24
+ "html-pdf-node": "^1.0.8",
25
+ "joi-to-swagger": "^6.2.0",
26
+ "mongodb": "^6.4.0",
27
+ "nodemon": "^3.1.0",
28
+ "swagger-ui-express": "^5.0.0",
29
+ "tango-api-schema": "^2.2.29",
30
+ "tango-app-api-middleware": "^3.1.50",
31
+ "winston": "^3.12.0",
32
+ "winston-daily-rotate-file": "^5.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "eslint": "^8.57.0",
36
+ "eslint-config-google": "^0.14.0",
37
+ "eslint-config-semistandard": "^17.0.0",
38
+ "eslint-config-standard": "^17.1.0",
39
+ "eslint-plugin-import": "^2.29.1",
40
+ "eslint-plugin-promise": "^6.1.1"
41
+ }
42
+ }
@@ -1,5 +1,5 @@
1
1
 
2
- import { aggregateStore, countDocumentsStore } from '../services/store.service.js';
2
+ import { aggregateStore, countDocumentsStore, findStore } 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';
@@ -7,16 +7,24 @@ import { aggregateClient, findClient } from '../services/client.service.js';
7
7
  import dayjs from 'dayjs';
8
8
  import { getOpenSearchData } from 'tango-app-api-middleware';
9
9
  import { aggregateUserAssignedStore, findUserAssignedStore } from '../services/userAssignedStore.service.js';
10
+ import { countDocumentsUser } from '../services/user.service.js';
11
+ import { countDocumentsTeams } from '../services/teams.service.js';
12
+ import { countDocumentsClusters } from '../services/cluster.service.js';
10
13
 
11
14
 
12
15
  export async function infraCard( req, res ) {
13
16
  try {
14
17
  let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
15
18
  let storecountQuery ={ 'clientId': { $in: req.body.clientId }, 'createdAt': { $lte: date.end }, 'status': 'active' };
16
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
17
- storecountQuery = { ...storecountQuery, ...{ storeId: { $in: req.body.permittedStores } } };
19
+
20
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
21
+ storecountQuery = { ...storecountQuery, ...{ storeId: { $in: req.body.assignedStores } } };
18
22
  }
23
+
19
24
  let storeCount = await countDocumentsStore( storecountQuery );
25
+ let stores = await findStore( { 'clientId': { $in: req.body.clientId }, 'status': 'active' } );
26
+ let storelist = stores.map( ( data ) => data.storeId );
27
+
20
28
  let yetToInstallQuery = [
21
29
  {
22
30
  $match: {
@@ -24,17 +32,18 @@ export async function infraCard( req, res ) {
24
32
  { issueType: 'installation' },
25
33
  { 'status': { $ne: 'closed' } },
26
34
  { 'basicDetails.clientId': { $in: req.body.clientId } },
35
+ { 'basicDetails.storeId': { $in: storelist } },
27
36
  { createdAt: { $lte: date.end } },
28
37
  ],
29
38
  },
30
39
  },
31
40
  ];
32
41
 
33
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
42
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
34
43
  yetToInstallQuery.push(
35
44
  {
36
45
  $match: {
37
- 'basicDetails.storeId': { $in: req.body.permittedStores },
46
+ 'basicDetails.storeId': { $in: req.body.assignedStores },
38
47
  },
39
48
  },
40
49
  );
@@ -50,11 +59,11 @@ export async function infraCard( req, res ) {
50
59
  ],
51
60
  },
52
61
  } ];
53
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
62
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
54
63
  totalStoreQuery.push(
55
64
  {
56
65
  $match: {
57
- 'storeId': { $in: req.body.permittedStores },
66
+ 'storeId': { $in: req.body.assignedStores },
58
67
  },
59
68
  },
60
69
  );
@@ -82,6 +91,9 @@ export async function infraCard( req, res ) {
82
91
  identifiedcount: {
83
92
  $cond: [ { $eq: [ '$ticketDetails.issueStatus', 'identified' ] }, 1, 0 ],
84
93
  },
94
+ notidentifiedcount: {
95
+ $cond: [ { $eq: [ '$ticketDetails.issueStatus', 'notidentified' ] }, 1, 0 ],
96
+ },
85
97
  },
86
98
  },
87
99
  {
@@ -89,6 +101,8 @@ export async function infraCard( req, res ) {
89
101
  _id: '$storeId',
90
102
  infraCount: { $sum: 1 },
91
103
  identifiedcount: { $sum: '$identifiedcount' },
104
+ notidentifiedcount: { $sum: '$notidentifiedcount' },
105
+
92
106
  },
93
107
  },
94
108
  {
@@ -96,6 +110,8 @@ export async function infraCard( req, res ) {
96
110
  _id: null,
97
111
  infraCount: { $sum: '$infraCount' },
98
112
  identifiedcount: { $sum: '$identifiedcount' },
113
+ notidentifiedcount: { $sum: '$notidentifiedcount' },
114
+
99
115
  },
100
116
  },
101
117
  ] );
@@ -190,22 +206,22 @@ export async function infraCard( req, res ) {
190
206
 
191
207
  response.unshift( {
192
208
  name: 'Identified Issues',
193
- count: infraStoreCount.length > 0 ? infraStoreCount[0].identifiedcount : 0,
209
+ count: ticketList.length,
194
210
  } );
195
211
  response.unshift( {
196
212
  name: 'All Issues',
197
- count: infraStoreCount.length > 0 ? infraStoreCount[0].infraCount : 0,
213
+ count: infraStoreCount.length > 0 ? req.body.filter && req.body.filter.length > 0?ticketList.length:( infraStoreCount[0].notidentifiedcount+ticketList.length ): 0,
198
214
  } );
199
215
  response.push( {
200
216
  name: 'Issues Not Identified',
201
- count: infraStoreCount.length > 0 ? infraStoreCount[0].infraCount - infraStoreCount[0].identifiedcount : 0,
217
+ count: infraStoreCount.length > 0 ?( req.body.filter && req.body.filter.length > 0 )?0: infraStoreCount[0].notidentifiedcount : 0,
202
218
  } );
203
219
  res.sendSuccess( {
204
220
  total: storeCount,
205
221
  liveStoreCount: infraStoreCount.length > 0 ? storeCount - infraStoreCount[0].infraCount : storeCount,
206
- infraStoreCount: infraStoreCount.length > 0 ? infraStoreCount[0].infraCount : 0,
207
- identifiedcount: infraStoreCount.length > 0 ? infraStoreCount[0].identifiedcount : 0,
208
- notidentifiedcount: infraStoreCount.length > 0 ? infraStoreCount[0].infraCount - infraStoreCount[0].identifiedcount : 0,
222
+ infraStoreCount: infraStoreCount.length > 0 ? infraStoreCount[0].notidentifiedcount+ticketList.length : 0,
223
+ identifiedcount: infraStoreCount.length > 0 ? ticketList.length : 0,
224
+ notidentifiedcount: infraStoreCount.length > 0 ?( req.body.filter && req.body.filter.length > 0 )?0: infraStoreCount[0].notidentifiedcount : 0,
209
225
  infraIssues: response,
210
226
  } );
211
227
  } catch ( error ) {
@@ -220,8 +236,10 @@ export async function installationCard( req, res ) {
220
236
  clientId: { $in: req.body.clientId },
221
237
  createdAt: { $lte: date.end },
222
238
  };
223
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
224
- baseQuery = { ...baseQuery, ...{ storeId: { $in: req.body.permittedStores } } };
239
+
240
+
241
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
242
+ baseQuery = { ...baseQuery, ...{ storeId: { $in: req.body.assignedStores } } };
225
243
  }
226
244
  let onboardQuery = { ...baseQuery };
227
245
  let installedQuery = { ...baseQuery, status: 'active' };
@@ -229,6 +247,8 @@ export async function installationCard( req, res ) {
229
247
  let onboardedCount = await countDocumentsStore( onboardQuery );
230
248
  let installedCount = await countDocumentsStore( installedQuery );
231
249
  let deactiveCount = await countDocumentsStore( deactiveQuery );
250
+ let stores = await findStore( { 'clientId': { $in: req.body.clientId }, 'status': 'active' } );
251
+ let storelist = stores.map( ( data ) => data.storeId );
232
252
 
233
253
 
234
254
  let ticketbaseQuery = [
@@ -238,16 +258,17 @@ export async function installationCard( req, res ) {
238
258
  { issueType: 'installation' },
239
259
  { 'status': { $ne: 'closed' } },
240
260
  { 'basicDetails.clientId': { $in: req.body.clientId } },
261
+ { 'basicDetails.storeId': { $in: storelist } },
241
262
  { createdAt: { $lte: date.end } },
242
263
  ],
243
264
  },
244
265
  },
245
266
  ];
246
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
267
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
247
268
  ticketbaseQuery.push(
248
269
  {
249
270
  $match: {
250
- 'basicDetails.storeId': { $in: req.body.permittedStores },
271
+ 'basicDetails.storeId': { $in: req.body.assignedStores },
251
272
  },
252
273
  },
253
274
  );
@@ -360,11 +381,11 @@ export async function infraIssuesTable( req, res ) {
360
381
  ],
361
382
  },
362
383
  } ];
363
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
384
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
364
385
  totalStoreQuery.push(
365
386
  {
366
387
  $match: {
367
- 'storeId': { $in: req.body.permittedStores },
388
+ 'storeId': { $in: req.body.assignedStores },
368
389
  },
369
390
  },
370
391
  );
@@ -385,11 +406,11 @@ export async function infraIssuesTable( req, res ) {
385
406
  ],
386
407
  },
387
408
  } );
388
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
409
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
389
410
  pendingquery.push(
390
411
  {
391
412
  $match: {
392
- 'basicDetails.storeId': { $in: req.body.permittedStores },
413
+ 'basicDetails.storeId': { $in: req.body.assignedStores },
393
414
  },
394
415
  },
395
416
  );
@@ -457,7 +478,7 @@ export async function infraIssuesTable( req, res ) {
457
478
  createdAt: 1,
458
479
  ticketId: 1,
459
480
  clientName: 1,
460
- actionBy: '$primaryIssue.actionBy',
481
+ issueIdentifiedBy: { $ifNull: [ '$primaryIssue.actionBy', '' ] },
461
482
  issueIdentifiedDate: { $ifNull: [ '$issueIdentifiedDate', '' ] },
462
483
  issueClosedDate: { $ifNull: [ '$issueClosedDate', '' ] },
463
484
  status: 1,
@@ -471,7 +492,7 @@ export async function infraIssuesTable( req, res ) {
471
492
  storeId: { $first: '$storeId' },
472
493
  clientId: { $first: '$clientId' },
473
494
  ticketId: { $first: '$ticketId' },
474
- actionBy: { $first: '$actionBy' },
495
+ issueIdentifiedBy: { $first: '$issueIdentifiedBy' },
475
496
  storeName: { $first: '$storeName' },
476
497
  clientName: { $first: '$clientName' },
477
498
  createdAt: { $first: '$createdAt' },
@@ -531,11 +552,11 @@ export async function infraIssuesTable( req, res ) {
531
552
  } ];
532
553
  }
533
554
  }
534
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
555
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
535
556
  storesQuery.push(
536
557
  {
537
558
  $match: {
538
- 'storeId': { $in: req.body.permittedStores },
559
+ 'storeId': { $in: req.body.assignedStores },
539
560
  },
540
561
  },
541
562
  );
@@ -563,15 +584,18 @@ export async function infraIssuesTable( req, res ) {
563
584
  storesQuery.push( searchCondition );
564
585
  }
565
586
 
587
+
566
588
  if ( req.body.filter && req.body.filter.length > 0 ) {
589
+ // req.body.filter.push( '' );
567
590
  query.push(
568
591
  {
569
592
  $match: {
570
- actionBy: { $in: req.body.filter },
593
+ issueIdentifiedBy: { $in: req.body.filter },
571
594
  },
572
595
  },
573
596
  );
574
597
  }
598
+
575
599
  if ( req.body.sortColumName && req.body.sortColumName !== '' && req.body.sortBy ) {
576
600
  const sortOption = { $sort: { [req.body.sortColumName]: req.body.sortBy } };
577
601
  query.push( sortOption );
@@ -648,19 +672,19 @@ export async function infraIssuesTable( req, res ) {
648
672
  const exportdata = result.map( ( element ) => {
649
673
  if ( req.body.infrafilterIssue === 'Live Stores' || req.body.infrafilterIssue === 'Total Stores' ) {
650
674
  return {
651
- 'Created On': element.createdAt,
675
+ 'Created On': dayjs( element.createdAt ).format( 'DD MMM, YYYY' ),
652
676
  'StoreID': element.storeId,
653
677
  'StoreName': element.storeName,
654
678
  'Status': element.status,
655
679
  };
656
680
  } else {
657
681
  return {
658
- 'Created On': element.createdAt,
682
+ 'Created On': dayjs( element.createdAt ).format( 'DD MMM, YYYY' ),
659
683
  'StoreID': element.storeId,
660
684
  'StoreName': element.storeName,
661
685
  'Primary Issue': element.primaryIssue,
662
686
  'Sub Issue': element.secondaryIssue,
663
- 'Issue Identified on': element.issueIdentifiedDate ? dayjs( element.issueIdentifiedDate ).tz( 'Asia/Kolkata' ).format( 'YYYY-MM-DD HH:mm A' ) : '',
687
+ 'Issue Identified on': element.issueIdentifiedDate ? dayjs( element.issueIdentifiedDate ).format( 'DD MMM, YYYY' ) : '',
664
688
  'Status': element.status,
665
689
  };
666
690
  }
@@ -696,16 +720,20 @@ export async function InstallationIssuesTable( req, res ) {
696
720
  ],
697
721
  },
698
722
  } );
699
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
723
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
700
724
  query.push(
701
725
  {
702
726
  $match: {
703
- 'basicDetails.storeId': { $in: req.body.permittedStores },
727
+ 'basicDetails.storeId': { $in: req.body.assignedStores },
704
728
  },
705
729
  },
706
730
  );
707
731
  }
708
732
  if ( req.body.installtionfilterIssue == 'yettoInstallStores' ) {
733
+ let stores = await findStore( { 'clientId': { $in: req.body.clientId }, 'status': 'active' } );
734
+ let storelist = stores.map( ( data ) => data.storeId );
735
+ query.push( { $match: { 'basicDetails.storeId': { $in: storelist } } } );
736
+
709
737
  query.push( { $match: { 'ticketDetails.issueStatus': 'notidentified' } } );
710
738
  }
711
739
  if ( req.body.installtionfilterIssue == 'installationFailedStores' ) {
@@ -764,11 +792,11 @@ export async function InstallationIssuesTable( req, res ) {
764
792
  },
765
793
  );
766
794
  let storesQuery = [];
767
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
795
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
768
796
  storesQuery.push(
769
797
  {
770
798
  $match: {
771
- 'storeId': { $in: req.body.permittedStores },
799
+ 'storeId': { $in: req.body.assignedStores },
772
800
  },
773
801
  },
774
802
  );
@@ -847,6 +875,7 @@ export async function InstallationIssuesTable( req, res ) {
847
875
  clientId: 1,
848
876
  storeName: 1,
849
877
  status: 1,
878
+ firstFileDate: { $ifNull: [ '$edge.firstFileDate', '' ] },
850
879
  },
851
880
  },
852
881
  );
@@ -916,16 +945,30 @@ export async function InstallationIssuesTable( req, res ) {
916
945
  }
917
946
  if ( req.body.export ) {
918
947
  const exportdata = [];
919
- storesList.forEach( ( element ) => {
920
- exportdata.push( {
921
- 'Brand Name': element.clientName,
922
- 'Store ID': element.storeId,
923
- 'Store Name': element.storeName,
924
- 'Status': element.status,
948
+ if ( req.body.installtionfilterIssue != 'installedStores' ) {
949
+ storesList.forEach( ( element ) => {
950
+ exportdata.push( {
951
+ 'Brand Name': element.clientName,
952
+ 'Store ID': element.storeId,
953
+ 'Store Name': element.storeName,
954
+ 'Status': element.status,
955
+ } );
925
956
  } );
926
- } );
927
- await download( exportdata, res );
928
- return;
957
+ await download( exportdata, res );
958
+ return;
959
+ } else if ( req.body.installtionfilterIssue == 'installedStores' ) {
960
+ storesList.forEach( ( element ) => {
961
+ exportdata.push( {
962
+ 'Brand Name': element.clientName,
963
+ 'Store ID': element.storeId,
964
+ 'Store Name': element.storeName,
965
+ 'DeployedDate': element.firstFileDate ? dayjs( element.firstFileDate ).format( 'DD MMM, YYYY' ) : '',
966
+ 'Status': element.status,
967
+ } );
968
+ } );
969
+ await download( exportdata, res );
970
+ return;
971
+ }
929
972
  }
930
973
  res.sendSuccess( {
931
974
  count: count.length,
@@ -1111,11 +1154,11 @@ export async function hourWiseDownstores( req, res ) {
1111
1154
  ],
1112
1155
  },
1113
1156
  } ];
1114
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
1157
+ if ( req.user&&req.user.userType ==='client' &&req.user.role!='superadmin' ) {
1115
1158
  totalStoreQuery.push(
1116
1159
  {
1117
1160
  $match: {
1118
- 'storeId': { $in: req.body.permittedStores },
1161
+ 'storeId': { $in: req.body.assignedStores },
1119
1162
  },
1120
1163
  },
1121
1164
  );
@@ -1136,11 +1179,11 @@ export async function hourWiseDownstores( req, res ) {
1136
1179
  ],
1137
1180
  },
1138
1181
  } );
1139
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
1182
+ if ( req.user&&req.user.userType ==='client' &&req.user.role!='superadmin' ) {
1140
1183
  pendingquery.push(
1141
1184
  {
1142
1185
  $match: {
1143
- 'basicDetails.storeId': { $in: req.body.permittedStores },
1186
+ 'basicDetails.storeId': { $in: req.body.assignedStores },
1144
1187
  },
1145
1188
  },
1146
1189
  );
@@ -1208,7 +1251,7 @@ export async function hourWiseDownstores( req, res ) {
1208
1251
  createdAt: 1,
1209
1252
  ticketId: 1,
1210
1253
  clientName: 1,
1211
- actionBy: '$primaryIssue.actionBy',
1254
+ issueIdentifiedBy: { $ifNull: [ '$primaryIssue.actionBy', '' ] },
1212
1255
  issueIdentifiedDate: { $ifNull: [ '$issueIdentifiedDate', '' ] },
1213
1256
  issueClosedDate: { $ifNull: [ '$issueClosedDate', '' ] },
1214
1257
  status: 1,
@@ -1222,7 +1265,7 @@ export async function hourWiseDownstores( req, res ) {
1222
1265
  storeId: { $first: '$storeId' },
1223
1266
  clientId: { $first: '$clientId' },
1224
1267
  ticketId: { $first: '$ticketId' },
1225
- actionBy: { $first: '$actionBy' },
1268
+ issueIdentifiedBy: { $first: '$issueIdentifiedBy' },
1226
1269
  storeName: { $first: '$storeName' },
1227
1270
  clientName: { $first: '$clientName' },
1228
1271
  createdAt: { $first: '$createdAt' },
@@ -1281,11 +1324,11 @@ export async function hourWiseDownstores( req, res ) {
1281
1324
  } ];
1282
1325
  }
1283
1326
  }
1284
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
1327
+ if ( req.user&&req.user.userType ==='client' ) {
1285
1328
  storesQuery.push(
1286
1329
  {
1287
1330
  $match: {
1288
- 'storeId': { $in: req.body.permittedStores },
1331
+ 'storeId': { $in: req.body.assignedStores },
1289
1332
  },
1290
1333
  },
1291
1334
  );
@@ -1314,10 +1357,11 @@ export async function hourWiseDownstores( req, res ) {
1314
1357
  }
1315
1358
 
1316
1359
  if ( req.body.filter && req.body.filter.length > 0 ) {
1360
+ req.body.filter.push( '' );
1317
1361
  query.push(
1318
1362
  {
1319
1363
  $match: {
1320
- actionBy: { $in: req.body.filter },
1364
+ issueIdentifiedBy: { $in: req.body.filter },
1321
1365
  },
1322
1366
  },
1323
1367
  );
@@ -1489,8 +1533,8 @@ export async function ticketCountSplit( req, res ) {
1489
1533
  { issueType: { $in: [ 'highcount', 'lowcount' ] } },
1490
1534
 
1491
1535
  ];
1492
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
1493
- filter.push( { 'basicDetails.storeId': { $in: req.body.permittedStores } } );
1536
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
1537
+ filter.push( { 'basicDetails.storeId': { $in: req.body.assignedStores } } );
1494
1538
  }
1495
1539
  if ( req.user.userType === 'client' ) {
1496
1540
  filter.push( { 'dataMismatch.showToClient': true } );
@@ -1570,8 +1614,8 @@ export async function overViewTable( req, res ) {
1570
1614
  'basicDetails.clientId': { $in: inputData.clientId },
1571
1615
  },
1572
1616
  ];
1573
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
1574
- filter.push( { 'basicDetails.storeId': { $in: req.body.permittedStores } } );
1617
+ if ( req.user&&req.user.userType ==='client' ) {
1618
+ filter.push( { 'basicDetails.storeId': { $in: req.body.assignedStores } } );
1575
1619
  }
1576
1620
  if ( req.user.userType === 'client' ) {
1577
1621
  filter.push( { 'dataMismatch.showToClient': true } );
@@ -1668,8 +1712,8 @@ export async function ticketCount( req, res ) {
1668
1712
  },
1669
1713
 
1670
1714
  ];
1671
- if ( req.body.permittedStores && req.body.permittedStores.length > 0 ) {
1672
- filter.push( { 'basicDetails.storeId': { $in: req.body.permittedStores } } );
1715
+ if ( req.user&&req.user.userType ==='client' &&req.user.role!='superadmin' ) {
1716
+ filter.push( { 'basicDetails.storeId': { $in: req.body.assignedStores } } );
1673
1717
  }
1674
1718
  if ( req.user.userType === 'client' ) {
1675
1719
  filter.push( { 'dataMismatch.showToClient': true } );
@@ -1828,7 +1872,7 @@ export async function checkPermission( req, res, next ) {
1828
1872
  }
1829
1873
  if ( result&&result.length>0 ) {
1830
1874
  const uniqueArray = [ ...new Set( result[0].storeList ) ];
1831
- req.body.permittedStores =uniqueArray;
1875
+ req.body.assignedStores =uniqueArray;
1832
1876
  }
1833
1877
  }
1834
1878
  next();
@@ -1837,3 +1881,30 @@ export async function checkPermission( req, res, next ) {
1837
1881
  res.sendError( 'Internal Server Error', 500 );
1838
1882
  }
1839
1883
  };
1884
+
1885
+ export async function getcount( req, res ) {
1886
+ try {
1887
+ let storecountQuery ={ 'clientId': { $in: req.body.clientId }, 'status': 'active' };
1888
+
1889
+ if ( req.user&&req.user.userType ==='client'&&req.user.role!='superadmin' ) {
1890
+ storecountQuery = { ...storecountQuery, ...{ storeId: { $in: req.body.assignedStores } } };
1891
+ }
1892
+
1893
+ let storeCount = await countDocumentsStore( storecountQuery );
1894
+ let userCount = await countDocumentsUser( { 'clientId': { $in: req.body.clientId }, 'isActive': true } );
1895
+ let teamCount = await countDocumentsTeams( { 'clientId': { $in: req.body.clientId } } );
1896
+ let clusterCount = await countDocumentsClusters( { 'clientId': { $in: req.body.clientId } } );
1897
+
1898
+
1899
+ res.sendSuccess( {
1900
+ storeCount: storeCount,
1901
+ userCount: userCount,
1902
+ teamCount: teamCount,
1903
+ clusterCount: clusterCount,
1904
+ } );
1905
+ } catch ( error ) {
1906
+ logger.error( { error: error, function: 'getcount' } );
1907
+ res.sendError( 'Internal Server Error', 500 );
1908
+ }
1909
+ }
1910
+