tango-app-api-audit 3.5.8 → 3.5.10

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.8",
3
+ "version": "3.5.10",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "mongodb": "^6.7.0",
27
27
  "nodemon": "^3.1.3",
28
28
  "swagger-ui-express": "^5.0.1",
29
- "tango-api-schema": "^2.2.113",
30
- "tango-app-api-middleware": "^3.1.78",
29
+ "tango-api-schema": "^2.2.137",
30
+ "tango-app-api-middleware": "^3.1.80",
31
31
  "winston": "^3.13.0",
32
32
  "winston-daily-rotate-file": "^5.0.0"
33
33
  },
@@ -597,6 +597,7 @@ export async function getAuditFile( req, res ) {
597
597
  },
598
598
 
599
599
  };
600
+ logger.info( { fetchData: fetchData, msg: msg, inputData: inputData, type: 'debug-bucketNameIssue' } );
600
601
  const list = msg.zone_id === 'track' ? inputData.nextId? await scrollResponse( inputData.nextId ):await searchOpenSearchData( msg.index_name, getQuery ): await listFileByPath( fetchData );
601
602
  const folderPath = msg.zone_id === 'track' ? list?.body?.hits?.hits : list.data;
602
603
  const nextQuery =msg.zone_id !== 'track' ? list.pageToken: '';
@@ -1,4 +1,4 @@
1
- import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray } from 'tango-app-api-middleware';
1
+ import { getOpenSearchData, getOpenSearchById, logger, insertOpenSearchData, updateOpenSearchData, download, chunkArray, getOpenSearchCount } from 'tango-app-api-middleware';
2
2
  import { findOneUser } from '../service/user.service.js';
3
3
  import mongoose from 'mongoose';
4
4
  import dayjs from 'dayjs';
@@ -19,7 +19,7 @@ export async function getList( req, res ) {
19
19
  const limit = inputData.limit || 10;
20
20
  const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
21
21
 
22
- const sortBy = inputData?.sortBy ? inputData.sortBy === 'coveredStepsAI'||inputData.sortBy==='updatedAt' ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
22
+ const sortBy = inputData?.sortBy ? [ 'coveredStepsAI', 'trustScore', 'date' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
23
23
  const order = inputData?.sortOrder || -1;
24
24
  let filter= [
25
25
  {
@@ -179,10 +179,11 @@ export async function getList( req, res ) {
179
179
  },
180
180
  'sort': [
181
181
  { [sortBy]: { order: order === -1 ?'desc':'asc' } },
182
+ { '_id': 'asc' },
182
183
  ],
184
+ // 'search_after': null,
183
185
  };
184
186
  }
185
-
186
187
  if ( inputData.isExport==true ) {
187
188
  searchQuery={
188
189
  'from': 0,
@@ -194,13 +195,21 @@ export async function getList( req, res ) {
194
195
  { 'storeName.keyword': { order: 'desc' } },
195
196
  ],
196
197
  };
198
+ // allResult =await fetchAllDocuments( openSearch.EyeTestInput, search );
197
199
  }
198
- const result = await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
199
- const count = result?.body?.hits?.total?.value;
200
- if ( !count || count == 0 ) {
201
- return res.sendError( 'No data found', 204 );
202
- }
203
- const searchValue = result?.body?.hits?.hits;
200
+
201
+ const countQuery = {
202
+ query: {
203
+ bool: search,
204
+ },
205
+ };
206
+ const result = offset >= 10000 ? await fetchDeepPage( openSearch.EyeTestInput, search, limit, offset, sortBy, order, inputData?.searchAfter ) : await getOpenSearchData( openSearch.EyeTestInput, searchQuery );
207
+ logger.info( { result: result } );
208
+ const getCount = inputData.isExport==true? null:await getOpenSearchCount( openSearch.EyeTestInput, countQuery );
209
+ const count =inputData.isExport==true?null: getCount?.body?.count;
210
+
211
+ const searchValue = offset >= 10000 ? result : result?.body?.hits?.hits;
212
+ logger.info( { searchValue: searchValue } );
204
213
  if ( !searchValue || searchValue?.length == 0 ) {
205
214
  return res.sendError( 'No data found', 204 );
206
215
  }
@@ -229,7 +238,7 @@ export async function getList( req, res ) {
229
238
  'Queue ID': element?._source?.queueId,
230
239
  'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
231
240
  'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
232
- 'trustScore': element?._source?.trustScore || 0,
241
+ 'Trust Score': element?._source?.trustScore || 0,
233
242
  'Visitor Type': element?._source?.visitorsType,
234
243
  'Test Duration': duration || '',
235
244
  'Audit Status': element?._source?.auditStatus || '',
@@ -245,7 +254,7 @@ export async function getList( req, res ) {
245
254
  'Engagement ID': element?._source?.engagementId,
246
255
  'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
247
256
  'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
248
- 'trustScore': element?._source?.trustScore ||0,
257
+ 'Trust Score': element?._source?.trustScore ||0,
249
258
  'Test Duration': duration || '',
250
259
  'Audit Status': element?._source?.auditStatus || '',
251
260
  'Audited By': userName?.userName || '',
@@ -284,6 +293,102 @@ export async function getList( req, res ) {
284
293
  }
285
294
  }
286
295
 
296
+ // export async function fetchAllDocuments( index, data ) {
297
+ // try {
298
+ // const pageSize = 1000; // safer chunk size
299
+ // let allHits = [];
300
+ // let searchAfter = null;
301
+ // let hasMore = true;
302
+ // let i =0;
303
+
304
+ // while ( hasMore ) {
305
+ // const body={
306
+ // size: pageSize,
307
+ // query: {
308
+ // bool: data,
309
+ // },
310
+ // sort: [
311
+ // { 'storeName.keyword': 'desc' },
312
+ // { '_id': 'asc' }, // Required for stable search_after
313
+ // ],
314
+ // };
315
+
316
+ // if ( searchAfter ) {
317
+ // body.search_after = searchAfter;
318
+ // }
319
+
320
+ // const response = await getOpenSearchData( index, body );
321
+ // const hits = response.body.hits.hits;
322
+ // i = i+hits.length;
323
+ // logger.info( { index: i, length: hits.length, msg: '........index' } );
324
+ // allHits.push( ...hits );
325
+ // if ( allHits.length >= 10000 ) {
326
+ // hasMore = false;
327
+ // } else {
328
+ // searchAfter = hits[hits.length - 1].sort;
329
+ // }
330
+ // }
331
+
332
+ // logger.info( `Fetched ${allHits.length} documents` );
333
+ // return allHits;
334
+ // } catch ( error ) {
335
+ // const err = error.message || 'Internal Server Error';
336
+ // return res.sendError( err, 500 );
337
+ // };
338
+ // };
339
+ export async function fetchDeepPage( index, data, limit, offset, sortBy, order, searchAfter1 ) {
340
+ try {
341
+ logger.info( { index: index, data: data, limit: limit, offset: offset } );
342
+ let searchAfter = searchAfter1 || null;
343
+ let currentCount = 0;
344
+ const body={
345
+ size: limit,
346
+ query: {
347
+ bool: data, // assuming your search object is here
348
+ },
349
+ sort: [
350
+ { [sortBy]: { order: order === -1 ? 'desc' : 'asc' } },
351
+ { _id: 'asc' },
352
+ ],
353
+ ...( searchAfter ? { search_after: searchAfter } : {} ),
354
+ };
355
+ logger.info( { offset: offset, limmit: limit, currentCount: currentCount } );
356
+
357
+ const response = await getOpenSearchData(
358
+ index,
359
+ body,
360
+ );
361
+
362
+ const hits = response?.body?.hits?.hits;
363
+ // while ( currentCount < offset + limit ) {
364
+ // const response = await getOpenSearchData(
365
+ // index,
366
+ // body,
367
+ // );
368
+
369
+ // const hits = response?.body?.hits?.hits;
370
+ // logger.info( { response: response } );
371
+ // if ( !hits.length || offset + limit <= i ) break;
372
+ // i = i+hits.length;
373
+ // logger.info( { hits: hits, function: '.........hits' } );
374
+ // currentCount += hits.length;
375
+ // searchAfter = hits[hits.length - 1].sort;
376
+ // logger.info( { searchAfter: searchAfter } );
377
+ // // Only keep the target range
378
+ // const startIndex = Math.max( 0, hits.length - ( currentCount - offset ) );
379
+ // const sliced = hits.slice( startIndex, startIndex + limit );
380
+ // if ( currentCount >= offset ) {
381
+ // finalResults.push( ...sliced );
382
+ // }
383
+ // }
384
+ return hits;
385
+ } catch ( error ) {
386
+ const err = error.message || 'Internal Server Error';
387
+ logger.error( { error: error, function: 'fetchDeepPage' } );
388
+ return err;
389
+ }
390
+ }
391
+
287
392
  export async function viewFile( req, res ) {
288
393
  try {
289
394
  const inputData = req.params;
@@ -26,6 +26,7 @@ export const getListSchema = joi.object(
26
26
  isExport: joi.boolean().optional(),
27
27
  sortBy: joi.string().optional(),
28
28
  sortOrder: joi.number().optional(),
29
+ searchAfter: joi.array().optional(),
29
30
  },
30
31
  );
31
32