tango-app-api-audit 3.5.25 → 3.5.26

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.26",
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
  {
@@ -1108,211 +1158,245 @@ export async function summaryList( req, res ) {
1108
1158
 
1109
1159
  ], count: 1 } );
1110
1160
  } 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': '',
1153
- },
1154
- {
1155
- 'processName': 'JCC',
1156
- 'AIStatus': true,
1157
- 'predictedTranscript': '',
1158
- },
1159
- {
1160
- 'processName': 'Near-VA-Check',
1161
- 'AIStatus': true,
1162
- 'predictedTranscript': '',
1163
- },
1164
- {
1165
- 'processName': 'Prescription-Verification',
1166
- 'AIStatus': false,
1167
- 'predictedTranscript': '',
1168
- },
1169
- ],
1161
+ let search ={
1162
+ 'must': filter,
1163
+ };
1164
+ if ( inputData.searchValue && inputData.searchValue !== '' ) {
1165
+ if ( inputData.type&&inputData.type==='remote' ) {
1166
+ search ={
1167
+ 'must': filter,
1168
+ 'should': [
1169
+ {
1170
+ 'wildcard': {
1171
+ 'storeName.keyword': {
1172
+ 'value': `*${inputData.searchValue}*`,
1173
+ },
1174
+ },
1175
+ },
1176
+ {
1177
+ 'wildcard': {
1178
+ 'storeId.keyword': {
1179
+ 'value': `*${inputData.searchValue}*`,
1180
+ },
1181
+ },
1182
+ },
1183
+ {
1184
+ 'wildcard': {
1185
+ 'engagementId.keyword': {
1186
+ 'value': `*${inputData.searchValue}*`,
1187
+ },
1188
+ },
1189
+ },
1190
+
1191
+ {
1192
+ 'wildcard': {
1193
+ 'auditStatus.keyword': {
1194
+ 'value': `*${inputData.searchValue}*`,
1195
+ },
1196
+ },
1197
+ },
1198
+ ],
1199
+ 'minimum_should_match': 1,
1200
+ };
1201
+ } else {
1202
+ search ={
1203
+ 'must': filter,
1204
+ 'should': [
1205
+ {
1206
+ 'wildcard': {
1207
+ 'storeName.keyword': {
1208
+ 'value': `*${inputData.searchValue}*`,
1209
+ },
1210
+ },
1211
+ },
1212
+ {
1213
+ 'wildcard': {
1214
+ 'storeId.keyword': {
1215
+ 'value': `*${inputData.searchValue}*`,
1216
+ },
1217
+ },
1218
+ },
1219
+ {
1220
+ 'wildcard': {
1221
+ 'engagementId.keyword': {
1222
+ 'value': `*${inputData.searchValue}*`,
1223
+ },
1224
+ },
1225
+ },
1226
+ {
1227
+ 'wildcard': {
1228
+ 'queueId.keyword': {
1229
+ 'value': `*${inputData.searchValue}*`,
1230
+ },
1231
+ },
1232
+ },
1233
+ {
1234
+ 'wildcard': {
1235
+ 'optumId.keyword': {
1236
+ 'value': `*${inputData.searchValue}*`,
1237
+ },
1238
+ },
1239
+ },
1240
+ {
1241
+ 'wildcard': {
1242
+ 'visitorsType.keyword': {
1243
+ 'value': `*${inputData.searchValue}*`,
1244
+ },
1245
+ },
1246
+ },
1247
+
1248
+ {
1249
+ 'wildcard': {
1250
+ 'auditStatus.keyword': {
1251
+ 'value': `*${inputData.searchValue}*`,
1252
+ },
1253
+ },
1254
+ },
1255
+ ],
1256
+ 'minimum_should_match': 1,
1257
+ };
1258
+ }
1259
+ }
1260
+
1261
+ let searchQuery={
1262
+ 'from': offset,
1263
+ 'size': limit,
1264
+ 'query': {
1265
+ 'bool': search,
1170
1266
  },
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
- },
1267
+ 'sort': [
1268
+ { date: { order: 'desc' } },
1269
+ ],
1270
+ };
1271
+
1272
+ if ( sortBy && sortBy !== '' ) {
1273
+ searchQuery={
1274
+ 'from': offset,
1275
+ 'size': limit,
1276
+ 'query': {
1277
+ 'bool': search,
1278
+ },
1279
+ 'sort': [
1280
+ { [sortBy]: { order: order === -1 ?'desc':'asc' } },
1281
+ { '_id': 'asc' },
1228
1282
  ],
1283
+ };
1284
+ }
1285
+
1286
+ if ( inputData.isExport==true ) {
1287
+ searchQuery={
1288
+ 'from': 0,
1289
+ 'size': 10000,
1290
+ 'query': {
1291
+ 'bool': search,
1292
+ },
1293
+ 'sort': [
1294
+ { 'storeName.keyword': { order: 'desc' } },
1295
+ ],
1296
+ };
1297
+ // allResult =await fetchAllDocuments( openSearch.EyeTestInput, search );
1298
+ }
1299
+
1300
+ const countQuery = {
1301
+ query: {
1302
+ bool: search,
1229
1303
  },
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
- },
1304
+ };
1305
+
1306
+ const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
1307
+ const getCount = inputData.isExport==true? null:await getOpenSearchCount( openSearch.EyeTestInput, countQuery );
1308
+ const count =inputData.isExport==true?null: getCount?.body?.count;
1309
+ const searchValue = result?.body?.hits?.hits;
1310
+ const temp =[];
1311
+ if ( !searchValue || searchValue?.length == 0 ) {
1312
+ return res.sendError( 'No data found', 204 );
1313
+ }
1314
+ if ( inputData.isExport == true ) {
1315
+ const chunkedMappingData = await chunkArray( searchValue, 10 );
1316
+ const promises = chunkedMappingData.map( async ( chunk ) => {
1317
+ const exportData = [];
1318
+ for ( const element of chunk ) {
1319
+ const testDuration = element?._source?.testDuration;
1320
+ const minutes = Math.floor( testDuration / 60 );
1321
+ const seconds = testDuration % 60;
1322
+ const minutes1 =minutes> 1? `${minutes} mins` : `${minutes} min`;
1323
+ const seconds1 = seconds > 1? `${minutes} secs`: seconds == 1? `${minutes} sec` : '';
1324
+ const duration =`${minutes1} ${seconds1}`;
1325
+ let userName = '';
1326
+ if ( element?._source?.userId&&element?._source?.userId!='' ) {
1327
+ userName = await findOneUser( { _id: element?._source?.userId }, { _id: 0, userName: 1 } );
1328
+ }
1329
+ if ( element?._source?.type == 'physical' ) {
1330
+ exportData.push( {
1331
+ 'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
1332
+ 'Store Name': element?._source?.storeName,
1333
+ 'Store ID': element?._source?.storeId || 'Un Assigned',
1334
+ 'Store Name': element?._source?.storeName ||'Un Assigned',
1335
+ 'Optum ID': element?._source?.optumId,
1336
+ 'Queue ID': element?._source?.queueId,
1337
+ 'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
1338
+ 'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
1339
+ 'Trust Score': element?._source?.trustScore || 0,
1340
+ 'Visitor Type': element?._source?.visitorsType,
1341
+ 'Test Duration': duration || '',
1342
+ 'Audit Status': element?._source?.auditStatus || '',
1343
+ 'Audited By': userName?.userName || '',
1344
+
1345
+ } );
1346
+ } else {
1347
+ exportData.push( {
1348
+ 'Date': dayjs( element?._source?.date ).format( 'D MMM, YYYY' ),
1349
+ 'Store Name': element?._source?.storeName,
1350
+ 'Store ID': element?._source?.storeId || 'Un Assigned',
1351
+ 'Store Name': element?._source?.storeName ||'Un Assigned',
1352
+ 'Engagement ID': element?._source?.engagementId,
1353
+ 'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
1354
+ 'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
1355
+ 'Trust Score': element?._source?.trustScore ||0,
1356
+ 'Test Duration': duration || '',
1357
+ 'Audit Status': element?._source?.auditStatus || '',
1358
+ 'Audited By': userName?.userName || '',
1359
+
1360
+ } );
1361
+ }
1362
+ }
1363
+ return exportData;
1364
+ } );
1365
+ const mappedArrays = await Promise.all( promises );
1366
+ const result = mappedArrays.flat();
1367
+ await download( result, res );
1368
+ return;
1369
+ } else {
1370
+ for ( const [ i, item ] of searchValue.entries() ) {
1371
+ temp.push( item?._source );
1372
+ logger.info( { source: item } );
1373
+ let userName='';
1374
+ if ( item?._source?.userId&&item?._source?.userId!='' ) {
1375
+ userName = await findOneUser( { _id: item?._source?.userId }, { _id: 0, userName: 1 } );
1376
+ }
1377
+ let RMName = '';
1378
+ let clusterName='';
1379
+ if ( item?._source?.storeId&&item?._source?.storeId!='' ) {
1380
+ const getCluster = await findOneClusters( { 'stores.storeId': item?._source?.storeId }, { Teamlead: 1, clusterName: 1 } );
1381
+ RMName =( getCluster && getCluster.Teamlead?.length > 0 )? getCluster?.Teamlead?.[0]?.email : '';
1382
+ clusterName = getCluster?.clusterName;
1383
+ }
1384
+ logger.info( { RMName: RMName } );
1385
+ const testDuration = item?._source?.testDuration;
1386
+ const minutes = Math.floor( testDuration / 60 );
1387
+ const seconds = testDuration % 60;
1388
+ temp[i].complianceScore = item?._source?.totalSteps>0 ? Math.round( ( item?._source?.coveredStepsAI/ item?._source?.totalSteps )*100 ): 0;
1389
+ temp[i].min = minutes;
1390
+ temp[i].sec = seconds;
1391
+ temp[i].auditedBy = userName?.userName || '';
1392
+ temp[i].date = dayjs( item?._source?.date ).format( 'D MMM, YYYY' );
1393
+ temp[i].RMName = RMName;
1394
+ temp[i].clusterName =clusterName;
1395
+ }
1396
+ logger.info( { temp: temp } );
1397
+ }
1314
1398
 
1315
- ], count: 14 } );
1399
+ return res.sendSuccess( { result: temp, count: count } );
1316
1400
  }
1317
1401
  } catch ( error ) {
1318
1402
  const err = error.message || 'Internal Server Error';
@@ -8,3 +8,7 @@ export function aggregateClusters( query ) {
8
8
  export function findClusters( query ) {
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
+ }