tango-app-api-audit 3.4.3-alpha.1 → 3.4.3-alpha.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.4.3-alpha.1",
3
+ "version": "3.4.3-alpha.10",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -9,6 +9,7 @@ import {
9
9
  signedUrl,
10
10
  getDate, getDateWithCustomizeTime,
11
11
  getUTC,
12
+ getOpenSearchData,
12
13
  } from 'tango-app-api-middleware';
13
14
  import {
14
15
  aggregateUserAudit,
@@ -3567,6 +3568,43 @@ export async function totalNotAssignedCount( req, res ) {
3567
3568
  },
3568
3569
  },
3569
3570
  ];
3571
+
3572
+ const mappingInprogressCount = [
3573
+ {
3574
+ $match: {
3575
+ fileDate: { $eq: latestTraxDate },
3576
+ },
3577
+ },
3578
+ {
3579
+ $project: {
3580
+ inprogressAuditCount: {
3581
+ $cond: [
3582
+ { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
3583
+ ],
3584
+ },
3585
+ inprogressTraxCount: {
3586
+ $cond: [
3587
+ { $and: [ { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
3588
+ ],
3589
+ },
3590
+
3591
+ },
3592
+ },
3593
+ {
3594
+ $group: {
3595
+ _id: null,
3596
+ inprogressAuditCount: { $sum: '$inprogressAuditCount' },
3597
+ inprogressTraxCount: { $sum: '$inprogressTraxCount' },
3598
+ },
3599
+ },
3600
+ {
3601
+ $project: {
3602
+ _id: 0,
3603
+ inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
3604
+ inprogressTraxCount: { $ifNull: [ '$inprogressTraxCount', 0 ] },
3605
+ },
3606
+ },
3607
+ ];
3570
3608
  // const binaryInprogressCount=[
3571
3609
  // {
3572
3610
  // $match: {
@@ -3651,6 +3689,8 @@ export async function totalNotAssignedCount( req, res ) {
3651
3689
  const getTotalTraxAudit = await aggregateTraxAuditData( traxQuery );
3652
3690
  const getInprogressCount = await aggregateStoreAudit( inprogressCount );
3653
3691
  const getBinaryInprogressCount = await aggregateBinaryAudit( binaryInprogressCount );
3692
+ const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
3693
+ logger.info( { getMappingInprogressCount: getMappingInprogressCount } );
3654
3694
  // const getMappingInprogressCount = await aggregateStoreEmpDetection( mappingInprogressCount );
3655
3695
  if ( getTotalcount.length == 0 && getTotalTraxAudit.length == 0 ) {
3656
3696
  return res.sendError( 'No Data Found', 204 );
@@ -3671,6 +3711,12 @@ export async function totalNotAssignedCount( req, res ) {
3671
3711
  } else {
3672
3712
  notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
3673
3713
  }
3714
+
3715
+ if ( getMappingInprogressCount.length > 0 ) {
3716
+ notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0].totalTraxAuditCount > getMappingInprogressCount[0].inprogressTraxCount ? getTotalTraxAudit[0].totalTraxAuditCount - getMappingInprogressCount[0].inprogressTraxCount : 0;
3717
+ } else {
3718
+ notAssignedCount.totalTraxAuditCount = getTotalTraxAudit[0]?.totalTraxAuditCount;
3719
+ }
3674
3720
  return res.sendSuccess( { result: notAssignedCount } );
3675
3721
  } catch ( error ) {
3676
3722
  const err = error.message || 'Internal Server Error';
@@ -4302,3 +4348,39 @@ export async function getUserAuditCountMTD( req, res ) {
4302
4348
  }
4303
4349
  }
4304
4350
 
4351
+ export async function auditViewLogs( req, res ) {
4352
+ try {
4353
+ const inputData = req.query;
4354
+ const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
4355
+ let downTimeQuery = {
4356
+ 'size': 100,
4357
+ 'query': {
4358
+ 'bool': {
4359
+ 'must': [
4360
+ {
4361
+ 'term': {
4362
+ 'doc.logData.fileDate.keyword': dayjs( inputData.fileDate ).format( 'DD-MM-YYYY' ),
4363
+ },
4364
+ },
4365
+ {
4366
+ 'term': {
4367
+ 'doc.logData.storeId.keyword': inputData.storeId,
4368
+ },
4369
+ },
4370
+ {
4371
+ 'term': {
4372
+ 'doc.logData.moduleType.keyword': inputData.moduleType,
4373
+ },
4374
+ },
4375
+ ],
4376
+
4377
+ },
4378
+ },
4379
+ };
4380
+ const downtime = await getOpenSearchData( parsedOpenSearch.auditLog, downTimeQuery );
4381
+ return res.sendSuccess( downtime );
4382
+ } catch ( err ) {
4383
+
4384
+ }
4385
+ }
4386
+
@@ -4,16 +4,19 @@ import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
5
5
  import { aggregateUserEmpDetection, createUserEmpDetection, updateOneUserEmpDetection } from '../service/userEmpDetection.service.js';
6
6
  import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
7
- import { aggregateClient } from '../service/client.service.js';
7
+ import { aggregateClient, findOneClient } from '../service/client.service.js';
8
8
  import dayjs from 'dayjs';
9
9
  import { aggregateAssignAudit } from '../service/assignAudit.service.js';
10
- import { aggregateStoreEmpDetection, updateManyStoreEmpDetection } from '../service/storeEmpDetection.service.js';
11
- import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
10
+ import { aggregateStoreEmpDetection, updateManyStoreEmpDetection, updateOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
11
+ import { listQueue, sendMessageToQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
12
12
  import _ from 'lodash';
13
13
  import mongoose from 'mongoose';
14
- import { findOneAuditLog } from '../service/auditLog.service.js';
15
-
16
-
14
+ import { findOneAuditLog, createAuditLog,
15
+ } from '../service/auditLog.service.js';
16
+ import {
17
+ findOneUserEmpDetection,
18
+ } from '../service/userEmpDetection.service.js';
19
+ import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.service.js';
17
20
  // export async function getDetectionAuditFile( req, res ) {
18
21
  // try {
19
22
  // const bucket = JSON.parse( process.env.BUCKET );
@@ -334,13 +337,13 @@ import { findOneAuditLog } from '../service/auditLog.service.js';
334
337
  // const data = await signedUrl( fetchData );
335
338
  // const mapimg = {
336
339
  // img_path: data,
337
- // img_name: image[0],
338
- // img_id: indexes[1],
340
+ // img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
341
+ // img_id: img[3],
339
342
  // };
340
343
  // files.push( {
341
344
  // img_path: data,
342
- // img_name: image[0],
343
- // img_id: indexes[1],
345
+ // img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
346
+ // img_id: img[3],
344
347
  // selected: false,
345
348
  // dropped: false,
346
349
  // count: 1,
@@ -742,7 +745,7 @@ export async function workSpace( req, res ) {
742
745
  },
743
746
  ];
744
747
 
745
- logger.info( { moduleType: inputData.moduleType, key: inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] ), dateStart: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ), end: dateRange.end, user: req.user._id, client: clientList } );
748
+ logger.info( { moduleType: inputData.moduleType, key: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ), dateStart: new Date( dayjs( fileDate ).format( 'YYYY-MM-DD' ) ), end: dateRange.end, user: req.user._id, client: clientList } );
746
749
 
747
750
  const userAsignAudit = [
748
751
  {
@@ -796,11 +799,11 @@ export async function workSpace( req, res ) {
796
799
  },
797
800
  ];
798
801
 
799
- const auditUserCount = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
800
- const userIncompleteFilesCount = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
802
+ const auditUserCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
803
+ const userIncompleteFilesCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
801
804
  logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
802
805
  const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
803
- const completedStoresCount = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
806
+ const completedStoresCount = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
804
807
  const clientAssignedCount = await aggregateAssignAudit( clientAssign );
805
808
  const auditStoreData = await aggregateTraxAuditData(
806
809
  auditStoreDataQuery,
@@ -1697,7 +1700,7 @@ export async function userAuditHistory( req, res ) {
1697
1700
  },
1698
1701
  );
1699
1702
  }
1700
- const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1703
+ const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1701
1704
  if ( count.length == 0 ) {
1702
1705
  return res.sendError( 'No Data Found', 204 );
1703
1706
  }
@@ -1767,7 +1770,7 @@ export async function userAuditHistory( req, res ) {
1767
1770
  {
1768
1771
  $limit: limit,
1769
1772
  } );
1770
- const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1773
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1771
1774
 
1772
1775
  return res.sendSuccess( { result: result, count: count.length } );
1773
1776
  } catch ( error ) {
@@ -1919,6 +1922,125 @@ export async function clientMetrics( req, res ) {
1919
1922
  },
1920
1923
  ];
1921
1924
 
1925
+ const MappingQuery =[
1926
+ {
1927
+ $match: {
1928
+ $and: filter,
1929
+ },
1930
+ },
1931
+ {
1932
+ $group: {
1933
+ _id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
1934
+ fileDate: { $last: '$fileDate' },
1935
+ clientId: { $last: '$clientId' },
1936
+ clientName: { $last: '$clientName' },
1937
+ moduleType: { $last: '$moduleType' },
1938
+ installedStore: { $last: '$installedStore' },
1939
+ queueName: { $last: '$queueName' },
1940
+ totalFilesCount: { $sum: 1 },
1941
+ },
1942
+ },
1943
+ {
1944
+ $project: {
1945
+ fileDate: 1,
1946
+ clientId: 1,
1947
+ clientName: 1,
1948
+ queueName: 1,
1949
+ installedStore: 1,
1950
+ totalFilesCount: 1,
1951
+ moduleType: 1,
1952
+ notAssignedCount: { $ifNull: [ 0, 0 ] },
1953
+ clientStatus: { $ifNull: [ '', '' ] },
1954
+ },
1955
+ },
1956
+ {
1957
+ $lookup: {
1958
+ 'from': 'storeEmpDetection',
1959
+ 'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
1960
+ 'pipeline': [
1961
+
1962
+ {
1963
+ $match: {
1964
+ $expr: {
1965
+ $and: storeAuditFilter,
1966
+ },
1967
+ },
1968
+ },
1969
+ {
1970
+ $project: {
1971
+ completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
1972
+ notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
1973
+ inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
1974
+ },
1975
+ },
1976
+ {
1977
+ $group: {
1978
+ _id: { clientId: '$clientId', fileDate: '$fileDate' },
1979
+ completedStores: { $sum: '$completedStores' },
1980
+ inprogressStores: { $sum: '$inprogressStores' },
1981
+ notAssignedStores: { $sum: '$notAssignedStores' },
1982
+ fileCount: { $sum: 1 },
1983
+ },
1984
+ },
1985
+ {
1986
+ $project: {
1987
+ _id: 0,
1988
+ completedStores: 1,
1989
+ inprogressStores: 1,
1990
+ notAssignedStores: 1,
1991
+ fileCount: { $ifNull: [ '$fileCount', 0 ] },
1992
+ completionPercentage: { $ifNull: [
1993
+ {
1994
+ $round: [ {
1995
+ $multiply: [
1996
+ 100, {
1997
+ $divide: [
1998
+ '$completedStores', '$$totalAuditFiles',
1999
+ ],
2000
+ },
2001
+ ],
2002
+ }, 1 ],
2003
+
2004
+ },
2005
+ 0,
2006
+ ],
2007
+ },
2008
+ },
2009
+ },
2010
+ ], 'as': 'binaryAudit',
2011
+ },
2012
+ },
2013
+ {
2014
+ $unwind: {
2015
+ path: '$binaryAudit',
2016
+ preserveNullAndEmptyArrays: true,
2017
+ },
2018
+ },
2019
+ {
2020
+ $project: {
2021
+ _id: 0,
2022
+ fileDate: 1,
2023
+ clientId: 1,
2024
+ clientName: 1,
2025
+ totalFilesCount: 1,
2026
+ moduleType: 1,
2027
+ value: {
2028
+ $replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
2029
+ },
2030
+ installedStore: 1,
2031
+ // notAssignedStores: '$binaryAudit.notAssignedStores',
2032
+ inprogressStoresCount: '$binaryAudit.inprogressStores',
2033
+ // fileCount: '$binaryAudit.fileCount',
2034
+ notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
2035
+ clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
2036
+ completedStores: '$binaryAudit.completedStores',
2037
+ completionPercentage: '$binaryAudit.completionPercentage',
2038
+
2039
+ },
2040
+ },
2041
+ ];
2042
+
2043
+
1922
2044
  if ( inputData?.filterByStatus?.length> 0 ) {
1923
2045
  query.push(
1924
2046
  {
@@ -1950,7 +2072,7 @@ export async function clientMetrics( req, res ) {
1950
2072
  );
1951
2073
  }
1952
2074
 
1953
- const count = await aggregateTraxAuditData( query );
2075
+ const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
1954
2076
  logger.info( { count: count } );
1955
2077
  if ( count.length == 0 ) {
1956
2078
  return res.sendError( 'No Data Found', 204 );
@@ -1983,7 +2105,7 @@ export async function clientMetrics( req, res ) {
1983
2105
  }
1984
2106
 
1985
2107
  logger.info( { query: query } );
1986
- const result = await aggregateTraxAuditData( query );
2108
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
1987
2109
  if ( result.length == 0 ) {
1988
2110
  return res.sendError( 'No Data Found', 204 );
1989
2111
  }
@@ -2426,7 +2548,9 @@ export async function storeMetrics( req, res ) {
2426
2548
  },
2427
2549
  );
2428
2550
  }
2429
- const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2551
+ logger.info( { keyss: [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType ) } );
2552
+ const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
2553
+
2430
2554
 
2431
2555
  if ( count.length == 0 ) {
2432
2556
  return res.sendError( 'No data Found', 204 );
@@ -2441,7 +2565,7 @@ export async function storeMetrics( req, res ) {
2441
2565
  } else {
2442
2566
  query.push( { $limit: 10000 } );
2443
2567
  }
2444
- const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2568
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2445
2569
  if ( inputData.isExport ) {
2446
2570
  const exportdata = [];
2447
2571
  result.forEach( ( element ) => {
@@ -2744,7 +2868,7 @@ export async function userMetrics( req, res ) {
2744
2868
  );
2745
2869
  }
2746
2870
 
2747
- const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2871
+ const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2748
2872
  if ( count.length == 0 ) {
2749
2873
  return res.sendError( 'No Data Found', 204 );
2750
2874
  }
@@ -2778,7 +2902,7 @@ export async function userMetrics( req, res ) {
2778
2902
  'Product Type': '$value',
2779
2903
  // 'Mapping Percentage': '$mappingPerc',
2780
2904
  };
2781
- inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?
2905
+ [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?
2782
2906
  query.push(
2783
2907
  {
2784
2908
  $project: detection,
@@ -2792,7 +2916,7 @@ export async function userMetrics( req, res ) {
2792
2916
  }
2793
2917
 
2794
2918
 
2795
- const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2919
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2796
2920
  if ( inputData.isExport ) {
2797
2921
  await download( result, res );
2798
2922
  return;
@@ -2936,7 +3060,7 @@ export async function pendingSummaryTable( req, res ) {
2936
3060
  },
2937
3061
  );
2938
3062
  }
2939
- const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3063
+ const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2940
3064
  if ( count.length == 0 ) {
2941
3065
  return res.sendError( 'No Data Found', 204 );
2942
3066
  }
@@ -2952,7 +3076,7 @@ export async function pendingSummaryTable( req, res ) {
2952
3076
  } );
2953
3077
  }
2954
3078
 
2955
- const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3079
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2956
3080
  if ( inputData.isExport ) {
2957
3081
  const exportdata = [];
2958
3082
  result.forEach( ( element ) => {
@@ -3146,7 +3270,7 @@ export async function overAllAuditSummary( req, res ) {
3146
3270
  },
3147
3271
  ];
3148
3272
 
3149
- const storeAudit = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
3273
+ const storeAudit = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
3150
3274
  if ( storeAudit.length > 0 ) {
3151
3275
  temp.inprogressStores= storeAudit[0].inprogressStores;
3152
3276
  temp.completedStores = storeAudit[0].completedStores;
@@ -3277,7 +3401,7 @@ export async function summarySplit( req, res ) {
3277
3401
  },
3278
3402
  },
3279
3403
  ];
3280
- const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
3404
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3281
3405
  const totalCount = await aggregateTraxAuditData( totalQuery );
3282
3406
  result[0].totalCount = totalCount[0]?.total;
3283
3407
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
@@ -3424,7 +3548,7 @@ export async function overviewTable( req, res ) {
3424
3548
  },
3425
3549
  );
3426
3550
  }
3427
- const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3551
+ const count = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3428
3552
  if ( count.length == 0 ) {
3429
3553
  return res.sendError( 'No Data Found', 204 );
3430
3554
  }
@@ -3439,7 +3563,7 @@ export async function overviewTable( req, res ) {
3439
3563
  $limit: limit,
3440
3564
  } );
3441
3565
  }
3442
- const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3566
+ const result = [ 'uniform-detection', 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
3443
3567
  if ( inputData.isExport ) {
3444
3568
  const exportdata = [];
3445
3569
  result.forEach( ( element ) => {
@@ -3812,13 +3936,13 @@ export async function getDetectionAuditFile( req, res ) {
3812
3936
  const data = await signedUrl( fetchData );
3813
3937
  const mapimg = {
3814
3938
  img_path: data,
3815
- img_name: image[0],
3816
- img_id: indexes[1],
3939
+ img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
3940
+ img_id: img[3],
3817
3941
  };
3818
3942
  files.push( {
3819
3943
  img_path: data,
3820
- img_name: image[0],
3821
- img_id: indexes[1],
3944
+ img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
3945
+ img_id: img[3],
3822
3946
  selected: false,
3823
3947
  dropped: false,
3824
3948
  count: 1,
@@ -3837,7 +3961,7 @@ export async function getDetectionAuditFile( req, res ) {
3837
3961
  userId: req.user._id,
3838
3962
  storeId: msg.storeId,
3839
3963
  clientId: msg.storeId.split( '-' )[0],
3840
- auditType: 'Audit',
3964
+ auditType: msg.auditType || 'Audit',
3841
3965
  fileDate: msg.fileDate,
3842
3966
  inputBucketName: msg.inputBucketName,
3843
3967
  folderPath: msg.folderPath,
@@ -3858,7 +3982,7 @@ export async function getDetectionAuditFile( req, res ) {
3858
3982
  userId: req.user._id,
3859
3983
  storeId: msg.storeId,
3860
3984
  clientId: msg.storeId.split( '-' )[0],
3861
- auditType: 'Audit',
3985
+ auditType: msg.auditType || 'Audit',
3862
3986
  fileDate: msg.fileDate,
3863
3987
  folderPath: msg.folderPath,
3864
3988
  inputBucketName: msg.inputBucketName,
@@ -3921,7 +4045,7 @@ export async function getDetectionAuditFile( req, res ) {
3921
4045
  queueName: inputData.queueName,
3922
4046
  storeId: storeId,
3923
4047
  fileDate: fileDate,
3924
- auditType: 'Audit',
4048
+ auditType: msg.auditType || 'Audit',
3925
4049
  auditId: insertData._id,
3926
4050
  userId: insertData.userId,
3927
4051
  moduleType: inputData.moduleType,
@@ -3945,7 +4069,7 @@ export async function saveDraft( req, res ) {
3945
4069
  const openSearch = JSON.parse( process.env.OPENSEARCH );
3946
4070
  const inputData = req.body;
3947
4071
  inputData.userId = req.user._id;
3948
- const getUserAuditData = await findOneUserAudit( { _id: inputData.auditId } );
4072
+ const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
3949
4073
  if ( !getUserAuditData ) {
3950
4074
  return res.sendError( 'No Data Found', 204 );
3951
4075
  }
@@ -3963,7 +4087,6 @@ export async function saveDraft( req, res ) {
3963
4087
  const storeQuery = {
3964
4088
  storeId: inputData.storeId,
3965
4089
  fileDate: inputData.fileDate,
3966
- zoneName: inputData.zoneName,
3967
4090
  };
3968
4091
 
3969
4092
  let storeRecord = {
@@ -4004,7 +4127,7 @@ export async function saveDraft( req, res ) {
4004
4127
  }
4005
4128
  await createAuditLog( inputData );
4006
4129
  await updateOneUserEmpDetection( userQuery, userRecord );
4007
- await updateOneStoreEmp( storeQuery, storeRecord );
4130
+ await updateOneStoreEmpDetection( storeQuery, storeRecord );
4008
4131
  return res.sendSuccess( {
4009
4132
  result: 'The file has been drafted successfully',
4010
4133
  } );
@@ -4048,8 +4171,13 @@ export async function getDraftedData( req, res ) {
4048
4171
  export async function save( req, res ) {
4049
4172
  try {
4050
4173
  const inputData = req.body;
4051
- const data = await createEmpDetection( inputData );
4174
+ const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
4175
+ inputData.clientId = getUserAuditData.clientId;
4176
+ const query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
4177
+ const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
4052
4178
  if ( data ) {
4179
+ await updateOneUserEmpDetection( { _id: inputData.auditId }, { auditStatus: 'completed', afterCount: inputData.employeeCount } );
4180
+ await updateOneStoreEmpDetection( query, { status: 'completed', afterCount: inputData.employeeCount } );
4053
4181
  return res.sendSuccess( { result: 'Updated Successfully' } );
4054
4182
  } else {
4055
4183
  return res.sendError( 'something went wrong', 403 );
@@ -4064,3 +4192,89 @@ export async function save( req, res ) {
4064
4192
  return res.sendError( err, 500 );
4065
4193
  }
4066
4194
  }
4195
+
4196
+ export async function reTrigger( req, res ) {
4197
+ try {
4198
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
4199
+ const inputData = req.body;
4200
+ const message = req.sqs;
4201
+ const sqs = JSON.parse( process.env.SQS );
4202
+ const getQueueName = await findOneClient( { clientId: req.audit.clientId }, { 'auditConfigs': 1 } );
4203
+ const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : getQueueName?.auditConfigs?.traxQueueName?.mobileDetection;
4204
+ if ( !getQueueName || queueName == '' ) {
4205
+ return res.sendError( 'queueName does not create', 400 );
4206
+ }
4207
+ const msg = {
4208
+ storeId: message.storeId,
4209
+ fileDate: message.fileDate,
4210
+ moduleType: message.moduleType,
4211
+ inputBucketName: message.inputBucketName,
4212
+ questionType: message.questionType,
4213
+ question: message.question,
4214
+ folderPath: message.folderPath,
4215
+ fileCount: message.fileCount,
4216
+ };
4217
+ const sqsProduceQueue = {
4218
+ QueueUrl: `${sqs.url}${queueName}`,
4219
+ MessageBody: JSON.stringify( msg ),
4220
+ };
4221
+ const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
4222
+ if ( sqsQueue?.errorCode ) {
4223
+ const error = sqsQueue?.errorMsg;
4224
+ const code = sqsQueue?.errorCode;
4225
+ return res.sendError( error, code );
4226
+ } else {
4227
+ if ( req.audit.status !== 'completed' ) {
4228
+ const userRecord = {
4229
+ auditStatus: 'skipped',
4230
+ isDraft: false,
4231
+ };
4232
+ const query = {
4233
+ storeId: inputData.storeId,
4234
+ fileDate: inputData.fileDate,
4235
+ auditStatus: req.audit.status,
4236
+ moduleType: inputData.moduleType,
4237
+
4238
+ };
4239
+ await updateOneUserEmpDetection( query, userRecord );
4240
+ }
4241
+
4242
+ const storeQuery = {
4243
+ storeId: inputData.storeId,
4244
+ fileDate: inputData.fileDate,
4245
+ moduleType: inputData.moduleType,
4246
+
4247
+ };
4248
+
4249
+ const storeRecord = {
4250
+ status: 'not_assign',
4251
+ };
4252
+
4253
+ await updateOneStoreEmpDetection( storeQuery, storeRecord );
4254
+ const logData = {
4255
+ userId: req.user._id,
4256
+ userName: req.user.userName,
4257
+ logType: 'traxAudit',
4258
+ logSubType: 'reTrigger',
4259
+ logData: {
4260
+ beforeCount: message.fileCount,
4261
+ afterCount: '',
4262
+ fileDate: inputData.fileDate,
4263
+ auditType: req.audit.auditType,
4264
+ storeId: inputData.storeId,
4265
+ moduleType: inputData.moduleType,
4266
+ queueName: queueName,
4267
+ triggerBy: req.user.userName,
4268
+ triggerId: req.user._id,
4269
+ },
4270
+ createdAt: new Date(),
4271
+ };
4272
+ await insertOpenSearchData( openSearch.auditLog, logData );
4273
+ }
4274
+ return res.sendSuccess( { result: 'The File has been Re-Triggered Succesfully' } );
4275
+ } catch ( error ) {
4276
+ const err = error.message;
4277
+ logger.error( { error: error, message: req.body, function: 'reTrigger' } );
4278
+ return res.sendError( err, 500 );
4279
+ }
4280
+ }
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema } from '../dtos/traxAudit.dtos.js';
2
+ import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema, getDetectionFileValid, saveBinarySchema, saveDraftSchema, getDraftedDataSchema, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
3
3
 
4
4
  export const traxAuditDocs = {
5
5
 
@@ -363,7 +363,7 @@ export const traxAuditDocs = {
363
363
  },
364
364
  },
365
365
 
366
- '/v3/reax-audit/get-drafted-data': {
366
+ '/v3/trax-audit/get-drafted-data': {
367
367
  get: {
368
368
  tags: [ 'Trax Audit' ],
369
369
  description: 'Get a saved file via DB',
@@ -403,4 +403,26 @@ export const traxAuditDocs = {
403
403
  },
404
404
  },
405
405
  },
406
+ '/v3/trax-audit/metrics/re-trigger': {
407
+ post: {
408
+ tags: [ 'Trax Audit' ],
409
+ description: `Manual re trigger a file`,
410
+ operationId: 'metrics/re-trigger',
411
+ parameters: {},
412
+ requestBody: {
413
+ content: {
414
+ 'application/json': {
415
+ schema: j2s( reTriggerValidSchema ).swagger,
416
+ },
417
+ },
418
+ },
419
+ responses: {
420
+ 200: { description: 'Successful' },
421
+ 401: { description: 'Unauthorized User' },
422
+ 422: { description: 'Field Error' },
423
+ 500: { description: 'Server Error' },
424
+ 204: { description: 'Not Found' },
425
+ },
426
+ },
427
+ },
406
428
  };
@@ -45,7 +45,6 @@ export const saveDraftSchema = joi.object(
45
45
  storeId: joi.string().required(),
46
46
  auditId: joi.string().required(),
47
47
  moduleType: joi.string().required(),
48
- zoneName: joi.string().required(),
49
48
  auditType: joi.string().required(),
50
49
  fileDate: joi.string().required(),
51
50
  queueName: joi.string().required(),
@@ -273,8 +272,6 @@ export const saveSchema = joi.object( {
273
272
  auditType: joi.string().required(),
274
273
  moduleType: joi.string().required(),
275
274
  beforeCount: joi.number().required(),
276
- junkCount: joi.number().required(),
277
- junk: joi.array().required(),
278
275
  employeeCount: joi.number().required(),
279
276
  employee: joi.array().required(),
280
277
  } );
@@ -282,3 +279,15 @@ export const saveSchema = joi.object( {
282
279
  export const saveValid = {
283
280
  body: saveSchema,
284
281
  };
282
+
283
+
284
+ export const reTriggerValidSchema = joi.object( {
285
+ fileDate: joi.string().required(),
286
+ storeId: joi.string().required(),
287
+ moduleType: joi.string().required(),
288
+
289
+ } );
290
+
291
+ export const reTriggerValid = {
292
+ body: reTriggerValidSchema,
293
+ };
@@ -1,7 +1,7 @@
1
1
  import express from 'express';
2
2
  import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
- import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD } from '../controllers/audit.controllers.js';
4
+ import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs } from '../controllers/audit.controllers.js';
5
5
  import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
6
6
 
7
7
  export const auditRouter = express.Router();
@@ -39,4 +39,7 @@ auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotA
39
39
  // audit user wallet
40
40
  auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditCount );
41
41
  auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
42
+
43
+ // audit log
44
+ auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, auditViewLogs );
42
45
  export default auditRouter;
@@ -1,10 +1,9 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
- import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid } from '../dtos/traxAudit.dtos.js';
3
+ import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
4
4
  import { isExistsQueue } from '../validation/audit.validation.js';
5
- import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save } from '../controllers/traxAudit.controllers.js';
6
- import { isTraxAuditDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
7
- import { saveDraftValid } from '../dtos/audit.dtos.js';
5
+ import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save, reTrigger } from '../controllers/traxAudit.controllers.js';
6
+ import { isMappingAuditInputFolderExist, isTraxAuditDocumentExist, isuserEmpDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
8
7
 
9
8
  export const traxAuditRouter = Router();
10
9
 
@@ -29,6 +28,7 @@ traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validat
29
28
  traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
30
29
  traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
31
30
  traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
31
+ traxAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValidSchema ), isuserEmpDocumentExist, isMappingAuditInputFolderExist, reTrigger );
32
32
 
33
33
  // summary
34
34
 
@@ -1,5 +1,5 @@
1
1
  import auditUserWalletModel from 'tango-api-schema/schema/auditUserWallet.model.js';
2
-
2
+ import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
3
3
 
4
4
  export function createAuditUserWallet( record ) {
5
5
  return auditUserWalletModel.create( record );
@@ -8,3 +8,6 @@ export function createAuditUserWallet( record ) {
8
8
  export function updateManyAuditUserWallet( query, record ) {
9
9
  return auditUserWalletModel.updateMany( query, record, { upsert: true } );
10
10
  };
11
+ export function createempDetectionOutput( query, field, option ) {
12
+ return empDetectionOutputModel.updateOne( query, field, option );
13
+ };
@@ -1,5 +1,5 @@
1
1
 
2
2
  import empDetectionOutputModel from 'tango-api-schema/schema/empDetectionOutput.model.js';
3
- export function createAuditLog( record ) {
4
- return empDetectionOutputModel.create( record );
3
+ export function updateOneEmpDetectionOutput( query, record, upsert ) {
4
+ return empDetectionOutputModel.updateOne( query, record, upsert );
5
5
  }
@@ -5,9 +5,14 @@ export function aggregateStoreEmpDetection( query ) {
5
5
  return storeEmpDetectionModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
6
6
  }
7
7
 
8
+ export function findOneStoreEmpDetection( query ) {
9
+ return storeEmpDetectionModel.findOne( query );
10
+ }
11
+
8
12
  export function updateOneStoreEmpDetection( query, record ) {
9
13
  return storeEmpDetectionModel.updateOne( query, { $set: record } );
10
14
  }
15
+
11
16
  export function updateManyStoreEmpDetection( query, record ) {
12
17
  return storeEmpDetectionModel.updateMany( query, { $set: record }, { upsert: true } );
13
18
  }
@@ -1,7 +1,8 @@
1
- import { logger } from 'tango-app-api-middleware';
1
+ import { checkFileExist, logger } from 'tango-app-api-middleware';
2
2
  import { findOneBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
3
3
  import { findOneUserEmpDetection } from '../service/userEmpDetection.service.js';
4
4
  import { findOneTraxAuditData } from '../service/traxAuditData.service.js';
5
+ import { findOneStoreEmpDetection } from '../service/storeEmpDetection.service.js';
5
6
 
6
7
  export async function validateUserEmpDetection( req, res, next ) {
7
8
  try {
@@ -116,3 +117,48 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
116
117
  return res.sendError( err, 500 );
117
118
  }
118
119
  }
120
+
121
+ export async function isuserEmpDocumentExist( req, res, next ) {
122
+ try {
123
+ const inputData = req.body;
124
+ const query={
125
+ storeId: inputData.storeId,
126
+ fileDate: inputData.fileDate,
127
+ moduleType: inputData.moduleType,
128
+ };
129
+ const auditInfo = await findOneStoreEmpDetection( query );
130
+ if ( auditInfo ) {
131
+ const sqs = await findOneTraxAuditData( query, { sqs: 1 } );
132
+ req.sqs = sqs.sqs.Body;
133
+ req.audit = auditInfo;
134
+ return next();
135
+ } else {
136
+ return res.sendError( 'No audited Record', 400 );
137
+ }
138
+ } catch ( error ) {
139
+ const err = error.message || 'Internal Server Error';
140
+ logger.error( { error: error, message: req.body, function: 'isAuditFileExist' } );
141
+ return res.sendError( err, 500 );
142
+ }
143
+ }
144
+
145
+
146
+ export async function isMappingAuditInputFolderExist( req, res, next ) {
147
+ try {
148
+ // const inputData = req.method === 'POST' ? req.body : req.query;
149
+ const params={
150
+ Bucket: req.sqs.inputBucketName,
151
+ Key: req.sqs.folderPath.replace( /\/$/, '' ),
152
+ };
153
+ const isExist = await checkFileExist( params );
154
+ if ( isExist ) {
155
+ next();
156
+ } else {
157
+ return res.sendError( `Audit Input folder not available : ${req.sqs.folderPath}`, 400 );
158
+ }
159
+ } catch ( error ) {
160
+ const err = error.message || 'Internal Server Error';
161
+ logger.error( { error: error, message: req.query, function: 'isAuidtInputFolderExist' } );
162
+ return res.sendError( err, 500 );
163
+ }
164
+ }