tango-app-api-audit 3.5.54 → 3.5.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.5.54",
3
+ "version": "3.5.56",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -51,6 +51,7 @@ import {
51
51
  mapCustomer,
52
52
  mapEmployee,
53
53
  mapJunk,
54
+ openSearchLog,
54
55
  splitB20000,
55
56
  splitE0,
56
57
  splitG20000,
@@ -148,7 +149,7 @@ export async function auditStoreList( req, res ) {
148
149
  const err = error.message || 'Internal Server Error';
149
150
  logger.error( {
150
151
  error: error,
151
- messgae: req.body,
152
+ message: req.body,
152
153
  function: 'auditStoreList',
153
154
  } );
154
155
  return res.sendError( err, 500 );
@@ -191,7 +192,7 @@ export async function auditUserList( req, res ) {
191
192
  const err = error.message || 'Internal Server Error';
192
193
  logger.error( {
193
194
  error: error,
194
- messgae: req.query,
195
+ message: req.query,
195
196
  function: 'auditUserList',
196
197
  } );
197
198
  return res.sendError( err, 500 );
@@ -234,9 +235,9 @@ export async function getAuditFile( req, res ) {
234
235
  ];
235
236
 
236
237
  const userDetails = await aggregateUserAudit( userQuery );
237
- let inserQuery = null;
238
+ let insertQuery = null;
238
239
  if ( userDetails && userDetails.length > 0 ) {
239
- inserQuery = [
240
+ insertQuery = [
240
241
  {
241
242
  $match: {
242
243
  $and: [
@@ -255,7 +256,7 @@ export async function getAuditFile( req, res ) {
255
256
  },
256
257
  ];
257
258
  }
258
- const auditInsertData = inserQuery? await aggregateAuditStoreData( inserQuery ): null;
259
+ const auditInsertData = insertQuery? await aggregateAuditStoreData( insertQuery ): null;
259
260
  const auditStatus = userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
260
261
  switch ( auditStatus ) {
261
262
  case null:
@@ -273,6 +274,23 @@ export async function getAuditFile( req, res ) {
273
274
  ];
274
275
  const userAssign = await aggregateAssignAudit( query );
275
276
  if ( userAssign.length > 0 ) {
277
+ // openSearch log
278
+ const id = `${req.query.moduleType}_${req.query.queueName}_getAuditFile_Info_${req?.user?.userEmail}_${Date.now()}`;
279
+ let temp = inputData;
280
+ temp.logType='audit';
281
+ temp.logSubType='get-audit-file';
282
+ temp.functionName='audit-controller-getAuditFile';
283
+ temp.messageType = 'log';
284
+ temp.message ='Hit in user assign';
285
+ temp.storeId =userAssign?.[0]?.storeId;
286
+ temp.fileDate =userAssign?.[0]?.fileDate;
287
+ temp.totalCount =userAssign?.[0]?.fileCount;
288
+ temp.zoneName =userAssign?.[0]?.zoneName;
289
+ temp.indexName= auditInsertData?.[0]?.index_name;
290
+
291
+
292
+ await openSearchLog( temp, req.user, id );
293
+ /** ******* end *******/
276
294
  logger.info( 'Hit in user assign', { inputData } );
277
295
  userAssign[0].auditType == 'Audit' ?
278
296
  ( msg = {
@@ -300,6 +318,18 @@ export async function getAuditFile( req, res ) {
300
318
  } );
301
319
  } else {
302
320
  logger.info( 'Hit in new file', { inputData } );
321
+ /* openSearch logs start*/
322
+
323
+ // declare basic details
324
+ const id = `${req.query.moduleType}_${req.query.queueName}_getAuditFile_Info_${req?.user?.userEmail}_${Date.now()}`;
325
+ let temp = inputData;
326
+ temp.logType='audit';
327
+ temp.logSubType='get-audit-file';
328
+ temp.functionName='audit-controller-getAuditFile';
329
+ temp.messageType = 'log';
330
+ temp.message ='Hit in new file';
331
+
332
+
303
333
  const consumer = await sqsReceive( inputData.queueName );
304
334
  if ( !consumer ) {
305
335
  logger.error( {
@@ -309,12 +339,37 @@ export async function getAuditFile( req, res ) {
309
339
  } );
310
340
  return res.sendError( `${inputData.queueName} is Empty`, 204 );
311
341
  }
342
+
312
343
  msg = JSON.parse( consumer );
344
+
345
+ // declare consumer data
346
+ temp.storeId =msg?.store_id;
347
+ temp.fileDate =msg?.curr_date;
348
+ temp.totalCount =msg?.total_count;
349
+ temp.zoneName =msg?.zone_id;
350
+ temp.indexName= msg?.index_name;
351
+ await openSearchLog( temp, req.user, id );
352
+ /* openSearch logs end */
313
353
  }
314
354
  break;
315
355
 
316
356
  case 'drafted':
317
357
  logger.info( 'userDetails drafted', { inputData } );
358
+ /* openSearch logs start */
359
+ const id = `${req.query.moduleType}_${req.query.queueName}_getAuditFile_Info_${req?.user?.userEmail}_${Date.now()}`;
360
+ let temp = inputData;
361
+ temp.logType='audit';
362
+ temp.logSubType='get-audit-file';
363
+ temp.functionName='audit-controller-getAuditFile';
364
+ temp.messageType = 'log';
365
+ temp.message ='Hit in drafted file';
366
+ msg = JSON.parse( consumer );
367
+ temp.storeId =userDetails[0].storeId;
368
+ temp.fileDate =userDetails[0].fileDate;
369
+ temp.totalCount =userDetails[0].beforeCount;
370
+ temp.zoneName =userDetails[0].zoneName;
371
+ await openSearchLog( temp, req.user, id );
372
+ /* openSearch logs end */
318
373
  const log = await findOneAuditLog(
319
374
  {
320
375
  userId: userDetails[0].userId,
@@ -420,16 +475,32 @@ export async function getAuditFile( req, res ) {
420
475
  break;
421
476
  }
422
477
  if ( msg.audit_type === 'ReAudit' && msg.zone_id !== 'track' ) {
478
+ /* openSearch logs start */
479
+ const id = `${req.query.moduleType}_${req.query.queueName}_getAuditFile_Info_${req?.user?.userEmail}_${Date.now()}`;
480
+ let temp = inputData;
481
+ temp.logType='audit';
482
+ temp.logSubType='get-audit-file';
483
+ temp.functionName='audit-controller-getAuditFile';
484
+ temp.messageType = 'log';
485
+ temp.message ='Hit in user ReAudit';
486
+ temp.storeId =msg?.store_id;
487
+ temp.fileDate =msg?.curr_date;
488
+ temp.totalCount =msg?.total_count;
489
+ temp.zoneName =msg?.zone_id;
490
+ temp.auditType = msg?.audit_type;
491
+ temp.indexName= msg?.index_name;
492
+ await openSearchLog( temp, req.user, id );
493
+ /* openSearch logs end */
423
494
  logger.info( 'Hit in user ReAudit', { inputData } );
424
- let reauditInsert = {};
495
+ let reAuditInsert = {};
425
496
  const [ filterData, auditImage ] = await Promise.all( [
426
- getFilterData( msg ),
427
- getAuditImage( msg ),
497
+ getFilterData( msg, req.user ),
498
+ getAuditImage( msg, req.user ),
428
499
  ] );
429
500
  if ( filterData.statusCode == 404 || auditImage.statusCode == 404 ) {
430
501
  return res.sendError( 'No Data found', 204 );
431
502
  }
432
- const reauditImg = await getReauditImg( filterData, auditImage );
503
+ const reAuditImg = await getReAuditImg( filterData, auditImage );
433
504
  if ( userDetails.length === 0 ) {
434
505
  const [ day, month, year ] = msg.curr_date.split( '-' );
435
506
  const temp = `${year}-${month}-${day}`;
@@ -444,7 +515,7 @@ export async function getAuditFile( req, res ) {
444
515
  auditType: msg.audit_type || 'ReAudit',
445
516
  fileDate: msg.curr_date,
446
517
  queueName: inputData.queueName,
447
- beforeCount: reauditImg.length,
518
+ beforeCount: reAuditImg.length,
448
519
  auditStatus: 'inprogress',
449
520
  fileDateISO: start,
450
521
  timeSpent: 0,
@@ -464,11 +535,11 @@ export async function getAuditFile( req, res ) {
464
535
  status: 'inprogress',
465
536
  timeSpent: 0,
466
537
  };
467
- reauditInsert = await createUserAudit( record );
538
+ reAuditInsert = await createUserAudit( record );
468
539
 
469
540
  await updateOneStoreAudit( query, storeRecord );
470
541
  } else {
471
- reauditInsert = userDetails[0];
542
+ reAuditInsert = userDetails[0];
472
543
  }
473
544
  const userdata = await findOneUser( { _id: req.user._id } );
474
545
  if ( inputData.nextId ) {
@@ -482,7 +553,7 @@ export async function getAuditFile( req, res ) {
482
553
  auditType: msg.audit_type,
483
554
  storeId: msg.store_id,
484
555
  clientName: inputData.queueName,
485
- auditId: reauditInsert._id,
556
+ auditId: reAuditInsert._id,
486
557
  zoneName: msg.zone_id,
487
558
  moduleType: inputData.moduleType,
488
559
  beforeCount: msg.total_count,
@@ -502,8 +573,8 @@ export async function getAuditFile( req, res ) {
502
573
  };
503
574
  const storeInfo = await findOneStore( storeQuery, storeFields );
504
575
  return res.sendSuccess( {
505
- result: reauditImg,
506
- count: reauditImg.length,
576
+ result: reAuditImg,
577
+ count: reAuditImg.length,
507
578
  storeId: storeInfo?.storeId,
508
579
  storeName: storeInfo?.storeName,
509
580
  address: storeInfo?.address || '',
@@ -512,12 +583,12 @@ export async function getAuditFile( req, res ) {
512
583
  file_date: msg.curr_date,
513
584
  type: msg.audit_type || 'ReAudit',
514
585
  queueName: inputData.queueName,
515
- auditId: reauditInsert._id,
516
- userId: reauditInsert.userId,
586
+ auditId: reAuditInsert._id,
587
+ userId: reAuditInsert.userId,
517
588
  zoneName: msg.zone_id,
518
589
  moduleType: inputData.moduleType,
519
590
  },
520
- isDraft: reauditInsert.isDraft,
591
+ isDraft: reAuditInsert.isDraft,
521
592
  } );
522
593
  }
523
594
  const storeId = msg.store_id;
@@ -597,6 +668,23 @@ export async function getAuditFile( req, res ) {
597
668
 
598
669
  };
599
670
  logger.info( { fetchData: fetchData, msg: msg, inputData: inputData, type: 'debug-bucketNameIssue' } );
671
+ /* openSearch logs start */
672
+ const _id = `${req.query.moduleType}_${req.query.queueName}_getAuditFile_Info_${req?.user?.userEmail}_${Date.now()}`;
673
+ let temp = inputData;
674
+ temp.logType='audit';
675
+ temp.logSubType='get-audit-file';
676
+ temp.functionName='audit-controller-getAuditFile';
677
+ temp.messageType = 'log';
678
+ temp.message ='debug-bucketNameIssue';
679
+ temp.storeId =msg?.store_id;
680
+ temp.fileDate =msg?.curr_date;
681
+ temp.totalCount =msg?.total_count;
682
+ temp.zoneName =msg?.zone_id;
683
+ temp.auditType = msg?.audit_type;
684
+ temp.indexName= msg?.index_name;
685
+ temp.params = JSON.stringify( fetchData );
686
+ await openSearchLog( temp, req.user, _id );
687
+ /* openSearch logs end */
600
688
  const list = msg.zone_id === 'track' ? inputData.nextId? await scrollResponse( inputData.nextId ):await searchOpenSearchData( msg.index_name, getQuery ): await listFileByPath( fetchData );
601
689
  const folderPath = msg.zone_id === 'track' ? list?.body?.hits?.hits : list.data;
602
690
  const nextQuery =msg.zone_id !== 'track' ? list.pageToken: '';
@@ -614,7 +702,7 @@ export async function getAuditFile( req, res ) {
614
702
  const indexes = msg.zone_id === 'track' ? msg.audit_type === 'ReAudit'? folderPath[i]?._source?.outputCluster ===50000? folderPath[i]?._source?.REIDCluster:folderPath[i]?._source?.outputCluster:folderPath[i]?._source?.REIDCluster: image[0]?.split( '_' );
615
703
  fetchData.file_path = msg.zone_id === 'track' ?folderPath[i]?._source?.personPath:folderPath[i].Key;
616
704
  const data =msg.zone_id === 'track' ? `${url.trackInput}${folderPath[i]?._source?.personPath}` :await signedUrl( fetchData );
617
- const mapimg = {
705
+ const mapImg = {
618
706
  img_path: data,
619
707
  img_name: msg.zone_id === 'track' ?indexes: indexes[1],
620
708
  img_id: image[0],
@@ -627,7 +715,7 @@ export async function getAuditFile( req, res ) {
627
715
  dropped: false,
628
716
  demographic: '',
629
717
  count: 1,
630
- mappedid: [ mapimg ],
718
+ mappedid: [ mapImg ],
631
719
  } ):
632
720
  files.push( {
633
721
  img_path: data,
@@ -637,7 +725,7 @@ export async function getAuditFile( req, res ) {
637
725
  dropped: false,
638
726
  demographic: '',
639
727
  count: 1,
640
- mappedid: [ mapimg ],
728
+ mappedid: [ mapImg ],
641
729
  } );
642
730
  }
643
731
  if ( userDetails.length === 0 ) {
@@ -701,10 +789,27 @@ export async function getAuditFile( req, res ) {
701
789
  list.body._scroll_id = '';
702
790
  insertData = userDetails[0];
703
791
  } else {
792
+ /* openSearch logs start*/
793
+ const id = `${req.query.moduleType}_${req.query.queueName}_getAuditFile_Error_${req?.user?.userEmail}_${Date.now()}`;
794
+ let temp = inputData;
795
+ temp.logType='audit';
796
+ temp.logSubType='get-audit-file';
797
+ temp.functionName='audit-controller-getAuditFile';
798
+ temp.messageType = 'error';
799
+ temp.message ='Bucket image data not available';
800
+ temp.storeId =msg?.store_id;
801
+ temp.fileDate =msg?.curr_date;
802
+ temp.totalCount =msg?.total_count;
803
+ temp.zoneName =msg?.zone_id;
804
+ temp.auditType = msg?.audit_type;
805
+ temp.indexName= msg?.index_name;
806
+ temp.folderPath= folderPath;
807
+ await openSearchLog( temp, req.user, id );
808
+ /* openSearch logs end*/
704
809
  logger.error( {
705
810
  error: { folderPath: folderPath, nextQuery: nextQuery },
706
811
  function: 'getAuditFile',
707
- message: 'Bucket image data not availale',
812
+ message: 'Bucket image data not available',
708
813
  } );
709
814
  return res.sendError( 'Bucket is Empty', 204 );
710
815
  }
@@ -757,6 +862,22 @@ export async function getAuditFile( req, res ) {
757
862
  isDraft: insertData.isDraft,
758
863
  } );
759
864
  } catch ( error ) {
865
+ /* openSearch logs start*/
866
+ const id = `${req.query.moduleType}_${req.query.queueName}_getAuditFile_Error_${req?.user?.userEmail}_${Date.now()}`;
867
+ let temp = inputData;
868
+ temp.logType='audit';
869
+ temp.logSubType='get-audit-file';
870
+ temp.functionName='audit-controller-getAuditFile';
871
+ temp.messageType = 'error';
872
+ temp.message =error.message || 'Internal Server Error';
873
+ temp.storeId =msg?.store_id;
874
+ temp.fileDate =msg?.curr_date;
875
+ temp.totalCount =msg?.total_count;
876
+ temp.zoneName =msg?.zone_id;
877
+ temp.auditType = msg?.audit_type;
878
+ temp.indexName= msg?.index_name;
879
+ await openSearchLog( temp, req.user, id );
880
+ /* openSearch logs end*/
760
881
  logger.error( {
761
882
  error: error,
762
883
  message: req.query,
@@ -772,7 +893,7 @@ function addUniqueFile( files, newFile ) {
772
893
  }
773
894
  }
774
895
 
775
- export async function getFilterData( msg ) {
896
+ export async function getFilterData( msg, user ) {
776
897
  try {
777
898
  const bucket = JSON.parse( process.env.BUCKET );
778
899
  const params = {
@@ -781,6 +902,23 @@ export async function getFilterData( msg ) {
781
902
  };
782
903
  const mappingFile = await getJsonFileData( params );
783
904
  if ( mappingFile.statusCode ) {
905
+ /* openSearch logs start*/
906
+ const id = `${msg.store_id}_${msg.zone_id}_${msg.curr_date}_${bucket.masterJsonFile}_getFilterData_Error_${user?.userEmail}_${Date.now()}`;
907
+ let temp = msg;
908
+ temp.logType='audit';
909
+ temp.logSubType='get-audit-file';
910
+ temp.functionName='audit-controller-getFilterData';
911
+ temp.messageType = 'error';
912
+ temp.message ='Hit in user ReAudit-getFilterData';
913
+ temp.storeId =msg?.store_id;
914
+ temp.fileDate =msg?.curr_date;
915
+ temp.totalCount =msg?.total_count;
916
+ temp.zoneName =msg?.zone_id;
917
+ temp.auditType = msg?.audit_type;
918
+ temp.indexName= msg?.index_name;
919
+ temp.params = JSON.stringify( params );
920
+ await openSearchLog( temp, user, id );
921
+ /* openSearch logs end*/
784
922
  return mappingFile;
785
923
  } else {
786
924
  const mappingData = await JSON.parse( mappingFile.toString( 'utf-8' ) );
@@ -796,6 +934,23 @@ export async function getFilterData( msg ) {
796
934
  return finalResult;
797
935
  }
798
936
  } catch ( error ) {
937
+ /* openSearch logs start*/
938
+ const id = `${msg.store_id}_${msg.zone_id}_${msg.curr_date}_${bucket.masterJsonFile}_getFilterData_Error_${user?.userEmail}_${Date.now()}`;
939
+ let temp = msg;
940
+ temp.logType='audit';
941
+ temp.logSubType='get-audit-file';
942
+ temp.functionName='audit-controller-getFilterData';
943
+ temp.messageType = 'error';
944
+ temp.message =error.message ||'Internal Server Error';
945
+ temp.storeId =msg?.store_id;
946
+ temp.fileDate =msg?.curr_date;
947
+ temp.totalCount =msg?.total_count;
948
+ temp.zoneName =msg?.zone_id;
949
+ temp.auditType = msg?.audit_type;
950
+ temp.indexName= msg?.index_name;
951
+ temp.params = JSON.stringify( params );
952
+ await openSearchLog( temp, user, id );
953
+ /* openSearch logs end*/
799
954
  logger.error( {
800
955
  error: error,
801
956
  type: 'MAPPING JSON getFilterData',
@@ -805,7 +960,7 @@ export async function getFilterData( msg ) {
805
960
  }
806
961
  }
807
962
 
808
- export async function getAuditImage( msg ) {
963
+ export async function getAuditImage( msg, user ) {
809
964
  try {
810
965
  const bucket = JSON.parse( process.env.BUCKET );
811
966
  const storeId = msg.store_id;
@@ -816,6 +971,23 @@ export async function getAuditImage( msg ) {
816
971
  fetchData.filePath = `${fileDate}/${storeId}/${msg.zone_id}/`;
817
972
  const folderPath = await listFileWithoutLimit( fetchData );
818
973
  if ( folderPath.statusCode == 404 ) {
974
+ /* openSearch logs start */
975
+ const id = `${fileDate}_${storeId}_${msg.zone_id}_${bucket.auditInput}_getAuditImage_Error_${user?.userEmail}_${Date.now()}`;
976
+ let temp = msg;
977
+ temp.logType='audit';
978
+ temp.logSubType='get-audit-file';
979
+ temp.functionName='audit-controller-getFilterData';
980
+ temp.messageType = 'error';
981
+ temp.message =JSON.stringify( folderPath );
982
+ temp.storeId =msg?.store_id;
983
+ temp.fileDate =msg?.curr_date;
984
+ temp.totalCount =msg?.total_count;
985
+ temp.zoneName =msg?.zone_id;
986
+ temp.auditType = msg?.audit_type;
987
+ temp.indexName= msg?.index_name;
988
+ temp.params = JSON.stringify( fetchData );
989
+ await openSearchLog( temp, user, id );
990
+ /* openSearch logs end */
819
991
  return folderPath;
820
992
  }
821
993
  const auditImages = folderPath;
@@ -829,7 +1001,7 @@ export async function getAuditImage( msg ) {
829
1001
  Bucket: fetchData.Bucket,
830
1002
  };
831
1003
  const data = await signedUrl( params );
832
- const mapimg = {
1004
+ const mapImg = {
833
1005
  img_path: data,
834
1006
  img_name: indexes[1],
835
1007
  img_id: image[0],
@@ -841,19 +1013,36 @@ export async function getAuditImage( msg ) {
841
1013
  selected: false,
842
1014
  dropped: false,
843
1015
  count: 1,
844
- mappedid: [ mapimg ],
1016
+ mappedid: [ mapImg ],
845
1017
  } );
846
1018
  }
847
1019
  logger.info( { files: files, level: 4 } );
848
1020
  return files;
849
1021
  }
850
1022
  } catch ( error ) {
1023
+ /* openSearch logs start*/
1024
+ const id = `${fileDate}_${storeId}_${msg.zone_id}_${bucket.auditInput}_getAuditImage_Error_${user?.userEmail}_${Date.now()}`;
1025
+ let temp = msg;
1026
+ temp.logType='audit';
1027
+ temp.logSubType='get-audit-file';
1028
+ temp.functionName='audit-controller-getFilterData';
1029
+ temp.messageType = 'error';
1030
+ temp.message =error.message ||'Internal Server Error';
1031
+ temp.storeId =msg?.store_id;
1032
+ temp.fileDate =msg?.curr_date;
1033
+ temp.totalCount =msg?.total_count;
1034
+ temp.zoneName =msg?.zone_id;
1035
+ temp.auditType = msg?.audit_type;
1036
+ temp.indexName= msg?.index_name;
1037
+ temp.params = JSON.stringify( fetchData );
1038
+ await openSearchLog( temp, user, id );
1039
+ /* openSearch logs end */
851
1040
  logger.error( { error: error, type: 'AWS BUCKET --getAuditImage' } );
852
1041
  return error;
853
1042
  }
854
1043
  }
855
1044
 
856
- export const getReauditImg = async ( filter, image ) => {
1045
+ export const getReAuditImg = async ( filter, image ) => {
857
1046
  const chunkedMappingData = await chunkArray( image, 10 );
858
1047
  const promises = chunkedMappingData.map( async ( chunk ) => {
859
1048
  return mapFunction( chunk, filter );
@@ -1408,6 +1597,22 @@ export async function save( req, res ) {
1408
1597
  const fileData = await getJsonFileData( params );
1409
1598
 
1410
1599
  if ( fileData?.statusCode ) {
1600
+ /* openSearch logs start*/
1601
+ const id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Error_${req?.user?.userEmail}_${Date.now()}`;
1602
+ let temp = inputData;
1603
+ temp.logType='audit';
1604
+ temp.logSubType='get-audit-file';
1605
+ temp.functionName='audit-controller-getAuditFile';
1606
+ temp.messageType = 'error';
1607
+ temp.message =`ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`;
1608
+ temp.storeId =inputData.storeId;
1609
+ temp.fileDate =inputData.fileDate;
1610
+ temp.totalCount =inputData.beforeCount;
1611
+ temp.zoneName =inputData.zoneName;
1612
+ temp.auditType = inputData.auditType;
1613
+ temp.params= JSON.stringify( params );
1614
+ await openSearchLog( temp, req.user, id );
1615
+ /* openSearch logs end*/
1411
1616
  logger.error( {
1412
1617
  error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
1413
1618
  type: 'UPLOAD_ERROR',
@@ -1443,6 +1648,22 @@ export async function save( req, res ) {
1443
1648
  const mappingUpload = await fileUpload( uploadDataParams );
1444
1649
 
1445
1650
  if ( mappingUpload?.statusCode ) {
1651
+ /* openSearch logs start*/
1652
+ const id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Error_${req?.user?.userEmail}_${Date.now()}`;
1653
+ let temp = inputData;
1654
+ temp.logType='audit';
1655
+ temp.logSubType='get-audit-file';
1656
+ temp.functionName='audit-controller-getAuditFile';
1657
+ temp.messageType = 'error';
1658
+ temp.message =`ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`;
1659
+ temp.storeId =inputData.storeId;
1660
+ temp.fileDate =inputData.fileDate;
1661
+ temp.totalCount =inputData.beforeCount;
1662
+ temp.zoneName =inputData.zoneName;
1663
+ temp.auditType = inputData.auditType;
1664
+ temp.params = uploadDataParams;
1665
+ await openSearchLog( temp, req.user, id );
1666
+ /* openSearch logs end*/
1446
1667
  logger.error( {
1447
1668
  error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.zoneName}/${inputData.fileDate}/${bucket.masterJsonFile}`,
1448
1669
  type: 'UPLOAD_ERROR',
@@ -1709,7 +1930,6 @@ export async function save( req, res ) {
1709
1930
  const cusIds = getCusId?.body?.hits?.total?.value || null;
1710
1931
  if ( cusIds ) {
1711
1932
  const temp = getCusId?.body?.hits?.hits.map( ( item ) => item._id );
1712
- logger.info( { custoemrTemp: temp } );
1713
1933
  const body = temp.flatMap( ( id ) => [
1714
1934
  { update: { _index: openSearch.trackerInput, _id: id } },
1715
1935
  { doc: { outputCluster: 50000, auditOutputCluster: 50000 } },
@@ -1763,8 +1983,8 @@ export async function save( req, res ) {
1763
1983
  inputData.moduleType == 'traffic'
1764
1984
  ) {
1765
1985
  logger.info(
1766
- `Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
1767
- 'Reaudit',
1986
+ `Hit in ReAudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
1987
+ 'ReAudit',
1768
1988
  );
1769
1989
  const queueName = inputData.moduleType == 'zone' ? clientData[0].auditConfigs.zoneQueueName : clientData[0].auditConfigs.trafficQueueName;
1770
1990
  if ( !queueName ) {
@@ -1834,6 +2054,22 @@ export async function save( req, res ) {
1834
2054
 
1835
2055
  await insertOpenSearchData( openSearch.auditLog, logData );
1836
2056
  } else {
2057
+ /* openSearch logs start*/
2058
+ let id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.userEmail}_${Date.now()}`;
2059
+ let temp = inputData;
2060
+ temp.logType='audit';
2061
+ temp.logSubType='get-audit-file';
2062
+ temp.functionName='audit-controller-getAuditFile';
2063
+ temp.messageType = 'info';
2064
+ temp.message ='Hit in Features';
2065
+ temp.storeId =inputData.storeId;
2066
+ temp.fileDate =inputData.fileDate;
2067
+ temp.totalCount =inputData.beforeCount;
2068
+ temp.zoneName =inputData.zoneName;
2069
+ temp.auditType = inputData.auditType;
2070
+ await openSearchLog( temp, req.user, id );
2071
+
2072
+ /* openSearch logs end */
1837
2073
  logger.info( 'Hit in Features', {
1838
2074
  data: _.omit( inputData, [ 'junk', 'employee', 'customer' ] ),
1839
2075
  } );
@@ -1914,9 +2150,20 @@ export async function save( req, res ) {
1914
2150
  sqsProduceQueue.MessageBody,
1915
2151
 
1916
2152
  );
1917
-
1918
- logger.info( { sqsQueue: sqsQueue } );
2153
+ /* openSearch logs start */
2154
+ id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.userEmail}_${Date.now()}`;
2155
+ const message = {
2156
+ getBody: getBody,
2157
+ streams: streams,
2158
+ sqsProduceQueue: sqsProduceQueue,
2159
+ sqsQueue: sqsQueue,
2160
+ };
2161
+ temp.message =JSON.stringify( message );
2162
+ await openSearchLog( temp, req.user, id );
2163
+ /* openSearch logs end */
1919
2164
  if ( inputData.moduleType === 'track' ) {
2165
+ // declare id
2166
+ id = `${inputData.moduleType}_${inputData.auditId}_${inputData.storeId}_${inputData.moduleType}_${inputData.auditType}_save_Info_${req?.user?.userEmail}_${Date.now()}`;
1920
2167
  const query =
1921
2168
  {
1922
2169
  module: 'REID-TRACKER-V1',
@@ -1926,6 +2173,10 @@ export async function save( req, res ) {
1926
2173
  timestamp: new Date(),
1927
2174
  };
1928
2175
  await upsertOpenSearchData( openSearch.trackerInput, `${inputData.storeId}_${inputData.fileDate}_23:00`, { doc: query } );
2176
+ /* update message */
2177
+ temp.message =JSON.stringify( query );
2178
+ await openSearchLog( temp, req.user, id );
2179
+ /* openSearch logs end */
1929
2180
  }
1930
2181
  }
1931
2182
 
@@ -4363,13 +4614,13 @@ export async function auditImages( req, res ) {
4363
4614
  return res.sendError( { error: error }, code );
4364
4615
  }
4365
4616
 
4366
- const reauditImg = await getReauditImg( filterData, auditImageAC );
4367
- if ( reauditImg?.length == 0 ) {
4617
+ const reAuditImg = await getReAuditImg( filterData, auditImageAC );
4618
+ if ( reAuditImg?.length == 0 ) {
4368
4619
  return res.sendError( 'No Data Found', 204 );
4369
4620
  }
4370
4621
 
4371
4622
  if ( inputData.export == true ) {
4372
- auditImageDownload = await zipDownloadImage( reauditImg, inputData?.moduleType );
4623
+ auditImageDownload = await zipDownloadImage( reAuditImg, inputData?.moduleType );
4373
4624
  // Set response headers for the zip file
4374
4625
  res.set( 'Content-Type', 'application/zip' );
4375
4626
  res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
@@ -4377,7 +4628,7 @@ export async function auditImages( req, res ) {
4377
4628
  // Send the zip file as the API response
4378
4629
  return res.send( auditImageDownload );
4379
4630
  }
4380
- return res.sendSuccess( { result: reauditImg } );
4631
+ return res.sendSuccess( { result: reAuditImg } );
4381
4632
  break;
4382
4633
  default:
4383
4634
  return res.sendError( 'No Data Found', 204 );
@@ -5405,3 +5656,98 @@ export async function convertTimestampToDateTime( timestamp ) {
5405
5656
  const seconds = ( '0' + adjustedDate.getSeconds() ).slice( -2 );
5406
5657
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
5407
5658
  }
5659
+
5660
+ export async function rePushAuditStores( req, res ) {
5661
+ try {
5662
+ const inputData = req.body;
5663
+ const sqs = JSON.parse( process.env.SQS );
5664
+ const getStoreAuditQuery = [
5665
+ {
5666
+ $match: {
5667
+ $and: [
5668
+ {
5669
+ clientId: { $eq: inputData.clientId },
5670
+ },
5671
+ {
5672
+ fileDate: { $eq: inputData.fileDate },
5673
+ },
5674
+ {
5675
+ moduleType: { $eq: inputData.moduleType },
5676
+ },
5677
+ ],
5678
+ },
5679
+ },
5680
+ {
5681
+ $group: {
5682
+ _id: null,
5683
+ storeList: { $addToSet: '$storeId' },
5684
+ },
5685
+ },
5686
+ {
5687
+ $project: {
5688
+ storeList: 1,
5689
+ _id: 0,
5690
+ },
5691
+ },
5692
+ ];
5693
+ const getStoreAudit = await aggregateStoreAudit( getStoreAuditQuery );
5694
+ logger.info( { getStoreAudit: getStoreAudit } );
5695
+ let filter = [
5696
+ {
5697
+ fileDate: { $eq: inputData?.fileDate },
5698
+ },
5699
+ {
5700
+ clientId: { $eq: inputData?.clientId },
5701
+ },
5702
+ {
5703
+ moduleType: { $eq: inputData.moduleType },
5704
+ },
5705
+ ];
5706
+ if ( getStoreAudit && getStoreAudit?.length > 0 && getStoreAudit?.[0]?.storeList?.length > 0 ) {
5707
+ filter.push( {
5708
+ storeId: { $nin: getStoreAudit?.[0]?.storeList },
5709
+ } );
5710
+ }
5711
+
5712
+ const getStoreDataQuery = [
5713
+ {
5714
+ $match: {
5715
+ $and: filter,
5716
+ },
5717
+
5718
+ },
5719
+ {
5720
+ $project: {
5721
+ message: '$sqs.Body',
5722
+ queueName: 1,
5723
+ },
5724
+ },
5725
+ ];
5726
+ const getStoreData = await aggregateAuditStoreData( getStoreDataQuery );
5727
+ const temp =[];
5728
+ logger.info( { getStoreDataQuery: getStoreDataQuery, getStoreData: getStoreData } );
5729
+ if ( getStoreData &&getStoreData.length>0 ) {
5730
+ for ( const item of getStoreData ) {
5731
+ const sqsProduceQueue = {
5732
+ QueueUrl: `${sqs.url}${item.queueName}`,
5733
+ MessageBody: JSON.stringify( item.message ),
5734
+ };
5735
+ logger.info( { item: item } );
5736
+ const sqsQueue = await sendMessageToQueue(
5737
+ sqsProduceQueue.QueueUrl,
5738
+ sqsProduceQueue.MessageBody );
5739
+ if ( !sqsQueue.statusCode ) {
5740
+ logger.info( { sqsQueue: sqsQueue } );
5741
+ temp.push( item?.message?.store_id );
5742
+ }
5743
+ }
5744
+ return res.sendSuccess( { result: `these store are pushed to queue ${temp?.toString()}` } );
5745
+ } else {
5746
+ return res.sendError( 'No messages are pending', 403 );
5747
+ }
5748
+ } catch ( error ) {
5749
+ const err = error.message || 'Internal Server Error';
5750
+ logger.error( { error: error, message: req.query, function: 'rePushAuditStores-audit-controller' } );
5751
+ return res.sendError( err, 500 );
5752
+ }
5753
+ }
@@ -1,7 +1,30 @@
1
- import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema, pendingSummaryTableSchema, overviewTableSchema, auditViewlogSchema } from '../dtos/audit.dtos.js';
1
+ import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema, pendingSummaryTableSchema, overviewTableSchema, auditViewlogSchema, rePushAuditStoresSchema } from '../dtos/audit.dtos.js';
2
2
  import j2s from 'joi-to-swagger';
3
3
 
4
4
  export const auditDocs = {
5
+ /** internal api */
6
+ '/v3/audit/re-push-audit-stores': {
7
+ post: {
8
+ tags: [ 'Internal API' ],
9
+ description: `re-push the files which is missing any one of the layer`,
10
+ operationId: 're-push-audit-stores',
11
+ parameters: {},
12
+ requestBody: {
13
+ content: {
14
+ 'application/json': {
15
+ schema: j2s( rePushAuditStoresSchema ).swagger,
16
+ },
17
+ },
18
+ },
19
+ responses: {
20
+ 200: { description: 'Successful' },
21
+ 401: { description: 'Unauthorized User' },
22
+ 422: { description: 'Field Error' },
23
+ 500: { description: 'Server Error' },
24
+ 204: { description: 'Not Found' },
25
+ },
26
+ },
27
+ },
5
28
 
6
29
 
7
30
  /* < -- *** Configuration *** --> */
@@ -41,7 +64,7 @@ export const auditDocs = {
41
64
  '/v3/audit/audit-stores': {
42
65
  post: {
43
66
  tags: [ 'Audit Stores' ],
44
- description: `sGet list of stores`,
67
+ description: `Get list of stores`,
45
68
  operationId: 'audit-stores',
46
69
  parameters: {},
47
70
  requestBody: {
@@ -627,4 +650,6 @@ export const auditDocs = {
627
650
  },
628
651
  },
629
652
  },
653
+
654
+
630
655
  };
@@ -310,3 +310,14 @@ export const auditImageValidSchema = joi.object( {
310
310
  export const auditImageValid = {
311
311
  query: auditImageValidSchema,
312
312
  };
313
+
314
+
315
+ export const rePushAuditStoresSchema = joi.object( {
316
+ fileDate: joi.string().required(),
317
+ clientId: joi.string().required(),
318
+ moduleType: joi.string().required().allow( 'traffic', 'track', 'zone' ),
319
+ } );
320
+
321
+ export const rePushAuditStoresValid = {
322
+ body: rePushAuditStoresSchema,
323
+ };
@@ -1,8 +1,8 @@
1
1
  import express from 'express';
2
- import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
2
+ import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit, validation } from '../validation/audit.validation.js';
3
3
  import { accessVerification, 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, auditViewLogs, getUserCredit } from '../controllers/audit.controllers.js';
5
- import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid, auditViewLogValid } from '../dtos/audit.dtos.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, getUserCredit, rePushAuditStores } from '../controllers/audit.controllers.js';
5
+ import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid, auditViewLogValid, rePushAuditStoresValid } from '../dtos/audit.dtos.js';
6
6
 
7
7
  export const auditRouter = express.Router();
8
8
 
@@ -46,3 +46,6 @@ auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAu
46
46
  // audit log
47
47
  auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditViewLogValid ), auditViewLogs );
48
48
  export default auditRouter;
49
+
50
+ //
51
+ auditRouter.post( '/re-push-audit-stores', validate( rePushAuditStoresValid ), validation, rePushAuditStores );
@@ -1,6 +1,6 @@
1
- import { checkFileExist, chunkArray, getJsonFileData, getObject, getQueueUrl, listFileWithoutLimit, logger, signedUrl } from 'tango-app-api-middleware';
1
+ import { checkFileExist, chunkArray, getJsonFileData, getObject, getQueueUrl, insertWithId, listFileWithoutLimit, logger, signedUrl } from 'tango-app-api-middleware';
2
2
  import { findOneUserAudit } from '../service/userAudit.service.js';
3
- import { findOneStoreAudit } from '../service/storeAudit.service.js';
3
+ import { aggregateStoreAudit, findOneStoreAudit } from '../service/storeAudit.service.js';
4
4
  import AdmZip from 'adm-zip';
5
5
  import { findOneAuditUsers } from '../service/auditUsers.service.js';
6
6
 
@@ -9,11 +9,31 @@ export async function isExistsQueue( req, res, next ) {
9
9
  const inputData = req.query;
10
10
  const isExist = await getQueueUrl( inputData.queueName );
11
11
  if ( isExist.statusCode ) {
12
+ /* openSearch logs start */
13
+ const id = `${inputData.moduleType}_${inputData.queueName}_isExistsQueue_Error_${req?.user?.userEmail}_${Date.now()}`;
14
+ let temp = inputData;
15
+ temp.logType='audit';
16
+ temp.logSubType='get-audit-file';
17
+ temp.functionName='audit-validation-isExistsQueue';
18
+ temp.messageType = 'error';
19
+ temp.message =`Queue doesn't Exist`;
20
+ await openSearchLog( temp, req.user, id );
21
+ /* openSearch logs end */
12
22
  return res.sendError( `Queue doesn't Exist`, 400 );
13
23
  } else {
14
24
  next();
15
25
  }
16
26
  } catch ( error ) {
27
+ /* openSearch logs start */
28
+ const id = `${req.query.moduleType}_${req.query.queueName}_isExistsQueue_Error_${req?.user?.userEmail}_${Date.now()}`;
29
+ let temp = req.query;
30
+ temp.logType='audit';
31
+ temp.logSubType='get-audit-file';
32
+ temp.functionName='audit-validation-isExistsQueue';
33
+ temp.messageType = 'error';
34
+ temp.message =error.message || 'Internal Server Error';
35
+ await openSearchLog( temp, req.user, id );
36
+ /* openSearch logs end */
17
37
  logger.error( { error: error, message: req.query, function: 'isExistsQueue' } );
18
38
  return res.sendError( error, 500 );
19
39
  }
@@ -22,7 +42,7 @@ export async function isExistsQueue( req, res, next ) {
22
42
  export async function validateUserAudit( req, res, next ) {
23
43
  try {
24
44
  const inputData = req.body;
25
- const userAuditDetails =await findOneUserAudit( { _id: inputData.auditId } );
45
+ const userAuditDetails = await findOneUserAudit( { _id: inputData.auditId } );
26
46
  if ( !userAuditDetails ) {
27
47
  return res.sendError( 'No Data Available' );
28
48
  } else if ( userAuditDetails && userAuditDetails.auditStatus == 'skipped' ) {
@@ -41,7 +61,7 @@ export async function isMasterJsonExists( req, res, next ) {
41
61
  try {
42
62
  const bucket = JSON.parse( process.env.BUCKET );
43
63
  const inputData = req.body;
44
- params={
64
+ params = {
45
65
  Bucket: bucket.masterJson,
46
66
  Key: `${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
47
67
  };
@@ -155,8 +175,8 @@ const mapFunction = async ( chunkData, filterData ) => {
155
175
  chunkData.find( ( item ) => {
156
176
  if ( mappedId.img_name === item.temp_ids ) {
157
177
  item.temp_ids = data.img_name;
158
- ( mappedId.img_name !== data.img_name )? item.query_status = '': null;
159
- item.demographic = data.demographic || '';
178
+ ( mappedId.img_name !== data.img_name ) ? item.query_status = '' : null;
179
+ item.demographic = data.demographic || '';
160
180
  }
161
181
  } );
162
182
  }
@@ -169,15 +189,15 @@ export async function isAuditInputFolderExist( req, res, next ) {
169
189
  try {
170
190
  const bucket = JSON.parse( process.env.BUCKET );
171
191
  const inputData = req.method === 'POST' ? req.body : req.query;
172
- const params={
192
+ const params = {
173
193
  Bucket: bucket.auditInput,
174
194
  Key: `${inputData.fileDate}/${inputData.storeId}/${inputData.zoneName}`,
175
195
  };
176
- const trackParams={
196
+ const trackParams = {
177
197
  Bucket: 'v4rnd-audit-input-images',
178
198
  Key: `${inputData.storeId}/${inputData.fileDate}`,
179
199
  };
180
- const isExist = await checkFileExist( inputData.moduleType == 'track'? trackParams:params );
200
+ const isExist = await checkFileExist( inputData.moduleType == 'track' ? trackParams : params );
181
201
  if ( isExist ) {
182
202
  next();
183
203
  } else {
@@ -193,7 +213,7 @@ export async function isAuditInputFolderExist( req, res, next ) {
193
213
  export async function isAuditDocumentExist( req, res, next ) {
194
214
  try {
195
215
  const inputData = req.body;
196
- const query={
216
+ const query = {
197
217
  storeId: inputData.storeId,
198
218
  fileDate: inputData.fileDate,
199
219
  zoneName: inputData.zoneName,
@@ -230,7 +250,7 @@ export async function getAuditImageData( data ) {
230
250
  }
231
251
  const auditImages = folderPath;
232
252
 
233
- if ( data.export==false ) {
253
+ if ( data.export == false ) {
234
254
  if ( auditImages && auditImages?.length > 0 ) {
235
255
  for ( let i = 0; i < auditImages.length; i++ ) {
236
256
  const img = auditImages[i].Key.split( '/' );
@@ -277,21 +297,21 @@ export async function getAuditImageData( data ) {
277
297
  }
278
298
  }
279
299
 
280
- export async function zipDownloadImage( data, modueType ) {
300
+ export async function zipDownloadImage( data, moduleType ) {
281
301
  try {
282
302
  const bucket = JSON.parse( process.env.BUCKET );
283
303
  const zip = new AdmZip();
284
304
  const split = await chunkArray( data, 10 );
285
305
  const promises = await split.map( async ( chunk ) => {
286
306
  for ( let item of chunk ) {
287
- const params ={
288
- Bucket: modueType === 'track' ? bucket.trackInput :`${bucket.auditInput}`,
289
- Key: modueType === 'track' ? item.img_path: item.imgFile.Key,
307
+ const params = {
308
+ Bucket: moduleType === 'track' ? bucket.trackInput : `${bucket.auditInput}`,
309
+ Key: moduleType === 'track' ? item.img_path : item.imgFile.Key,
290
310
  };
291
311
 
292
312
  const fileBuffer = await getObject( params );
293
- const splitItem = modueType === 'track'?item.img_path.split( '/' ) :null;
294
- const key = modueType === 'track' ? `${splitItem[0]}/${splitItem[1]}/${splitItem[3]}`: item.imgFile.Key;
313
+ const splitItem = moduleType === 'track' ? item.img_path.split( '/' ) : null;
314
+ const key = moduleType === 'track' ? `${splitItem[0]}/${splitItem[1]}/${splitItem[3]}` : item.imgFile.Key;
295
315
  zip.addFile( key, fileBuffer.Body );
296
316
  }
297
317
  return zip;
@@ -356,3 +376,83 @@ export async function isAuditUser( req, res, next ) {
356
376
  }
357
377
  }
358
378
 
379
+ export async function validation( req, res, next ) {
380
+ try {
381
+ const inputData = req.body;
382
+ const getStoreDataQuery = [
383
+ {
384
+ $match: {
385
+ $and: [
386
+ {
387
+ clientId: { $eq: inputData.clientId },
388
+ },
389
+ {
390
+ fileDate: { $eq: inputData.fileDate },
391
+ },
392
+ {
393
+ moduleType: { $eq: inputData.moduleType },
394
+ },
395
+ {
396
+ status: { $nin: [ 'not_assign', 'assigned' ] },
397
+ },
398
+ ],
399
+ },
400
+ },
401
+ ];
402
+ const getStoreAudit = await aggregateStoreAudit( getStoreDataQuery );
403
+ if ( getStoreAudit && getStoreAudit?.length > 0 ) {
404
+ return res.sendError( 'Already pending stores are there', 403 );
405
+ } else {
406
+ next();
407
+ return;
408
+ }
409
+ } catch ( error ) {
410
+ logger.error( { error: error, message: req.query, function: 'validation-audit.validation' } );
411
+ return res.sendError( error, 500 );
412
+ }
413
+ }
414
+ // openSearch log functions
415
+ export async function openSearchLog( inputData, user, id ) {
416
+ try {
417
+ const openSearch = JSON.parse( process.env.OPENSEARCH );
418
+ const logs = {
419
+ userId: user._id,
420
+ userName: user.userName,
421
+ userEmail: user.email,
422
+ functionName: inputData.functionName,
423
+ messageType: inputData.messageType,
424
+ message: inputData.message,
425
+ logType: inputData.logType,
426
+ logSubType: inputData.logSubType,
427
+ logData: {
428
+ fileDate: inputData.fileDate || '',
429
+ auditType: inputData.auditType || '',
430
+ storeId: inputData.storeId || '',
431
+ clientId: inputData.storeId.split( '-' )[0] || '',
432
+ zoneName: inputData.zoneName || '',
433
+ moduleType: inputData.moduleType || '',
434
+ queueName: inputData.queueName || '',
435
+ beforeCount: inputData.beforeCount || null,
436
+ afterCount: inputData.afterCount || null,
437
+ startTime: inputData.startTime || '',
438
+ endTime: inputData.startTime || '',
439
+ timeSpent: inputData.timeSpent || '',
440
+ auditId: inputData.auditId || '',
441
+ totalCount: inputData.totalCount || null,
442
+ indexName: inputData.indexName || '',
443
+ auditType: inputData.auditType || '',
444
+ folderPath: inputData.folderPath || '',
445
+ params: inputData.params||'',
446
+ createdAt: new Date(),
447
+ updatedAt: new Date(),
448
+ },
449
+
450
+ };
451
+ await insertWithId( openSearch.auditLog, id, logs );
452
+ return true;
453
+ } catch ( error ) {
454
+ logger.error( { error: error, message: { logs: logs, id: id }, function: 'openSearchLog-audit.validation' } );
455
+ return false;
456
+ }
457
+ }
458
+