tango-app-api-audit 3.5.7 → 3.5.9

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.7",
3
+ "version": "3.5.9",
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
  },
@@ -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,6 +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,
241
+ 'Trust Score': element?._source?.trustScore || 0,
232
242
  'Visitor Type': element?._source?.visitorsType,
233
243
  'Test Duration': duration || '',
234
244
  'Audit Status': element?._source?.auditStatus || '',
@@ -242,8 +252,9 @@ export async function getList( req, res ) {
242
252
  'Store ID': element?._source?.storeId || 'Un Assigned',
243
253
  'Store Name': element?._source?.storeName ||'Un Assigned',
244
254
  'Engagement ID': element?._source?.engagementId,
245
- 'Compliance Score': element?._source?.complianceScore || 0,
255
+ 'Compliance Score': element?._source?.totalSteps>0 ? Math.round( ( element?._source?.coveredStepsAI/ element?._source?.totalSteps )*100 ): 0,
246
256
  'Steps Covered By AI': element?._source?.coveredStepsAI || 0,
257
+ 'Trust Score': element?._source?.trustScore ||0,
247
258
  'Test Duration': duration || '',
248
259
  'Audit Status': element?._source?.auditStatus || '',
249
260
  'Audited By': userName?.userName || '',
@@ -282,6 +293,102 @@ export async function getList( req, res ) {
282
293
  }
283
294
  }
284
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
+
285
392
  export async function viewFile( req, res ) {
286
393
  try {
287
394
  const inputData = req.params;
@@ -1592,6 +1592,7 @@ export async function saveBinary( req, res ) {
1592
1592
  formData.append( 'question', `Please upload the QR image pasted in this clinic-${req.userAudit?.streamName}` );
1593
1593
  formData.append( 'scheduleDate', formattedDate );
1594
1594
  formData.append( 'scheduleEndTime', '11:00 PM' );
1595
+ formData.append( 'streamId', req.userAudit?.streamName );
1595
1596
 
1596
1597
  formData.append( 'referenceImage', img.Body );
1597
1598
  const response = await axios.post( `${url.apiDomain}/v3/task/eyeTesttask`, formData, { headers: {
@@ -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