tango-app-api-audit 3.5.28 → 3.5.30

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.28",
3
+ "version": "3.5.30",
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: {
@@ -1175,7 +1199,7 @@ export async function summaryList( req, res ) {
1175
1199
  {
1176
1200
  $group: {
1177
1201
  _id: '$Teamlead.email',
1178
- clusterName: { $first: '$clusterName' },
1202
+ clusterName: { $addToSet: '$clusterName' },
1179
1203
  RMName: { $first: '$Teamlead.email' },
1180
1204
  store: { $addToSet: '$stores.storeId' },
1181
1205
 
@@ -1183,8 +1207,27 @@ export async function summaryList( req, res ) {
1183
1207
  },
1184
1208
  { $project: {
1185
1209
  RMName: 1,
1186
- clusterName: 1,
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
  ];
@@ -1237,7 +1280,6 @@ export async function summaryList( req, res ) {
1237
1280
  },
1238
1281
  };
1239
1282
  const getResponse = await getOpenSearchData( openSearch.EyeTestInput, getClusterQuery );
1240
- logger.info( { getResponse: getResponse } );
1241
1283
  if ( getResponse?.body?.aggregations ) {
1242
1284
  delete temp[i].store;
1243
1285
  delete temp[i]._id;
@@ -1245,11 +1287,47 @@ export async function summaryList( req, res ) {
1245
1287
  temp[i].completedFiles=getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 0;
1246
1288
  temp[i].complianceScore = getResponse?.body?.aggregations?.avg_complianceScore?.value || 0;
1247
1289
  temp[i].trustScore =getResponse?.body?.aggregations?.audited_trustScore?.totalCount?.value || 'NA';
1248
- logger.info( { getResponse: getResponse, ms: '........1' } );
1249
1290
  }
1250
1291
  }
1251
1292
 
1252
- return res.sendSuccess( { result: temp, count: getCluster?.length || 0 } );
1293
+ if ( inputData.isExport == true ) {
1294
+ const chunkedMappingData = await chunkArray( temp, 10 );
1295
+ const promises = chunkedMappingData.map( async ( chunk ) => {
1296
+ const exportData = [];
1297
+ for ( const element of chunk ) {
1298
+ if ( inputData?.keyType == 'rm' ) {
1299
+ exportData.push( {
1300
+ 'RM Name': element?.RMName,
1301
+ 'Cluster Count': element?.clusterCount,
1302
+ 'Store Count': element?.storesCount,
1303
+ 'Total Tango AI Files': element.totalFiles,
1304
+ 'Trust Audit Completed': element.completedFiles,
1305
+ 'Tango Score': element?.complianceScores || 0,
1306
+ 'Trust Score': element?.trustScore || '--',
1307
+
1308
+
1309
+ } );
1310
+ } else {
1311
+ exportData.push( {
1312
+ 'Cluster Name': element?.clusterName,
1313
+ 'Store Count': element?.storesCount,
1314
+ 'Total Tango AI Files': element.totalFiles,
1315
+ 'Trust Audit Completed': element.completedFiles,
1316
+ 'Tango Score': element?.complianceScores || 0,
1317
+ 'Trust Score': element?.trustScore || '--',
1318
+
1319
+ } );
1320
+ }
1321
+ }
1322
+ return exportData;
1323
+ } );
1324
+ const mappedArrays = await Promise.all( promises );
1325
+ const result = mappedArrays.flat();
1326
+ await download( result, res );
1327
+ return;
1328
+ } else {
1329
+ return res.sendSuccess( { result: temp, count: getCluster?.length || 0 } );
1330
+ }
1253
1331
  } else {
1254
1332
  let search ={
1255
1333
  'must': filter,