tango-app-api-audit 3.5.25 → 3.5.27

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-audit",
3
- "version": "3.5.25",
3
+ "version": "3.5.27",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -7,7 +7,7 @@ import timezone from 'dayjs/plugin/timezone.js';
7
7
  import 'dayjs/locale/en.js';
8
8
  import { findOneEyeTestConfig, updateOneEyeTestConfig } from '../service/eyeTestConfiguration.service.js';
9
9
  import { ObjectId } from 'mongodb';
10
- import { aggregateClusters } from '../service/clusters.service.js';
10
+ import { aggregateClusters, findOneClusters } from '../service/clusters.service.js';
11
11
 
12
12
  dayjs.extend( utc );
13
13
  dayjs.extend( timezone );
@@ -1081,6 +1081,56 @@ export async function userAuditedData( req, res ) {
1081
1081
  export async function summaryList( req, res ) {
1082
1082
  try {
1083
1083
  const inputData = req.body;
1084
+ if ( inputData.clientId !== '11' ) {
1085
+ return res.sendError( 'No data found', 204 );
1086
+ }
1087
+
1088
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
1089
+ const limit = inputData.limit || 10;
1090
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
1091
+
1092
+ const sortBy = inputData?.sortBy ? [ 'coveredStepsAI', 'trustScore', 'date' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
1093
+ const order = inputData?.sortOrder || -1;
1094
+
1095
+ let filter= [
1096
+ {
1097
+ 'range': {
1098
+ 'date': {
1099
+ 'gte': new Date( inputData.fromDate ),
1100
+ 'lte': new Date( inputData.toDate ),
1101
+ },
1102
+ },
1103
+ },
1104
+
1105
+ ];
1106
+ if ( inputData.demographics && inputData.demographics.length > 0 ) {
1107
+ filter.push( {
1108
+ 'terms': {
1109
+ 'visitorsType.keyword': inputData.demographics,
1110
+ },
1111
+ } );
1112
+ }
1113
+ if ( inputData.type && inputData.type!='' ) {
1114
+ filter.push( {
1115
+ 'term': {
1116
+ 'type.keyword': inputData.type,
1117
+ },
1118
+
1119
+ } );
1120
+ }
1121
+ if ( inputData.storeId && inputData.storeId.length > 0 ) {
1122
+ filter.push( {
1123
+
1124
+ 'terms': {
1125
+ 'storeId.keyword': inputData.storeId,
1126
+ },
1127
+
1128
+ } );
1129
+ } else {
1130
+ return res.sendError( 'No data found', 204 );
1131
+ }
1132
+
1133
+
1084
1134
  if ( inputData.keyType === 'rm' ) {
1085
1135
  return res.sendSuccess( { result: [
1086
1136
  {
@@ -1095,224 +1145,338 @@ export async function summaryList( req, res ) {
1095
1145
 
1096
1146
  ], count: 1 } );
1097
1147
  } else if ( inputData.keyType === 'cluster' ) {
1098
- return res.sendSuccess( { result: [
1148
+ const clusterQuery =[
1149
+ { $match: { 'Teamlead.email': { $in: inputData.RMList } } },
1150
+ { $unwind: { path: '$stores', preserveNullAndEmptyArrays: true } },
1099
1151
  {
1100
- RMName: '',
1101
- clusterName: '',
1102
- storeName: '',
1103
- totalFiles: 0,
1104
- completedFiles: 0,
1105
- tangoScore: 0,
1106
- trustScore: 0,
1152
+ $group: {
1153
+ _id: '$clusterName',
1154
+ clusterName: { $first: '$clusterName' },
1155
+ store: { $addToSet: '$stores.storeId' },
1156
+
1157
+ },
1107
1158
  },
1159
+ { $project: {
1160
+ RMName: inputData?.RMList[0],
1161
+ clusterName: 1,
1162
+ storesCount: { $size: '$store' },
1163
+ store: 1,
1164
+ } },
1165
+ ];
1166
+ const getCluster = await aggregateClusters( clusterQuery );
1167
+ logger.info( { getCluster: getCluster } );
1168
+ if ( !getCluster || getCluster?.length == 0 ) {
1169
+ return res.sendError( 'No data', 400 );
1170
+ }
1171
+ const temp =[];
1172
+ for ( const [ i, cluster ] of getCluster.entries() ) {
1173
+ logger.info( { cluster: cluster } );
1174
+ temp.push( cluster );
1175
+ const getClusterQuery= {
1176
+ 'size': 0,
1177
+ 'query': {
1178
+ 'bool': {
1179
+ 'must': [
1180
+ { 'terms': { 'storeId.keyword': cluster?.store } },
1181
+ { 'term': { 'type.keyword': inputData?.type } },
1182
+ {
1183
+ 'range': {
1184
+ 'date': {
1185
+ 'gte': inputData?.fromDate,
1186
+ 'lte': inputData?.toDate,
1187
+ },
1188
+ },
1189
+ },
1108
1190
 
1109
- ], count: 1 } );
1110
- } else {
1111
- return res.sendSuccess( { result: [
1112
- {
1113
- 'fileDate': '2025-08-19',
1114
- 'comment': '',
1115
- 'subComment': '',
1116
- 'date': '2025-08-19T00:00:00.000+00:00',
1117
- 'storeName': 'LKST886',
1118
- 'storeId': '11-995',
1119
- 'type': 'physical',
1120
- 'optumId': '184812',
1121
- 'queueId': '106906147',
1122
- 'engagementId': '',
1123
- 'totalSteps': 6,
1124
- 'coveredStepsAI': 5,
1125
- 'testDuration': 420,
1126
- 'auditStatus': 'Yet-to-Audit',
1127
- 'userId': null,
1128
- 'visitorsType': 'adult',
1129
- 'inputBucketName': 'tango-eye-test-output',
1130
- 'filePath': 'eye-test/2025-08-19/11-995/106906147_184812.mp4',
1131
- 'startTime': '',
1132
- 'endTime': '',
1133
- 'displayName': '',
1134
- 'testStartTime': '17:13:34',
1135
- 'testEndTime': '17:20:34',
1136
- 'createdAt': '2025-08-20T08:05:28.188Z',
1137
- 'updatedAt': '2025-08-20T08:05:28.188Z',
1138
- 'steps': [
1139
- {
1140
- 'processName': 'Distance-VA-Check',
1141
- 'AIStatus': true,
1142
- 'predictedTranscript': '',
1143
- },
1144
- {
1145
- 'processName': 'DuoChrome-Test',
1146
- 'AIStatus': true,
1147
- 'predictedTranscript': '',
1148
- },
1149
- {
1150
- 'processName': 'Torchlight',
1151
- 'AIStatus': true,
1152
- 'predictedTranscript': '',
1191
+ ],
1153
1192
  },
1154
- {
1155
- 'processName': 'JCC',
1156
- 'AIStatus': true,
1157
- 'predictedTranscript': '',
1193
+ },
1194
+ 'aggs': {
1195
+ 'total_count': {
1196
+ 'value_count': { 'field': '_id' },
1158
1197
  },
1159
- {
1160
- 'processName': 'Near-VA-Check',
1161
- 'AIStatus': true,
1162
- 'predictedTranscript': '',
1198
+ 'avg_complianceScore': {
1199
+ 'avg': { 'field': 'ComplianceScore' },
1163
1200
  },
1164
- {
1165
- 'processName': 'Prescription-Verification',
1166
- 'AIStatus': false,
1167
- 'predictedTranscript': '',
1201
+ 'audited_trustScore': {
1202
+ 'filter': { 'terms': { 'auditStatus.keyword': [ 'Audited', 'reAudited' ] } },
1203
+ 'aggs': {
1204
+ 'avg_trustScore': {
1205
+ 'avg': { 'field': 'trustScore' },
1206
+ },
1207
+ 'totalCount': {
1208
+ 'value_count': { 'field': '_id' },
1209
+ },
1210
+ },
1168
1211
  },
1169
- ],
1212
+ },
1213
+ };
1214
+ const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
1215
+ logger.info( { getResponse: getResponse } );
1216
+ if ( getResponse?.body?.aggregations ) {
1217
+ delete temp[i].store;
1218
+ delete temp[i]._id;
1219
+ temp[i].totalFiles = getResponse?.body?.aggregations?.total_count?.value || 0,
1220
+ temp[i].completedFiles=getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 0;
1221
+ temp[i].complianceScore = getResponse?.body?.aggregations?.avg_complianceScore?.value || 0;
1222
+ temp[i].trustScore =getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 'NA';
1223
+ logger.info( { getResponse: getResponse, ms: '........1' } );
1224
+ }
1225
+ }
1226
+
1227
+ return res.sendSuccess( { result: temp, count: getCluster?.length || 0 } );
1228
+ } else {
1229
+ let search ={
1230
+ 'must': filter,
1231
+ };
1232
+ if ( inputData.searchValue && inputData.searchValue !== '' ) {
1233
+ if ( inputData.type&&inputData.type==='remote' ) {
1234
+ search ={
1235
+ 'must': filter,
1236
+ 'should': [
1237
+ {
1238
+ 'wildcard': {
1239
+ 'storeName.keyword': {
1240
+ 'value': `*${inputData.searchValue}*`,
1241
+ },
1242
+ },
1243
+ },
1244
+ {
1245
+ 'wildcard': {
1246
+ 'storeId.keyword': {
1247
+ 'value': `*${inputData.searchValue}*`,
1248
+ },
1249
+ },
1250
+ },
1251
+ {
1252
+ 'wildcard': {
1253
+ 'engagementId.keyword': {
1254
+ 'value': `*${inputData.searchValue}*`,
1255
+ },
1256
+ },
1257
+ },
1258
+
1259
+ {
1260
+ 'wildcard': {
1261
+ 'auditStatus.keyword': {
1262
+ 'value': `*${inputData.searchValue}*`,
1263
+ },
1264
+ },
1265
+ },
1266
+ ],
1267
+ 'minimum_should_match': 1,
1268
+ };
1269
+ } else {
1270
+ search ={
1271
+ 'must': filter,
1272
+ 'should': [
1273
+ {
1274
+ 'wildcard': {
1275
+ 'storeName.keyword': {
1276
+ 'value': `*${inputData.searchValue}*`,
1277
+ },
1278
+ },
1279
+ },
1280
+ {
1281
+ 'wildcard': {
1282
+ 'storeId.keyword': {
1283
+ 'value': `*${inputData.searchValue}*`,
1284
+ },
1285
+ },
1286
+ },
1287
+ {
1288
+ 'wildcard': {
1289
+ 'engagementId.keyword': {
1290
+ 'value': `*${inputData.searchValue}*`,
1291
+ },
1292
+ },
1293
+ },
1294
+ {
1295
+ 'wildcard': {
1296
+ 'queueId.keyword': {
1297
+ 'value': `*${inputData.searchValue}*`,
1298
+ },
1299
+ },
1300
+ },
1301
+ {
1302
+ 'wildcard': {
1303
+ 'optumId.keyword': {
1304
+ 'value': `*${inputData.searchValue}*`,
1305
+ },
1306
+ },
1307
+ },
1308
+ {
1309
+ 'wildcard': {
1310
+ 'visitorsType.keyword': {
1311
+ 'value': `*${inputData.searchValue}*`,
1312
+ },
1313
+ },
1314
+ },
1315
+
1316
+ {
1317
+ 'wildcard': {
1318
+ 'auditStatus.keyword': {
1319
+ 'value': `*${inputData.searchValue}*`,
1320
+ },
1321
+ },
1322
+ },
1323
+ ],
1324
+ 'minimum_should_match': 1,
1325
+ };
1326
+ }
1327
+ }
1328
+
1329
+ let searchQuery={
1330
+ 'from': offset,
1331
+ 'size': limit,
1332
+ 'query': {
1333
+ 'bool': search,
1170
1334
  },
1171
- {
1172
- 'fileDate': '2025-08-18',
1173
- 'comment': '',
1174
- 'subComment': '',
1175
- 'date': '2025-08-18T00:00:00.000+00:00',
1176
- 'storeName': 'LKST80',
1177
- 'storeId': '11-10',
1178
- 'type': 'physical',
1179
- 'optumId': '164980',
1180
- 'queueId': '106772967',
1181
- 'engagementId': '',
1182
- 'totalSteps': 6,
1183
- 'coveredStepsAI': 4,
1184
- 'testDuration': 580,
1185
- 'auditStatus': 'Yet-to-Audit',
1186
- 'userId': null,
1187
- 'visitorsType': 'adult',
1188
- 'inputBucketName': 'tango-eye-test-output',
1189
- 'filePath': 'eye-test/2025-08-18/11-10/106772967_164980.mp4',
1190
- 'startTime': '',
1191
- 'endTime': '',
1192
- 'displayName': '',
1193
- 'testStartTime': '12:25:32',
1194
- 'testEndTime': '12:35:12',
1195
- 'createdAt': '2025-08-19T11:56:55.822Z',
1196
- 'updatedAt': '2025-08-19T11:56:55.822Z',
1197
- 'steps': [
1198
- {
1199
- 'processName': 'Distance-VA-Check',
1200
- 'AIStatus': true,
1201
- 'predictedTranscript': '',
1202
- },
1203
- {
1204
- 'processName': 'DuoChrome-Test',
1205
- 'AIStatus': true,
1206
- 'predictedTranscript': '',
1207
- },
1208
- {
1209
- 'processName': 'Prescription-Verification',
1210
- 'AIStatus': true,
1211
- 'predictedTranscript': '',
1212
- },
1213
- {
1214
- 'processName': 'Near-VA-Check',
1215
- 'AIStatus': true,
1216
- 'predictedTranscript': '',
1217
- },
1218
- {
1219
- 'processName': 'Torchlight',
1220
- 'AIStatus': false,
1221
- 'predictedTranscript': '',
1222
- },
1223
- {
1224
- 'processName': 'JCC',
1225
- 'AIStatus': false,
1226
- 'predictedTranscript': '',
1227
- },
1335
+ 'sort': [
1336
+ { date: { order: 'desc' } },
1337
+ ],
1338
+ };
1339
+
1340
+ if ( sortBy && sortBy !== '' ) {
1341
+ searchQuery={
1342
+ 'from': offset,
1343
+ 'size': limit,
1344
+ 'query': {
1345
+ 'bool': search,
1346
+ },
1347
+ 'sort': [
1348
+ { [sortBy]: { order: order === -1 ?'desc':'asc' } },
1349
+ { '_id': 'asc' },
1228
1350
  ],
1351
+ };
1352
+ }
1353
+
1354
+ if ( inputData.isExport==true ) {
1355
+ searchQuery={
1356
+ 'from': 0,
1357
+ 'size': 10000,
1358
+ 'query': {
1359
+ 'bool': search,
1360
+ },
1361
+ 'sort': [
1362
+ { 'storeName.keyword': { order: 'desc' } },
1363
+ ],
1364
+ };
1365
+ // allResult =await fetchAllDocuments( openSearch.EyeTestInput, search );
1366
+ }
1367
+
1368
+ const countQuery = {
1369
+ query: {
1370
+ bool: search,
1229
1371
  },
1230
- {
1231
- 'fileDate': '2025-08-19',
1232
- 'comment': 'Possible Fake Video',
1233
- 'subComment': 'Customer not inside clinic within 120 seconds.',
1234
- 'date': '2025-08-19T00:00:00.000+00:00',
1235
- 'storeName': 'LKST1362',
1236
- 'storeId': '11-1563',
1237
- 'type': 'physical',
1238
- 'optumId': '131354',
1239
- 'queueId': '106907022',
1240
- 'engagementId': '',
1241
- 'totalSteps': 6,
1242
- 'coveredStepsAI': 0,
1243
- 'testDuration': 555,
1244
- 'auditStatus': 'Yet-to-Audit',
1245
- 'userId': null,
1246
- 'visitorsType': 'adult',
1247
- 'inputBucketName': 'tango-eye-test-output',
1248
- 'filePath': 'eye-test/2025-08-19/11-1563/106907022_131354.mp4',
1249
- 'startTime': '',
1250
- 'endTime': '',
1251
- 'displayName': '',
1252
- 'testStartTime': '17:31:57',
1253
- 'testEndTime': '17:41:12',
1254
- 'createdAt': '2025-08-20T10:24:15.169Z',
1255
- 'updatedAt': '2025-08-20T10:24:15.169Z',
1256
- 'steps': [],
1257
- },
1258
- {
1259
- 'fileDate': '2025-08-19',
1260
- 'comment': 'Possible Fake Video',
1261
- 'subComment': 'Customer not inside clinic within 120 seconds.',
1262
- 'date': '2025-08-19T00:00:00.000+00:00',
1263
- 'storeName': 'LKST1158',
1264
- 'storeId': '11-1003',
1265
- 'type': 'physical',
1266
- 'optumId': '174254',
1267
- 'queueId': '106907580',
1268
- 'engagementId': '',
1269
- 'totalSteps': 6,
1270
- 'coveredStepsAI': 0,
1271
- 'testDuration': 834,
1272
- 'auditStatus': 'Yet-to-Audit',
1273
- 'userId': null,
1274
- 'visitorsType': 'adult',
1275
- 'inputBucketName': 'tango-eye-test-output',
1276
- 'filePath': 'eye-test/2025-08-19/11-1003/106907580_174254.mp4',
1277
- 'startTime': '',
1278
- 'endTime': '',
1279
- 'displayName': '',
1280
- 'testStartTime': '17:21:42',
1281
- 'testEndTime': '17:35:36',
1282
- 'createdAt': '2025-08-20T09:52:29.116Z',
1283
- 'updatedAt': '2025-08-20T09:52:29.116Z',
1284
- 'steps': [],
1285
- },
1286
- {
1287
- 'fileDate': '2025-08-19',
1288
- 'comment': 'Possible Fake Video',
1289
- 'subComment': 'Customer not inside clinic within 120 seconds.',
1290
- 'date': '2025-08-19T00:00:00.000+00:00',
1291
- 'storeName': 'LKST1158',
1292
- 'storeId': '11-1003',
1293
- 'type': 'physical',
1294
- 'optumId': '174254',
1295
- 'queueId': '106878780',
1296
- 'engagementId': '',
1297
- 'totalSteps': 6,
1298
- 'coveredStepsAI': 0,
1299
- 'testDuration': 335,
1300
- 'auditStatus': 'Yet-to-Audit',
1301
- 'userId': null,
1302
- 'visitorsType': 'adult',
1303
- 'inputBucketName': 'tango-eye-test-output',
1304
- 'filePath': 'eye-test/2025-08-19/11-1003/106878780_174254.mp4',
1305
- 'startTime': '',
1306
- 'endTime': '',
1307
- 'displayName': '',
1308
- 'testStartTime': '13:08:43',
1309
- 'testEndTime': '13:14:18',
1310
- 'createdAt': '2025-08-20T09:47:06.812Z',
1311
- 'updatedAt': '2025-08-20T09:47:06.812Z',
1312
- 'steps': [],
1313
- },
1372
+ };
1373
+
1374
+ const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
1375
+ const getCount = inputData.isExport==true? null:await getOpenSearchCount( openSearch.EyeTestInput, countQuery );
1376
+ const count =inputData.isExport==true?null: getCount?.body?.count;
1377
+ const searchValue = result?.body?.hits?.hits;
1378
+ const temp =[];
1379
+ if ( !searchValue || searchValue?.length == 0 ) {
1380
+ return res.sendError( 'No data found', 204 );
1381
+ }
1382
+ if ( inputData.isExport == true ) {
1383
+ const chunkedMappingData = await chunkArray( searchValue, 10 );
1384
+ const promises = chunkedMappingData.map( async ( chunk ) => {
1385
+ const exportData = [];
1386
+ for ( const element of chunk ) {
1387
+ const testDuration = element?._source?.testDuration;
1388
+ const minutes = Math.floor( testDuration / 60 );
1389
+ const seconds = testDuration % 60;
1390
+ const minutes1 =minutes> 1? `${minutes} mins` : `${minutes} min`;
1391
+ const seconds1 = seconds > 1? `${minutes} secs`: seconds == 1? `${minutes} sec` : '';
1392
+ const duration =`${minutes1} ${seconds1}`;
1393
+ let userName = '';
1394
+ if ( element?._source?.userId&&element?._source?.userId!='' ) {
1395
+ userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
1396
+ }
1397
+
1398
+ let RMName = '';
1399
+ let clusterName='';
1400
+ if ( element?._source?.storeId&&element?._source?.storeId!='' ) {
1401
+ const getCluster = await findOneClusters( { 'stores.storeId': element?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
1402
+ RMName =( getCluster && getCluster.Teamlead?.length > 0 )? getCluster?.Teamlead?.[0]?.email : '';
1403
+ clusterName = getCluster?.clusterName;
1404
+ }
1405
+ if ( element?._source?.type == 'physical' ) {
1406
+ exportData.push( {
1407
+ 'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
1408
+ 'RM Name': RMName,
1409
+ 'Cluster Name': clusterName,
1410
+ 'Store Name': element?._source?.storeName,
1411
+ 'Store ID': element?._source?.storeId || 'Un Assigned',
1412
+ 'Store Name': element?._source?.storeName ||'Un Assigned',
1413
+ 'Optum ID': element?._source?.optumId,
1414
+ 'Queue ID': element?._source?.queueId,
1415
+ 'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
1416
+ 'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
1417
+ 'Trust Score': element?._source?.trustScore || 0,
1418
+ 'Visitor Type': element?._source?.visitorsType,
1419
+ 'Test Duration': duration || '',
1420
+ 'Audit Status': element?._source?.auditStatus || '',
1421
+ 'Audited By': userName?.userName || '',
1422
+
1423
+ } );
1424
+ } else {
1425
+ exportData.push( {
1426
+ 'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
1427
+ 'Cluster Name': clusterName,
1428
+ 'Store Name': element?._source?.storeName,
1429
+ 'Store Name': element?._source?.storeName,
1430
+ 'Store ID': element?._source?.storeId || 'Un Assigned',
1431
+ 'Store Name': element?._source?.storeName ||'Un Assigned',
1432
+ 'Engagement ID': element?._source?.engagementId,
1433
+ 'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
1434
+ 'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
1435
+ 'Trust Score': element?._source?.trustScore ||0,
1436
+ 'Test Duration': duration || '',
1437
+ 'Audit Status': element?._source?.auditStatus || '',
1438
+ 'Audited By': userName?.userName || '',
1439
+
1440
+ } );
1441
+ }
1442
+ }
1443
+ return exportData;
1444
+ } );
1445
+ const mappedArrays = await Promise.all( promises );
1446
+ const result = mappedArrays.flat();
1447
+ await download( result, res );
1448
+ return;
1449
+ } else {
1450
+ for ( const [ i, item ] of searchValue.entries() ) {
1451
+ temp.push( item?._source );
1452
+ logger.info( { source: item } );
1453
+ let userName='';
1454
+ if ( item?._source?.userId&&item?._source?.userId!='' ) {
1455
+ userName = await findOneUser( { _id: item?._source?.userId }, { _id: 0, userName: 1 } );
1456
+ }
1457
+ let RMName = '';
1458
+ let clusterName='';
1459
+ if ( item?._source?.storeId&&item?._source?.storeId!='' ) {
1460
+ const getCluster = await findOneClusters( { 'stores.storeId': item?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
1461
+ RMName =( getCluster && getCluster.Teamlead?.length > 0 )? getCluster?.Teamlead?.[0]?.email : '';
1462
+ clusterName = getCluster?.clusterName;
1463
+ }
1464
+ logger.info( { RMName: RMName } );
1465
+ const testDuration = item?._source?.testDuration;
1466
+ const minutes = Math.floor( testDuration / 60 );
1467
+ const seconds = testDuration % 60;
1468
+ temp[i].complianceScore = item?._source?.totalSteps>0 ? Math.round( ( item?._source?.coveredStepsAI/ item?._source?.totalSteps )*100 ): 0;
1469
+ temp[i].min = minutes;
1470
+ temp[i].sec = seconds;
1471
+ temp[i].auditedBy = userName?.userName || '';
1472
+ temp[i].date = dayjs( item?._source?.date ).format( 'D MMM, YYYY' );
1473
+ temp[i].RMName = RMName;
1474
+ temp[i].clusterName =clusterName;
1475
+ }
1476
+ logger.info( { temp: temp } );
1477
+ }
1314
1478
 
1315
- ], count: 14 } );
1479
+ return res.sendSuccess( { result: temp, count: count } );
1316
1480
  }
1317
1481
  } catch ( error ) {
1318
1482
  const err = error.message || 'Internal Server Error';
@@ -5,6 +5,10 @@ export function aggregateClusters( query ) {
5
5
  return clusterModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
6
6
  }
7
7
 
8
- export function findClusters( query ) {
8
+ export function findClusters( query, field ) {
9
9
  return clusterModel.find( query, field );
10
10
  }
11
+
12
+ export function findOneClusters( query, field ) {
13
+ return clusterModel.findOne( query, field ).sort( { _id: -1 } );
14
+ }