tango-app-api-audit 3.6.43 → 3.6.45

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.6.43",
3
+ "version": "3.6.45",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,17 +25,32 @@ export async function getList( req, res ) {
25
25
 
26
26
  const sortBy = inputData?.sortBy ? [ 'coveredStepsAI', 'trustScore', 'date' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
27
27
  const order = inputData?.sortOrder || -1;
28
- let filter= [
29
- {
30
- 'range': {
31
- 'date': {
32
- 'gte': new Date( inputData.fromDate ),
33
- 'lte': new Date( inputData.toDate ),
28
+ let filter;
29
+ if ( dateType === 'auditedDate' ) {
30
+ filter= [
31
+ {
32
+ 'range': {
33
+ 'updatedAt': {
34
+ 'gte': new Date( inputData.fromDate ),
35
+ 'lte': new Date( inputData.toDate ),
36
+ },
34
37
  },
35
38
  },
36
- },
37
39
 
38
- ];
40
+ ];
41
+ } else {
42
+ filter= [
43
+ {
44
+ 'range': {
45
+ 'date': {
46
+ 'gte': new Date( inputData.fromDate ),
47
+ 'lte': new Date( inputData.toDate ),
48
+ },
49
+ },
50
+ },
51
+
52
+ ];
53
+ }
39
54
 
40
55
 
41
56
  if ( inputData.demographics && inputData.demographics.length > 0 ) {
@@ -298,49 +313,7 @@ export async function getList( req, res ) {
298
313
  }
299
314
  }
300
315
 
301
- // export async function fetchAllDocuments( index, data ) {
302
- // try {
303
- // const pageSize = 1000; // safer chunk size
304
- // let allHits = [];
305
- // let searchAfter = null;
306
- // let hasMore = true;
307
- // let i =0;
308
-
309
- // while ( hasMore ) {
310
- // const body={
311
- // size: pageSize,
312
- // query: {
313
- // bool: data,
314
- // },
315
- // sort: [
316
- // { 'storeName.keyword': 'desc' },
317
- // { '_id': 'asc' }, // Required for stable search_after
318
- // ],
319
- // };
320
-
321
- // if ( searchAfter ) {
322
- // body.search_after = searchAfter;
323
- // }
324
-
325
- // const response = await getOpenSearchData( index, body );
326
- // const hits = response.body.hits.hits;
327
- // i = i+hits.length;
328
- // logger.info( { index: i, length: hits.length, msg: '........index' } );
329
- // allHits.push( ...hits );
330
- // if ( allHits.length >= 50000 ) {
331
- // hasMore = false;
332
- // } else {
333
- // searchAfter = hits[hits.length - 1].sort;
334
- // }
335
- // }
336
-
337
- // logger.info( `Fetched ${allHits.length} documents` );
338
- // return allHits;
339
- // } catch ( error ) {
340
- // const err = error.message || 'Internal Server Error';
341
- // return res.sendError( err, 500 );
342
- // };
343
- // };
316
+
344
317
  export async function fetchDeepPage( index, data, limit, offset, sortBy, order, searchAfter1 ) {
345
318
  try {
346
319
  logger.info( { index: index, data: data, limit: limit, offset: offset } );
@@ -365,27 +338,6 @@ export async function fetchDeepPage( index, data, limit, offset, sortBy, order,
365
338
  );
366
339
 
367
340
  const hits = response?.body?.hits?.hits;
368
- // while ( currentCount < offset + limit ) {
369
- // const response = await getOpenSearchData(
370
- // index,
371
- // body,
372
- // );
373
-
374
- // const hits = response?.body?.hits?.hits;
375
- // logger.info( { response: response } );
376
- // if ( !hits.length || offset + limit <= i ) break;
377
- // i = i+hits.length;
378
- // logger.info( { hits: hits, function: '.........hits' } );
379
- // currentCount += hits.length;
380
- // searchAfter = hits[hits.length - 1].sort;
381
- // logger.info( { searchAfter: searchAfter } );
382
- // // Only keep the target range
383
- // const startIndex = Math.max( 0, hits.length - ( currentCount - offset ) );
384
- // const sliced = hits.slice( startIndex, startIndex + limit );
385
- // if ( currentCount >= offset ) {
386
- // finalResults.push( ...sliced );
387
- // }
388
- // }
389
341
  return hits;
390
342
  } catch ( error ) {
391
343
  const err = error.message || 'Internal Server Error';
@@ -1460,21 +1412,36 @@ export async function summaryList( req, res ) {
1460
1412
  const limit = inputData.limit || 10;
1461
1413
  const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
1462
1414
 
1463
- const sortBy = inputData?.sortBy ? [ 'coveredStepsAI', 'trustScore', 'date', 'ComplianceScore', 'auditedSteps' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
1415
+ const sortBy = inputData?.sortBy ? inputData?.sortBy === 'auditedDate'? 'updatedAt': [ 'coveredStepsAI', 'trustScore', 'date', 'ComplianceScore', 'auditedSteps' ].includes( inputData.sortBy ) ? inputData.sortBy :`${inputData.sortBy}.keyword` : 'storeName.keyword';
1464
1416
  const order = inputData?.sortOrder || -1;
1465
1417
 
1466
1418
  // declare filter and assign range values from inputData
1467
- let filter= [
1468
- {
1469
- 'range': {
1470
- 'date': {
1471
- 'gte': new Date( inputData.fromDate ),
1472
- 'lte': new Date( inputData.toDate ),
1419
+ let filter;
1420
+ if ( inputData?.dateType === 'auditedDate' ) {
1421
+ filter= [
1422
+ {
1423
+ 'range': {
1424
+ 'updatedAt': {
1425
+ 'gte': new Date( inputData.fromDate ),
1426
+ 'lte': new Date( inputData.toDate ),
1427
+ },
1473
1428
  },
1474
1429
  },
1475
- },
1476
1430
 
1477
- ];
1431
+ ];
1432
+ } else {
1433
+ filter= [
1434
+ {
1435
+ 'range': {
1436
+ 'date': {
1437
+ 'gte': new Date( inputData.fromDate ),
1438
+ 'lte': new Date( inputData.toDate ),
1439
+ },
1440
+ },
1441
+ },
1442
+
1443
+ ];
1444
+ }
1478
1445
 
1479
1446
  // filter by Audit Status if key has minimum one element
1480
1447
  if ( inputData?.auditStatus && inputData?.auditStatus?.length > 0 ) {
@@ -2388,15 +2355,9 @@ export async function summaryCard( req, res ) {
2388
2355
  const inputData = req.body;
2389
2356
  const openSearch = JSON.parse( process.env.OPENSEARCH );
2390
2357
 
2358
+
2391
2359
  let filter =[
2392
- {
2393
- 'range': {
2394
- 'date': {
2395
- 'gte': new Date( inputData.fromDate ),
2396
- 'lte': new Date( inputData.toDate ),
2397
- },
2398
- },
2399
- },
2360
+
2400
2361
  {
2401
2362
  term: {
2402
2363
  'type.keyword': inputData?.type,
@@ -2408,6 +2369,33 @@ export async function summaryCard( req, res ) {
2408
2369
  },
2409
2370
  },
2410
2371
  ];
2372
+
2373
+ if ( inputData?.dateType === 'auditedDate' ) {
2374
+ filter.push(
2375
+ {
2376
+ 'range': {
2377
+ 'updatedAt': {
2378
+ 'gte': new Date( inputData.fromDate ),
2379
+ 'lte': new Date( inputData.toDate ),
2380
+ },
2381
+ },
2382
+ },
2383
+
2384
+ );
2385
+ } else {
2386
+ filter.push(
2387
+ {
2388
+ 'range': {
2389
+ 'date': {
2390
+ 'gte': new Date( inputData.fromDate ),
2391
+ 'lte': new Date( inputData.toDate ),
2392
+ },
2393
+ },
2394
+ },
2395
+
2396
+ );
2397
+ }
2398
+
2411
2399
  if ( inputData?.demographics && inputData?.demographics?.length > 0 ) {
2412
2400
  filter.push( {
2413
2401
  terms: {
@@ -3,6 +3,7 @@ import dayjs from 'dayjs';
3
3
 
4
4
  export const getListSchema = joi.object(
5
5
  {
6
+ dateType: joi.string().optional().valid( 'fileDate', 'auditedDate' ),
6
7
  fromDate: joi.string().required().messages( {
7
8
  'any.required': 'From Date is required',
8
9
  'string.empty': 'From Date cannot be empty',
@@ -101,6 +102,7 @@ export const userAuditedDataValid = {
101
102
  };
102
103
 
103
104
  export const summaryListSchema = joi.object( {
105
+ dateType: joi.string().optional().valid( 'fileDate', 'auditedDate' ),
104
106
  keyType: joi.string()
105
107
  .valid( 'rm', 'cluster', 'store' )
106
108
  .required()
@@ -174,7 +176,7 @@ export const summaryListValid = {
174
176
 
175
177
 
176
178
  export const summaryCardSchema = joi.object( {
177
-
179
+ dateType: joi.string().optional().valid( 'fileDate', 'auditedDate' ),
178
180
  fromDate: joi.string()
179
181
  .pattern( /^\d{4}-\d{2}-\d{2}$/, 'YYYY-MM-DD format' )
180
182
  .required()