tango-app-api-audit 3.5.29 → 3.5.31

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.29",
3
+ "version": "3.5.31",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1118,6 +1118,17 @@ export async function summaryList( req, res ) {
1118
1118
 
1119
1119
  } );
1120
1120
  }
1121
+ if ( inputData.complianceScore && inputData.complianceScore!= null ) {
1122
+ logger.info( { complsc: inputData.complianceScore } );
1123
+ filter.push( {
1124
+ range: {
1125
+ 'ComplianceScore': {
1126
+ lt: inputData.complianceScore,
1127
+ },
1128
+ },
1129
+
1130
+ } );
1131
+ }
1121
1132
  if ( inputData.storeId && inputData.storeId.length > 0 ) {
1122
1133
  filter.push( {
1123
1134
 
@@ -1132,6 +1143,15 @@ export async function summaryList( req, res ) {
1132
1143
 
1133
1144
 
1134
1145
  if ( inputData.keyType === 'rm' || inputData.keyType === 'cluster' ) {
1146
+ let sort ={
1147
+ _id: -1,
1148
+ };
1149
+ if ( inputData?.sortBy ) {
1150
+ const sortOrder = inputData?.sortOrder || -1;
1151
+ sort={
1152
+ [inputData?.sortBy]: sortOrder,
1153
+ };
1154
+ }
1135
1155
  const clusterQuery =[
1136
1156
  { $match: {
1137
1157
  $and: [
@@ -1157,6 +1177,10 @@ export async function summaryList( req, res ) {
1157
1177
  storesCount: { $size: '$store' },
1158
1178
  store: 1,
1159
1179
  } },
1180
+ {
1181
+ $sort: sort,
1182
+ },
1183
+
1160
1184
  ];
1161
1185
  const RMQuery =[
1162
1186
  { $match: {
@@ -1183,11 +1207,53 @@ export async function summaryList( req, res ) {
1183
1207
  },
1184
1208
  { $project: {
1185
1209
  RMName: 1,
1186
- clusterCount: { $size: '$clusterName' },
1187
- storesCount: { $size: '$store' },
1210
+ clusterCount1: { $size: '$clusterName' },
1211
+ storesCount1: { $size: '$store' },
1212
+ store: 1,
1213
+ } },
1214
+ {
1215
+ $addFields: {
1216
+ clusterCount: { $toInt: '$clusterCount1' },
1217
+ },
1218
+ },
1219
+ {
1220
+ $addFields: {
1221
+ storesCount: { $toInt: '$storesCount1' },
1222
+ },
1223
+ },
1224
+ {
1225
+ $sort: sort,
1226
+ },
1227
+ { $project: {
1228
+ RMName: 1,
1229
+ clusterCount: 1,
1230
+ storesCount: 1,
1188
1231
  store: 1,
1189
1232
  } },
1190
1233
  ];
1234
+ const getcount = await aggregateClusters( inputData.keyType === 'rm'?RMQuery: clusterQuery );
1235
+ const count = getcount?.length || 0;
1236
+ if ( count == 0 ) {
1237
+ return res.sendError( 'No data', 204 );
1238
+ }
1239
+ if ( inputData.isExport === false || !inputData.isExport ) {
1240
+ RMQuery.push(
1241
+ {
1242
+ $skip: offset,
1243
+ },
1244
+ {
1245
+ $limit: limit,
1246
+ },
1247
+ );
1248
+ clusterQuery.push(
1249
+ {
1250
+ $skip: offset,
1251
+ },
1252
+ {
1253
+ $limit: limit,
1254
+ },
1255
+ );
1256
+ }
1191
1257
  const getCluster = await aggregateClusters( inputData.keyType === 'rm'?RMQuery: clusterQuery );
1192
1258
  logger.info( { getCluster: getCluster } );
1193
1259
  if ( !getCluster || getCluster?.length == 0 ) {
@@ -1237,7 +1303,6 @@ export async function summaryList( req, res ) {
1237
1303
  },
1238
1304
  };
1239
1305
  const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
1240
- logger.info( { getResponse: getResponse } );
1241
1306
  if ( getResponse?.body?.aggregations ) {
1242
1307
  delete temp[i].store;
1243
1308
  delete temp[i]._id;
@@ -1245,11 +1310,47 @@ export async function summaryList( req, res ) {
1245
1310
  temp[i].completedFiles=getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 0;
1246
1311
  temp[i].complianceScore = getResponse?.body?.aggregations?.avg_complianceScore?.value || 0;
1247
1312
  temp[i].trustScore =getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 'NA';
1248
- logger.info( { getResponse: getResponse, ms: '........1' } );
1249
1313
  }
1250
1314
  }
1251
1315
 
1252
- return res.sendSuccess( { result: temp, count: getCluster?.length || 0 } );
1316
+ if ( inputData.isExport == true ) {
1317
+ const chunkedMappingData = await chunkArray( temp, 10 );
1318
+ const promises = chunkedMappingData.map( async ( chunk ) => {
1319
+ const exportData = [];
1320
+ for ( const element of chunk ) {
1321
+ if ( inputData?.keyType == 'rm' ) {
1322
+ exportData.push( {
1323
+ 'RM Name': element?.RMName,
1324
+ 'Cluster Count': element?.clusterCount,
1325
+ 'Store Count': element?.storesCount,
1326
+ 'Total Tango AI Files': element.totalFiles,
1327
+ 'Trust Audit Completed': element.completedFiles,
1328
+ 'Tango Score': element?.complianceScores || 0,
1329
+ 'Trust Score': element?.trustScore || '--',
1330
+
1331
+
1332
+ } );
1333
+ } else {
1334
+ exportData.push( {
1335
+ 'Cluster Name': element?.clusterName,
1336
+ 'Store Count': element?.storesCount,
1337
+ 'Total Tango AI Files': element.totalFiles,
1338
+ 'Trust Audit Completed': element.completedFiles,
1339
+ 'Tango Score': element?.complianceScores || 0,
1340
+ 'Trust Score': element?.trustScore || '--',
1341
+
1342
+ } );
1343
+ }
1344
+ }
1345
+ return exportData;
1346
+ } );
1347
+ const mappedArrays = await Promise.all( promises );
1348
+ const result = mappedArrays.flat();
1349
+ await download( result, res );
1350
+ return;
1351
+ } else {
1352
+ return res.sendSuccess( { result: temp, count: count || 0 } );
1353
+ }
1253
1354
  } else {
1254
1355
  let search ={
1255
1356
  'must': filter,