tango-app-api-audit 3.4.55 → 3.4.56

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.55",
3
+ "version": "3.4.56",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
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.69",
29
+ "tango-api-schema": "^2.2.93",
30
30
  "tango-app-api-middleware": "^3.1.48",
31
31
  "winston": "^3.13.0",
32
32
  "winston-daily-rotate-file": "^5.0.0"
@@ -1,4 +1,4 @@
1
- import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getObject, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive, updateOpenSearchData } from 'tango-app-api-middleware';
1
+ import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getJsonFileData, getObject, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive, updateOpenSearchData } from 'tango-app-api-middleware';
2
2
  import { aggregateBinaryAudit, findOneBinaryAudit, updateOneBinaryAuditModel, updateOneUpsertBinaryAudit } from '../service/binaryAudit.service.js';
3
3
  import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
@@ -72,7 +72,7 @@ export async function workSpace( req, res ) {
72
72
  { $eq: [ inputData.moduleType, 'scrum' ] }, '$auditConfigs.traxQueueName.scrum',
73
73
  {
74
74
  $cond: [
75
- { $and: [ { $eq: [ inputData.moduleType, 'open-time' ] }, { $eq: [ inputData.moduleType, 'close-time' ] } ] }, '$auditConfigs.traxQueueName.openClose', '$auditConfigs.traxQueueName.anomaly',
75
+ { $eq: [ inputData.moduleType, 'open-time' ] }, '$auditConfigs.traxQueueName.openClose', '$auditConfigs.traxQueueName.anomaly',
76
76
 
77
77
  ],
78
78
  },
@@ -369,10 +369,10 @@ export async function workSpace( req, res ) {
369
369
  },
370
370
  ];
371
371
 
372
- const auditUserCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
373
- const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
372
+ const auditUserCount = [ 'mobile-detection', 'uniform-detection', 'hygiene', 'open-time', 'close-time' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
373
+ const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection', 'hygiene', 'open-time', 'close-time' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
374
374
  const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
375
- const completedStoresCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
375
+ const completedStoresCount = [ 'mobile-detection', 'uniform-detection', 'hygiene', 'open-time', 'close-time' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
376
376
  const clientAssignedCount = await aggregateAssignAudit( clientAssign );
377
377
  const auditStoreData = await aggregateTraxAuditData(
378
378
  auditStoreDataQuery,
@@ -4262,6 +4262,43 @@ export async function getDetectionAuditFile( req, res ) {
4262
4262
  const fetchData = {};
4263
4263
  let msg = {};
4264
4264
  // get user's inprogress files
4265
+ let filterQuery ={};
4266
+ let filter=[];
4267
+ switch ( inputData.moduleType ) {
4268
+ case 'mobile-detction':
4269
+ case 'uniform-detection':
4270
+ case 'open-time':
4271
+ case 'close-time':
4272
+ filter =[
4273
+ {
4274
+ $eq: [ '$fileDate', '$$fileDate' ],
4275
+ },
4276
+ {
4277
+ $eq: [ '$storeId', '$$storeId' ],
4278
+ },
4279
+ ];
4280
+ filterQuery={
4281
+ fileDate: '$fileDate', storeId: '$storeId',
4282
+ };
4283
+ break;
4284
+ case 'hygiene':
4285
+ filter =[
4286
+ {
4287
+ $eq: [ '$fileDate', '$$fileDate' ],
4288
+ },
4289
+ {
4290
+ $eq: [ '$storeId', '$$storeId' ],
4291
+ },
4292
+ {
4293
+ $eq: [ '$zoneName', '$$zoneName' ],
4294
+ },
4295
+ ];
4296
+ filterQuery={
4297
+ fileDate: '$fileDate', storeId: '$storeId', zoneName: '$zoneName',
4298
+ };
4299
+ break;
4300
+ }
4301
+
4265
4302
  const userQuery = [
4266
4303
  {
4267
4304
  $match: {
@@ -4271,7 +4308,7 @@ export async function getDetectionAuditFile( req, res ) {
4271
4308
  { auditStatus: { $nin: [ 'completed', 'skipped' ] } },
4272
4309
  { createdAt: { $gte: start } },
4273
4310
  { createdAt: { $lte: end } },
4274
- { moduleType: inputData.moduleType },
4311
+ { moduleType: { $in: inputData.moduleType=='open-time'?[ 'open-time', 'close-time' ]: [ inputData.moduleType ] } },
4275
4312
  ],
4276
4313
  },
4277
4314
  },
@@ -4284,24 +4321,12 @@ export async function getDetectionAuditFile( req, res ) {
4284
4321
  {
4285
4322
  $lookup: {
4286
4323
  from: 'traxAuditData',
4287
- let: {
4288
- fileDate: '$fileDate', storeId: '$storeId', zoneName: '$zoneName',
4289
- },
4324
+ let: { ...filterQuery, moduleType: '$moduleType' },
4290
4325
  pipeline: [
4291
4326
  {
4292
4327
  $match: {
4293
4328
  $expr: {
4294
- $and: [
4295
- {
4296
- $eq: [ '$fileDate', '$$fileDate' ],
4297
- },
4298
- {
4299
- $eq: [ '$storeId', '$$storeId' ],
4300
- },
4301
- {
4302
- $eq: [ '$zoneName', '$$zoneName' ],
4303
- },
4304
- ],
4329
+ $and: [ ...filter, { $eq: [ '$moduleType', '$$moduleType' ] } ],
4305
4330
  },
4306
4331
  },
4307
4332
  },
@@ -4316,8 +4341,8 @@ export async function getDetectionAuditFile( req, res ) {
4316
4341
  ];
4317
4342
 
4318
4343
  const userDetails = await aggregateUserEmpDetection( userQuery );
4319
- logger.info( { userDetails: userDetails, function: 'userDetails' } );
4320
4344
  const auditStatus = userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
4345
+ logger.info( { auditStatus: auditStatus, userDetails: userDetails } );
4321
4346
  switch ( auditStatus ) {
4322
4347
  case null:
4323
4348
  logger.info( 'Hit in new file', { inputData } );
@@ -4435,6 +4460,7 @@ export async function getDetectionAuditFile( req, res ) {
4435
4460
  inputBucketName: userDetails[0].inputBucketName,
4436
4461
  folderPath: userDetails[0].folderPath,
4437
4462
  question: userDetails[0]?.sqs[0]?.message?.question,
4463
+ moduleType: userDetails[0]?.moduleType,
4438
4464
  };
4439
4465
  break;
4440
4466
  }
@@ -4451,39 +4477,77 @@ export async function getDetectionAuditFile( req, res ) {
4451
4477
  if ( inputData.nextId ) {
4452
4478
  fetchData.ContinuationToken = decodeURIComponent( inputData.nextId );
4453
4479
  }
4480
+ const openParems ={
4481
+ Bucket: msg.inputBucketName,
4482
+ Key: msg.folderPath,
4483
+ };
4484
+ inputData.moduleType= inputData.moduleType == 'open-time'? msg.moduleType : inputData.moduleType;
4454
4485
  const list = inputData.moduleType == 'hygiene'? await checkFileExist( {
4455
4486
  Bucket: msg.inputBucketName,
4456
4487
  Key: msg.folderPath,
4457
- } ) :
4458
- await listFileByPath( fetchData );
4488
+ } ) :[ 'open-time', 'close-time' ].includes( inputData.moduleType )? await getJsonFileData( openParems ) :
4489
+ await listFileByPath( fetchData );
4459
4490
  const folderPath = inputData.moduleType == 'hygiene'? list? [ {
4460
4491
  Key: msg.folderPath,
4461
- } ] : [] : list.data;
4492
+ } ] : [] : [ 'open-time', 'close-time' ].includes( inputData.moduleType )? list?.statusCode== 500? []:JSON.parse( list.toString( 'utf-8' ) ).data : list.data;
4462
4493
  const nextQuery = inputData.moduleType == 'hygiene'? null : list?.pageToken;
4463
4494
  const bucketCDN = url.traxAuditInput;
4464
4495
  if ( folderPath?.length > 0 ) {
4465
- for ( let i = 0; i < folderPath.length; i++ ) {
4466
- const img = folderPath[i].Key.split( '/' );
4467
- const image = img[3].split( '.' );
4468
- const indexes = image[0].split( '_' );
4469
- const Key = folderPath[i].Key;
4470
- const data = `${bucketCDN}${Key}`;
4471
- const mapimg = {
4472
- img_path: data,
4473
- img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}`:image[0],
4474
- img_id: img[3],
4475
- };
4476
- files.push( {
4477
- img_path: data,
4478
- img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}`:image[0],
4479
- img_id: img[3],
4480
- selected: false,
4481
- dropped: false,
4482
- singleDetection: false,
4483
- count: 1,
4484
- mappedid: [ mapimg ],
4485
- } );
4496
+ switch ( inputData.moduleType ) {
4497
+ case 'mobile-detction':
4498
+ case 'uniform-detection':
4499
+ case 'hygiene':
4500
+ for ( let i = 0; i < folderPath.length; i++ ) {
4501
+ const img = folderPath[i].Key.split( '/' );
4502
+ const image = img[3].split( '.' );
4503
+ const indexes = image[0].split( '_' );
4504
+ const Key = folderPath[i].Key;
4505
+ const data = `${bucketCDN}${Key}`;
4506
+ const mapimg = {
4507
+ img_path: data,
4508
+ img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}`:image[0],
4509
+ img_id: img[3],
4510
+ };
4511
+ files.push( {
4512
+ img_path: data,
4513
+ img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}`:image[0],
4514
+ img_id: img[3],
4515
+ selected: false,
4516
+ dropped: false,
4517
+ singleDetection: false,
4518
+ count: 1,
4519
+ mappedid: [ mapimg ],
4520
+ } );
4521
+ }
4522
+ break;
4523
+ case 'open-time':
4524
+ case 'close-time':
4525
+
4526
+ for ( let i = 0; i < folderPath?.length; i++ ) {
4527
+ const item = folderPath[i];
4528
+ const img = item?.file_path?.split( '/' );
4529
+ const time = item?.time;
4530
+ const Key = item?.file_path;
4531
+ const data = `${bucketCDN}${Key}`;
4532
+ const mapimg = {
4533
+ img_path: data,
4534
+ img_name: time,
4535
+ img_id: img[3],
4536
+ };
4537
+ files.push( {
4538
+ img_path: data,
4539
+ img_name: time,
4540
+ img_id: img[3],
4541
+ selected: false,
4542
+ dropped: false,
4543
+ singleDetection: false,
4544
+ count: 1,
4545
+ mappedid: [ mapimg ],
4546
+ } );
4547
+ }
4548
+ break;
4486
4549
  }
4550
+
4487
4551
  if ( userDetails.length === 0 ) {
4488
4552
  const [ day, month, year ] = msg.fileDate.split( '-' );
4489
4553
  const temp = `${year}-${month}-${day}`;