tango-app-api-audit 3.4.54 → 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.
|
@@ -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,11 +72,8 @@ export async function workSpace( req, res ) {
|
|
|
72
72
|
{ $eq: [ inputData.moduleType, 'scrum' ] }, '$auditConfigs.traxQueueName.scrum',
|
|
73
73
|
{
|
|
74
74
|
$cond: [
|
|
75
|
-
{ $eq: [ inputData.moduleType, 'open-time' ] }, '$auditConfigs.traxQueueName.
|
|
76
|
-
|
|
77
|
-
$cond: [
|
|
78
|
-
{ $eq: [ inputData.moduleType, 'close-time' ] }, '$auditConfigs.traxQueueName.closeTime', '$auditConfigs.traxQueueName.anomaly' ],
|
|
79
|
-
},
|
|
75
|
+
{ $eq: [ inputData.moduleType, 'open-time' ] }, '$auditConfigs.traxQueueName.openClose', '$auditConfigs.traxQueueName.anomaly',
|
|
76
|
+
|
|
80
77
|
],
|
|
81
78
|
},
|
|
82
79
|
],
|
|
@@ -223,7 +220,6 @@ export async function workSpace( req, res ) {
|
|
|
223
220
|
},
|
|
224
221
|
},
|
|
225
222
|
},
|
|
226
|
-
|
|
227
223
|
{
|
|
228
224
|
$group: {
|
|
229
225
|
_id: '$clientId',
|
|
@@ -373,11 +369,10 @@ export async function workSpace( req, res ) {
|
|
|
373
369
|
},
|
|
374
370
|
];
|
|
375
371
|
|
|
376
|
-
const auditUserCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
377
|
-
const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
378
|
-
logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
|
|
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 );
|
|
379
374
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
380
|
-
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 );
|
|
381
376
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
382
377
|
const auditStoreData = await aggregateTraxAuditData(
|
|
383
378
|
auditStoreDataQuery,
|
|
@@ -552,7 +547,6 @@ export async function getAuditFile( req, res ) {
|
|
|
552
547
|
};
|
|
553
548
|
break;
|
|
554
549
|
case 'camera-angle-change':
|
|
555
|
-
case 'anomaly-audit':
|
|
556
550
|
query ={
|
|
557
551
|
storeId: userDetails[0].storeId,
|
|
558
552
|
fileDate: userDetails[0].fileDate,
|
|
@@ -570,11 +564,18 @@ export async function getAuditFile( req, res ) {
|
|
|
570
564
|
};
|
|
571
565
|
break;
|
|
572
566
|
case 'cleaning':
|
|
567
|
+
query ={
|
|
568
|
+
storeId: userDetails[0].storeId,
|
|
569
|
+
fileDate: userDetails[0].fileDate,
|
|
570
|
+
moduleType: userDetails[0].moduleType,
|
|
571
|
+
};
|
|
572
|
+
break;
|
|
573
573
|
case 'scrum':
|
|
574
574
|
query ={
|
|
575
575
|
storeId: userDetails[0].storeId,
|
|
576
576
|
fileDate: userDetails[0].fileDate,
|
|
577
577
|
moduleType: userDetails[0].moduleType,
|
|
578
|
+
streamName: userDetails[0].moduleType,
|
|
578
579
|
};
|
|
579
580
|
break;
|
|
580
581
|
default:
|
|
@@ -629,7 +630,6 @@ export async function getAuditFile( req, res ) {
|
|
|
629
630
|
case 'unattended-customer':
|
|
630
631
|
case 'left-in-middle':
|
|
631
632
|
case 'cleaning':
|
|
632
|
-
case 'scrum':
|
|
633
633
|
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
634
634
|
const files = [];
|
|
635
635
|
const params ={
|
|
@@ -661,6 +661,35 @@ export async function getAuditFile( req, res ) {
|
|
|
661
661
|
} );
|
|
662
662
|
}
|
|
663
663
|
break;
|
|
664
|
+
case 'scrum':
|
|
665
|
+
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
666
|
+
const files = [];
|
|
667
|
+
const params ={
|
|
668
|
+
Bucket: msg.inputBucketName,
|
|
669
|
+
Key: msg?.fileDetails[i]?.folderPath,
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
const isFileExists = await checkFileExist( params );
|
|
673
|
+
if ( isFileExists ) {
|
|
674
|
+
const data = `${url.traxAuditInput}${msg?.fileDetails[i]?.folderPath}`;
|
|
675
|
+
|
|
676
|
+
files.push(
|
|
677
|
+
data,
|
|
678
|
+
);
|
|
679
|
+
} else {
|
|
680
|
+
logger.error( {
|
|
681
|
+
error: { folderPath: msg?.fileDetails[i]?.folderPath },
|
|
682
|
+
function: `getAuditFile - ${inputData.moduleType}`,
|
|
683
|
+
message: 'Bucket image data not availale',
|
|
684
|
+
} );
|
|
685
|
+
return res.sendError( 'File not found', 204 );
|
|
686
|
+
}
|
|
687
|
+
result.push( {
|
|
688
|
+
type: msg.fileDetails[i].type,
|
|
689
|
+
file: files,
|
|
690
|
+
} );
|
|
691
|
+
}
|
|
692
|
+
break;
|
|
664
693
|
case 'eye-test-camera':
|
|
665
694
|
const eyeTestfiles = [];
|
|
666
695
|
|
|
@@ -672,34 +701,19 @@ export async function getAuditFile( req, res ) {
|
|
|
672
701
|
const isCameraExists = await checkFileExist( eyeTestparams );
|
|
673
702
|
|
|
674
703
|
if ( isCameraExists ) {
|
|
675
|
-
const url = JSON.parse( process.env.URL );
|
|
676
|
-
logger.info( { url: url, cameraBaseImage: url.cameraBaseImage } );
|
|
677
704
|
const data = `${url.cameraBaseImage}${msg?.filePath}`;
|
|
678
705
|
|
|
679
706
|
eyeTestfiles.push(
|
|
680
707
|
data,
|
|
681
708
|
);
|
|
682
709
|
} else {
|
|
683
|
-
return res.sendSuccess( 'No Data
|
|
710
|
+
return res.sendSuccess( 'No Data Found', 204 );
|
|
684
711
|
}
|
|
685
712
|
result.push( {
|
|
686
713
|
type: 'image',
|
|
687
714
|
file: eyeTestfiles,
|
|
688
715
|
} );
|
|
689
716
|
break;
|
|
690
|
-
case 'anomaly-audit':
|
|
691
|
-
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
692
|
-
const files = [];
|
|
693
|
-
const data = msg.fileDetails[i].folderPath;
|
|
694
|
-
files.push(
|
|
695
|
-
data,
|
|
696
|
-
);
|
|
697
|
-
result.push( {
|
|
698
|
-
type: msg.fileDetails[i].type,
|
|
699
|
-
file: files,
|
|
700
|
-
} );
|
|
701
|
-
}
|
|
702
|
-
break;
|
|
703
717
|
default:
|
|
704
718
|
return res.sendError( 'Please given valid moduleType', 400 );
|
|
705
719
|
}
|
|
@@ -719,7 +733,6 @@ export async function getAuditFile( req, res ) {
|
|
|
719
733
|
const [ day, month, year ] = msg.fileDate.split( '-' );
|
|
720
734
|
const temp = `${year}-${month}-${day}`;
|
|
721
735
|
let start = new Date( temp );
|
|
722
|
-
logger.info( { start: start, date: msg.fileDate } );
|
|
723
736
|
const userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
724
737
|
start = new Date( start.getTime() - userTimezoneOffset );
|
|
725
738
|
start.setUTCHours( 0, 0, 0, 0 );
|
|
@@ -740,7 +753,7 @@ export async function getAuditFile( req, res ) {
|
|
|
740
753
|
questionType: msg.questionType,
|
|
741
754
|
streamName: msg.streamName,
|
|
742
755
|
};
|
|
743
|
-
record.streamName = inputData.moduleType == 'camera-angle-change' || inputData.moduleType == 'eye-test-camera' || inputData.moduleType == '
|
|
756
|
+
record.streamName = inputData.moduleType == 'camera-angle-change' || inputData.moduleType == 'eye-test-camera' || inputData.moduleType == 'scrum'? msg.streamName : '';
|
|
744
757
|
record.videoDetails = inputData.moduleType == 'left-in-middle'? {
|
|
745
758
|
'startHour': msg.startHour,
|
|
746
759
|
'inspectHour': msg.inspectHour,
|
|
@@ -770,7 +783,6 @@ export async function getAuditFile( req, res ) {
|
|
|
770
783
|
break;
|
|
771
784
|
case 'camera-angle-change':
|
|
772
785
|
case 'eye-test-camera':
|
|
773
|
-
case 'anomaly-audit':
|
|
774
786
|
getQuery ={
|
|
775
787
|
storeId: msg.storeId,
|
|
776
788
|
fileDate: msg.fileDate,
|
|
@@ -779,11 +791,18 @@ export async function getAuditFile( req, res ) {
|
|
|
779
791
|
};
|
|
780
792
|
break;
|
|
781
793
|
case 'cleaning':
|
|
794
|
+
getQuery ={
|
|
795
|
+
storeId: msg.storeId,
|
|
796
|
+
fileDate: msg.fileDate,
|
|
797
|
+
moduleType: inputData.moduleType,
|
|
798
|
+
};
|
|
799
|
+
break;
|
|
782
800
|
case 'scrum':
|
|
783
801
|
getQuery ={
|
|
784
802
|
storeId: msg.storeId,
|
|
785
803
|
fileDate: msg.fileDate,
|
|
786
804
|
moduleType: inputData.moduleType,
|
|
805
|
+
streamName: msg.streamName,
|
|
787
806
|
};
|
|
788
807
|
break;
|
|
789
808
|
default:
|
|
@@ -903,7 +922,6 @@ export async function getUpdatedFile( req, res ) {
|
|
|
903
922
|
case 'unattended-customer':
|
|
904
923
|
case 'left-in-middle':
|
|
905
924
|
case 'cleaning':
|
|
906
|
-
case 'scrum':
|
|
907
925
|
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
908
926
|
const files = [];
|
|
909
927
|
const params ={
|
|
@@ -937,6 +955,35 @@ export async function getUpdatedFile( req, res ) {
|
|
|
937
955
|
} );
|
|
938
956
|
}
|
|
939
957
|
break;
|
|
958
|
+
case 'scrum':
|
|
959
|
+
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
960
|
+
const files = [];
|
|
961
|
+
const params ={
|
|
962
|
+
Bucket: msg.inputBucketName,
|
|
963
|
+
Key: msg?.fileDetails[i]?.folderPath,
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
const isFileExists = await checkFileExist( params );
|
|
967
|
+
if ( isFileExists ) {
|
|
968
|
+
const data = `${url.traxAuditInput}${msg?.fileDetails[i]?.folderPath}`;
|
|
969
|
+
|
|
970
|
+
files.push(
|
|
971
|
+
data,
|
|
972
|
+
);
|
|
973
|
+
} else {
|
|
974
|
+
logger.error( {
|
|
975
|
+
error: { folderPath: folderPath },
|
|
976
|
+
function: `getAuditFile - ${inputData.moduleType}`,
|
|
977
|
+
message: 'Bucket image data not availale',
|
|
978
|
+
} );
|
|
979
|
+
return res.sendError( 'File not found', 204 );
|
|
980
|
+
}
|
|
981
|
+
result.push( {
|
|
982
|
+
type: msg.fileDetails[i].type,
|
|
983
|
+
file: files,
|
|
984
|
+
} );
|
|
985
|
+
}
|
|
986
|
+
break;
|
|
940
987
|
case 'eye-test-camera':
|
|
941
988
|
const eyeTestfiles = [];
|
|
942
989
|
|
|
@@ -962,19 +1009,6 @@ export async function getUpdatedFile( req, res ) {
|
|
|
962
1009
|
file: eyeTestfiles,
|
|
963
1010
|
} );
|
|
964
1011
|
break;
|
|
965
|
-
case 'anomaly-audit':
|
|
966
|
-
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
967
|
-
const files = [];
|
|
968
|
-
const data = msg.fileDetails[i].folderPath;
|
|
969
|
-
files.push(
|
|
970
|
-
data,
|
|
971
|
-
);
|
|
972
|
-
result.push( {
|
|
973
|
-
type: msg.fileDetails[i].type,
|
|
974
|
-
file: files,
|
|
975
|
-
} );
|
|
976
|
-
}
|
|
977
|
-
break;
|
|
978
1012
|
default:
|
|
979
1013
|
return res.sendError( 'Please given valid moduleType', 400 );
|
|
980
1014
|
}
|
|
@@ -1047,8 +1081,6 @@ export async function saveBinary( req, res ) {
|
|
|
1047
1081
|
const value = inputData.moduleType? inputData.moduleType.replace( /-/g, ' ' ) : '';
|
|
1048
1082
|
switch ( inputData.moduleType ) {
|
|
1049
1083
|
case 'unattended-customer':
|
|
1050
|
-
case 'cleaning':
|
|
1051
|
-
case 'scrum':
|
|
1052
1084
|
let unattendedquery ={
|
|
1053
1085
|
_id: inputData.auditId,
|
|
1054
1086
|
storeId: inputData.storeId,
|
|
@@ -1068,66 +1100,6 @@ export async function saveBinary( req, res ) {
|
|
|
1068
1100
|
if ( updatDataunattended.modifiedCount==0 ) {
|
|
1069
1101
|
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1070
1102
|
}
|
|
1071
|
-
if ( [ 'cleaning', 'scrum' ].includes( inputData.moduleType ) ) {
|
|
1072
|
-
let filter= [
|
|
1073
|
-
{
|
|
1074
|
-
'term': {
|
|
1075
|
-
'storeId.keyword': inputData.storeId,
|
|
1076
|
-
},
|
|
1077
|
-
},
|
|
1078
|
-
{
|
|
1079
|
-
'term': {
|
|
1080
|
-
'fileDate.keyword': inputData.fileDate,
|
|
1081
|
-
},
|
|
1082
|
-
},
|
|
1083
|
-
{
|
|
1084
|
-
'term': {
|
|
1085
|
-
'moduleType.keyword': inputData.moduleType,
|
|
1086
|
-
},
|
|
1087
|
-
},
|
|
1088
|
-
];
|
|
1089
|
-
let searchQuery={
|
|
1090
|
-
'size': 1,
|
|
1091
|
-
'query': {
|
|
1092
|
-
'bool': {
|
|
1093
|
-
'must': filter,
|
|
1094
|
-
},
|
|
1095
|
-
},
|
|
1096
|
-
};
|
|
1097
|
-
const [ getStore, getClient ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: req.userAudit?.clientId }, { clientName: 1 } ) ] );
|
|
1098
|
-
const getFilePath = await findOneTraxAuditData(
|
|
1099
|
-
{
|
|
1100
|
-
fileDate: inputData.fileDate,
|
|
1101
|
-
storeId: inputData.storeId,
|
|
1102
|
-
moduleType: inputData.moduleType,
|
|
1103
|
-
},
|
|
1104
|
-
);
|
|
1105
|
-
const output = {
|
|
1106
|
-
clientId: req.userAudit?.clientId,
|
|
1107
|
-
clientName: getClient?.clientName,
|
|
1108
|
-
storeId: inputData.storeId,
|
|
1109
|
-
storeName: getStore?.storeName,
|
|
1110
|
-
question: getFilePath?.sqs?.Body?.question,
|
|
1111
|
-
spocName: getStore?.spocDetails? getStore?.spocDetails[0]?.name : '',
|
|
1112
|
-
spocEmail: getStore?.spocDetails? getStore?.spocDetails[0]?.email:'',
|
|
1113
|
-
spocContact: getStore?.spocDetails? getStore?.spocDetails[0].contact:'',
|
|
1114
|
-
address: getStore?.storeProfile?.address,
|
|
1115
|
-
fileDate: inputData.fileDate,
|
|
1116
|
-
moduleType: inputData.moduleType,
|
|
1117
|
-
Answer: inputData.answer,
|
|
1118
|
-
configTime: getFilePath?.sqs?.Body?.configTime,
|
|
1119
|
-
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
1120
|
-
folderPath: [ 'cleaning', 'scrum' ].includes( inputData.moduleType ) ? getFilePath?.sqs?.Body?.fileDetails[0]?.outputFilePath : folderPath.split( '/' ).slice( 0, -1 ).join( '/' ) + '/',
|
|
1121
|
-
createdAt: new Date(),
|
|
1122
|
-
};
|
|
1123
|
-
const searchData= await getOpenSearchData( openSearch.traxDetectionOutput, searchQuery );
|
|
1124
|
-
logger.info( { length: searchData?.body?.hits?.hits?.length, _id: searchData?.body?.hits?.hits[0]?._id, output: output } );
|
|
1125
|
-
if ( searchData?.body?.hits?.hits?.length >0 ) {
|
|
1126
|
-
await updateOpenSearchData( openSearch.traxDetectionOutput, searchData?.body?.hits?.hits[0]?._id, { doc: output } );
|
|
1127
|
-
} else {
|
|
1128
|
-
await insertOpenSearchData( openSearch.traxDetectionOutput, output );
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
1103
|
const logData2 = {
|
|
1132
1104
|
userId: req.user._id,
|
|
1133
1105
|
userName: req.user.userName,
|
|
@@ -1140,8 +1112,6 @@ export async function saveBinary( req, res ) {
|
|
|
1140
1112
|
moduleType: req.userAudit?.moduleType,
|
|
1141
1113
|
queueName: req.userAudit?.queueName,
|
|
1142
1114
|
clientId: req.userAudit?.clientId,
|
|
1143
|
-
// beforeCount: req.userAudit?.beforeCount,
|
|
1144
|
-
// afterCount: inputData.employeeCount,
|
|
1145
1115
|
startTime: req.userAudit?.startTime,
|
|
1146
1116
|
streamName: req.userAudit?.streamName,
|
|
1147
1117
|
tempId: req.userAudit?.tempId,
|
|
@@ -1157,63 +1127,87 @@ export async function saveBinary( req, res ) {
|
|
|
1157
1127
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1158
1128
|
|
|
1159
1129
|
break;
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
let uniformDetectionQuery ={
|
|
1130
|
+
case 'cleaning':
|
|
1131
|
+
let cleaningQuery ={
|
|
1163
1132
|
_id: inputData.auditId,
|
|
1164
1133
|
storeId: inputData.storeId,
|
|
1165
1134
|
fileDate: inputData.fileDate,
|
|
1166
|
-
// tempId: inputData.tempId,
|
|
1167
1135
|
moduleType: inputData.moduleType,
|
|
1168
1136
|
};
|
|
1169
1137
|
|
|
1170
|
-
let
|
|
1138
|
+
let cleaningUpdate={
|
|
1171
1139
|
auditStatus: 'completed',
|
|
1172
1140
|
answer: inputData.answer,
|
|
1173
1141
|
userComments: inputData.userComments || '',
|
|
1174
1142
|
endTime: new Date(),
|
|
1175
1143
|
timeSpent: timeDifferenceInMinutes,
|
|
1176
1144
|
};
|
|
1177
|
-
let
|
|
1178
|
-
if (
|
|
1145
|
+
let updatDataCleaning= await updateOneBinaryAuditModel( cleaningQuery, cleaningUpdate );
|
|
1146
|
+
if ( updatDataCleaning.modifiedCount==0 ) {
|
|
1179
1147
|
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1180
1148
|
}
|
|
1181
|
-
|
|
1149
|
+
let cleaningFilter= [
|
|
1150
|
+
{
|
|
1151
|
+
'term': {
|
|
1152
|
+
'storeId.keyword': inputData.storeId,
|
|
1153
|
+
},
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
'term': {
|
|
1157
|
+
'fileDate.keyword': inputData.fileDate,
|
|
1158
|
+
},
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
'term': {
|
|
1162
|
+
'moduleType.keyword': inputData.moduleType,
|
|
1163
|
+
},
|
|
1164
|
+
},
|
|
1165
|
+
];
|
|
1166
|
+
let cleaningSearchQuery={
|
|
1167
|
+
'size': 1,
|
|
1168
|
+
'query': {
|
|
1169
|
+
'bool': {
|
|
1170
|
+
'must': cleaningFilter,
|
|
1171
|
+
},
|
|
1172
|
+
},
|
|
1173
|
+
};
|
|
1174
|
+
const [ getStore, getClient ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: req.userAudit?.clientId }, { clientName: 1 } ) ] );
|
|
1175
|
+
const getCleaningFilePath = await findOneTraxAuditData(
|
|
1182
1176
|
{
|
|
1183
1177
|
fileDate: inputData.fileDate,
|
|
1184
1178
|
storeId: inputData.storeId,
|
|
1185
1179
|
moduleType: inputData.moduleType,
|
|
1186
|
-
tempId: inputData.tempId,
|
|
1187
1180
|
},
|
|
1188
1181
|
);
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1182
|
+
const output = {
|
|
1183
|
+
clientId: req.userAudit?.clientId,
|
|
1184
|
+
clientName: getClient?.clientName,
|
|
1185
|
+
storeId: inputData.storeId,
|
|
1186
|
+
storeName: getStore?.storeName,
|
|
1187
|
+
question: getCleaningFilePath?.sqs?.Body?.question,
|
|
1188
|
+
spocName: getStore?.spocDetails? getStore?.spocDetails[0]?.name : '',
|
|
1189
|
+
spocEmail: getStore?.spocDetails? getStore?.spocDetails[0]?.email:'',
|
|
1190
|
+
spocContact: getStore?.spocDetails? getStore?.spocDetails[0].contact:'',
|
|
1191
|
+
address: getStore?.storeProfile?.address,
|
|
1192
|
+
fileDate: inputData.fileDate,
|
|
1193
|
+
moduleType: inputData.moduleType,
|
|
1194
|
+
Answer: inputData.answer,
|
|
1195
|
+
configTime: getCleaningFilePath?.sqs?.Body?.configTime,
|
|
1196
|
+
isDownTime: getCleaningFilePath?.sqs?.Body?.isDownTime,
|
|
1197
|
+
downTime: getCleaningFilePath?.sqs?.Body?.downTime,
|
|
1198
|
+
inputBucketName: getCleaningFilePath?.sqs?.Body?.inputBucketName,
|
|
1199
|
+
folderPath: getCleaningFilePath?.sqs?.Body?.fileDetails[0]?.outputFilePath,
|
|
1200
|
+
createdAt: new Date(),
|
|
1203
1201
|
};
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
logger.error( {
|
|
1211
|
-
error: `${sqsQueue}`,
|
|
1212
|
-
type: 'UPLOAD_ERROR',
|
|
1213
|
-
} );
|
|
1214
|
-
return res.sendError( 'SQS not sent', 500 );
|
|
1202
|
+
const cleaningSearchData= await getOpenSearchData( openSearch.traxDetectionOutput, cleaningSearchQuery );
|
|
1203
|
+
logger.info( { length: cleaningSearchData?.body?.hits?.hits?.length, _id: cleaningSearchData?.body?.hits?.hits[0]?._id, output: output } );
|
|
1204
|
+
if ( cleaningSearchData?.body?.hits?.hits?.length >0 ) {
|
|
1205
|
+
await updateOpenSearchData( openSearch.traxDetectionOutput, cleaningSearchData?.body?.hits?.hits[0]?._id, { doc: output } );
|
|
1206
|
+
} else {
|
|
1207
|
+
await insertOpenSearchData( openSearch.traxDetectionOutput, output );
|
|
1215
1208
|
}
|
|
1216
|
-
|
|
1209
|
+
|
|
1210
|
+
const logDataClean = {
|
|
1217
1211
|
userId: req.user._id,
|
|
1218
1212
|
userName: req.user.userName,
|
|
1219
1213
|
logType: 'traxAudit',
|
|
@@ -1225,8 +1219,6 @@ export async function saveBinary( req, res ) {
|
|
|
1225
1219
|
moduleType: req.userAudit?.moduleType,
|
|
1226
1220
|
queueName: req.userAudit?.queueName,
|
|
1227
1221
|
clientId: req.userAudit?.clientId,
|
|
1228
|
-
// beforeCount: req.userAudit?.beforeCount,
|
|
1229
|
-
// afterCount: inputData.employeeCount,
|
|
1230
1222
|
startTime: req.userAudit?.startTime,
|
|
1231
1223
|
streamName: req.userAudit?.streamName,
|
|
1232
1224
|
tempId: req.userAudit?.tempId,
|
|
@@ -1238,30 +1230,108 @@ export async function saveBinary( req, res ) {
|
|
|
1238
1230
|
},
|
|
1239
1231
|
createdAt: Date.now(),
|
|
1240
1232
|
};
|
|
1241
|
-
await insertOpenSearchData( openSearch.auditLog,
|
|
1233
|
+
await insertOpenSearchData( openSearch.auditLog, logDataClean );
|
|
1242
1234
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1243
|
-
break;
|
|
1244
1235
|
|
|
1245
|
-
|
|
1246
|
-
|
|
1236
|
+
break;
|
|
1237
|
+
case 'scrum':
|
|
1238
|
+
let scrumQuery ={
|
|
1247
1239
|
_id: inputData.auditId,
|
|
1248
1240
|
storeId: inputData.storeId,
|
|
1249
1241
|
fileDate: inputData.fileDate,
|
|
1250
|
-
|
|
1242
|
+
tempId: inputData.tempId,
|
|
1251
1243
|
moduleType: inputData.moduleType,
|
|
1252
1244
|
};
|
|
1253
|
-
|
|
1245
|
+
|
|
1246
|
+
let scrumUpdate={
|
|
1254
1247
|
auditStatus: 'completed',
|
|
1255
1248
|
answer: inputData.answer,
|
|
1256
1249
|
userComments: inputData.userComments || '',
|
|
1257
1250
|
endTime: new Date(),
|
|
1258
1251
|
timeSpent: timeDifferenceInMinutes,
|
|
1259
1252
|
};
|
|
1260
|
-
let
|
|
1261
|
-
if (
|
|
1253
|
+
let updateScrum= await updateOneBinaryAuditModel( scrumQuery, scrumUpdate );
|
|
1254
|
+
if ( updateScrum.modifiedCount==0 ) {
|
|
1262
1255
|
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1263
1256
|
}
|
|
1264
|
-
|
|
1257
|
+
|
|
1258
|
+
let scrumFilter= [
|
|
1259
|
+
{
|
|
1260
|
+
'term': {
|
|
1261
|
+
'storeId.keyword': inputData.storeId,
|
|
1262
|
+
},
|
|
1263
|
+
},
|
|
1264
|
+
{
|
|
1265
|
+
'term': {
|
|
1266
|
+
'fileDate.keyword': inputData.fileDate,
|
|
1267
|
+
},
|
|
1268
|
+
},
|
|
1269
|
+
{
|
|
1270
|
+
'term': {
|
|
1271
|
+
'moduleType.keyword': inputData.moduleType,
|
|
1272
|
+
},
|
|
1273
|
+
},
|
|
1274
|
+
{
|
|
1275
|
+
'term': {
|
|
1276
|
+
'streamName.keyword': req.userAudit?.streamName,
|
|
1277
|
+
},
|
|
1278
|
+
},
|
|
1279
|
+
];
|
|
1280
|
+
let scrumSearchQuery={
|
|
1281
|
+
'size': 1,
|
|
1282
|
+
'query': {
|
|
1283
|
+
'bool': {
|
|
1284
|
+
'must': scrumFilter,
|
|
1285
|
+
},
|
|
1286
|
+
},
|
|
1287
|
+
};
|
|
1288
|
+
const [ getStore1, getClient1 ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: req.userAudit?.clientId }, { clientName: 1 } ) ] );
|
|
1289
|
+
const getScrumFilePath = await findOneTraxAuditData(
|
|
1290
|
+
{
|
|
1291
|
+
fileDate: inputData.fileDate,
|
|
1292
|
+
storeId: inputData.storeId,
|
|
1293
|
+
moduleType: inputData.moduleType,
|
|
1294
|
+
streamName: req.userAudit?.streamName,
|
|
1295
|
+
},
|
|
1296
|
+
);
|
|
1297
|
+
logger.info( { getScrumFilePath: getScrumFilePath, data: {
|
|
1298
|
+
fileDate: inputData.fileDate,
|
|
1299
|
+
storeId: inputData.storeId,
|
|
1300
|
+
moduleType: inputData.moduleType,
|
|
1301
|
+
streamName: req.userAudit?.streamName,
|
|
1302
|
+
}, mesage: '.............1' } );
|
|
1303
|
+
const scrumOutput = {
|
|
1304
|
+
clientId: req.userAudit?.clientId,
|
|
1305
|
+
clientName: getClient1?.clientName,
|
|
1306
|
+
storeId: inputData.storeId,
|
|
1307
|
+
storeName: getStore1?.storeName,
|
|
1308
|
+
streamName: req.userAudit?.streamName,
|
|
1309
|
+
question: getScrumFilePath?.sqs?.Body?.question,
|
|
1310
|
+
spocName: getStore1?.spocDetails? getStore1?.spocDetails[0]?.name : '',
|
|
1311
|
+
spocEmail: getStore1?.spocDetails? getStore1?.spocDetails[0]?.email:'',
|
|
1312
|
+
spocContact: getStore1?.spocDetails? getStore1?.spocDetails[0].contact:'',
|
|
1313
|
+
address: getStore1?.storeProfile?.address,
|
|
1314
|
+
fileDate: inputData.fileDate,
|
|
1315
|
+
moduleType: inputData.moduleType,
|
|
1316
|
+
Answer: inputData.answer,
|
|
1317
|
+
configTime: getScrumFilePath?.sqs?.Body?.configTime,
|
|
1318
|
+
huddleDuration: getScrumFilePath?.sqs?.Body?.huddleDuration,
|
|
1319
|
+
huddleSlot: getScrumFilePath?.sqs?.Body?.huddleSlot,
|
|
1320
|
+
isDownTime: getScrumFilePath?.sqs?.Body?.isDownTime,
|
|
1321
|
+
downTime: getScrumFilePath?.sqs?.Body?.downTime,
|
|
1322
|
+
inputBucketName: getScrumFilePath?.sqs?.Body?.inputBucketName,
|
|
1323
|
+
folderPath: getScrumFilePath?.sqs?.Body?.fileDetails[0]?.outputFilePath,
|
|
1324
|
+
createdAt: new Date(),
|
|
1325
|
+
};
|
|
1326
|
+
const scrumSearchData= await getOpenSearchData( openSearch.traxDetectionOutput, scrumSearchQuery );
|
|
1327
|
+
logger.info( { length: scrumSearchData?.body?.hits?.hits?.length, _id: scrumSearchData?.body?.hits?.hits[0]?._id, output: scrumOutput } );
|
|
1328
|
+
if ( scrumSearchData?.body?.hits?.hits?.length >0 ) {
|
|
1329
|
+
await updateOpenSearchData( openSearch.traxDetectionOutput, scrumSearchData?.body?.hits?.hits[0]?._id, { doc: scrumOutput } );
|
|
1330
|
+
} else {
|
|
1331
|
+
await insertOpenSearchData( openSearch.traxDetectionOutput, scrumOutput );
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
const scrumLogData = {
|
|
1265
1335
|
userId: req.user._id,
|
|
1266
1336
|
userName: req.user.userName,
|
|
1267
1337
|
logType: 'traxAudit',
|
|
@@ -1273,8 +1343,6 @@ export async function saveBinary( req, res ) {
|
|
|
1273
1343
|
moduleType: req.userAudit?.moduleType,
|
|
1274
1344
|
queueName: req.userAudit?.queueName,
|
|
1275
1345
|
clientId: req.userAudit?.clientId,
|
|
1276
|
-
// beforeCount: req.userAudit?.beforeCount,
|
|
1277
|
-
// afterCount: inputData.employeeCount,
|
|
1278
1346
|
startTime: req.userAudit?.startTime,
|
|
1279
1347
|
streamName: req.userAudit?.streamName,
|
|
1280
1348
|
tempId: req.userAudit?.tempId,
|
|
@@ -1286,17 +1354,150 @@ export async function saveBinary( req, res ) {
|
|
|
1286
1354
|
},
|
|
1287
1355
|
createdAt: Date.now(),
|
|
1288
1356
|
};
|
|
1289
|
-
await insertOpenSearchData( openSearch.auditLog,
|
|
1357
|
+
await insertOpenSearchData( openSearch.auditLog, scrumLogData );
|
|
1290
1358
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1291
1359
|
|
|
1292
1360
|
break;
|
|
1293
1361
|
|
|
1294
|
-
case '
|
|
1295
|
-
let
|
|
1362
|
+
case 'uniform-detection':
|
|
1363
|
+
let uniformDetectionQuery ={
|
|
1296
1364
|
_id: inputData.auditId,
|
|
1297
1365
|
storeId: inputData.storeId,
|
|
1298
1366
|
fileDate: inputData.fileDate,
|
|
1299
|
-
|
|
1367
|
+
// tempId: inputData.tempId,
|
|
1368
|
+
moduleType: inputData.moduleType,
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
let updateUniform={
|
|
1372
|
+
auditStatus: 'completed',
|
|
1373
|
+
answer: inputData.answer,
|
|
1374
|
+
userComments: inputData.userComments || '',
|
|
1375
|
+
endTime: new Date(),
|
|
1376
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1377
|
+
};
|
|
1378
|
+
let updatDataUniform= await updateOneBinaryAuditModel( uniformDetectionQuery, updateUniform );
|
|
1379
|
+
if ( updatDataUniform.modifiedCount==0 ) {
|
|
1380
|
+
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1381
|
+
}
|
|
1382
|
+
const getFilePath = await findOneTraxAuditData(
|
|
1383
|
+
{
|
|
1384
|
+
fileDate: inputData.fileDate,
|
|
1385
|
+
storeId: inputData.storeId,
|
|
1386
|
+
moduleType: inputData.moduleType,
|
|
1387
|
+
tempId: inputData.tempId,
|
|
1388
|
+
},
|
|
1389
|
+
);
|
|
1390
|
+
if ( !getFilePath ) {
|
|
1391
|
+
return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
|
|
1392
|
+
}
|
|
1393
|
+
const sqsProduceQueue = {
|
|
1394
|
+
QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
|
|
1395
|
+
MessageBody: JSON.stringify( {
|
|
1396
|
+
storeId: inputData.storeId,
|
|
1397
|
+
fileDate: inputData.fileDate,
|
|
1398
|
+
tempId: inputData.tempId,
|
|
1399
|
+
moduleType: inputData.moduleType,
|
|
1400
|
+
answer: inputData.answer,
|
|
1401
|
+
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
1402
|
+
filePath: getFilePath?.sqs?.Body?.filePath,
|
|
1403
|
+
} ),
|
|
1404
|
+
};
|
|
1405
|
+
const sqsQueue = await sendMessageToQueue(
|
|
1406
|
+
sqsProduceQueue.QueueUrl,
|
|
1407
|
+
sqsProduceQueue.MessageBody,
|
|
1408
|
+
);
|
|
1409
|
+
|
|
1410
|
+
if ( sqsQueue.statusCode ) {
|
|
1411
|
+
logger.error( {
|
|
1412
|
+
error: `${sqsQueue}`,
|
|
1413
|
+
type: 'UPLOAD_ERROR',
|
|
1414
|
+
} );
|
|
1415
|
+
return res.sendError( 'SQS not sent', 500 );
|
|
1416
|
+
}
|
|
1417
|
+
const logData3 = {
|
|
1418
|
+
userId: req.user._id,
|
|
1419
|
+
userName: req.user.userName,
|
|
1420
|
+
logType: 'traxAudit',
|
|
1421
|
+
logSubType: 'auditDone',
|
|
1422
|
+
logData: {
|
|
1423
|
+
fileDate: req.userAudit?.fileDate,
|
|
1424
|
+
auditType: req.userAudit?.auditType,
|
|
1425
|
+
storeId: req.userAudit?.storeId,
|
|
1426
|
+
moduleType: req.userAudit?.moduleType,
|
|
1427
|
+
queueName: req.userAudit?.queueName,
|
|
1428
|
+
clientId: req.userAudit?.clientId,
|
|
1429
|
+
// beforeCount: req.userAudit?.beforeCount,
|
|
1430
|
+
// afterCount: inputData.employeeCount,
|
|
1431
|
+
startTime: req.userAudit?.startTime,
|
|
1432
|
+
streamName: req.userAudit?.streamName,
|
|
1433
|
+
tempId: req.userAudit?.tempId,
|
|
1434
|
+
question: req.userAudit?.question,
|
|
1435
|
+
result: req.userAudit?.answer,
|
|
1436
|
+
endTime: Date.now(),
|
|
1437
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1438
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1439
|
+
},
|
|
1440
|
+
createdAt: Date.now(),
|
|
1441
|
+
};
|
|
1442
|
+
await insertOpenSearchData( openSearch.auditLog, logData3 );
|
|
1443
|
+
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1444
|
+
break;
|
|
1445
|
+
|
|
1446
|
+
case 'left-in-middle':
|
|
1447
|
+
let leftquery ={
|
|
1448
|
+
_id: inputData.auditId,
|
|
1449
|
+
storeId: inputData.storeId,
|
|
1450
|
+
fileDate: inputData.fileDate,
|
|
1451
|
+
question: inputData.question,
|
|
1452
|
+
moduleType: inputData.moduleType,
|
|
1453
|
+
};
|
|
1454
|
+
let leftupdate={
|
|
1455
|
+
auditStatus: 'completed',
|
|
1456
|
+
answer: inputData.answer,
|
|
1457
|
+
userComments: inputData.userComments || '',
|
|
1458
|
+
endTime: new Date(),
|
|
1459
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1460
|
+
};
|
|
1461
|
+
let updatDataleft= await updateOneBinaryAuditModel( leftquery, leftupdate );
|
|
1462
|
+
if ( updatDataleft.modifiedCount==0 ) {
|
|
1463
|
+
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1464
|
+
}
|
|
1465
|
+
const logData1 = {
|
|
1466
|
+
userId: req.user._id,
|
|
1467
|
+
userName: req.user.userName,
|
|
1468
|
+
logType: 'traxAudit',
|
|
1469
|
+
logSubType: 'auditDone',
|
|
1470
|
+
logData: {
|
|
1471
|
+
fileDate: req.userAudit?.fileDate,
|
|
1472
|
+
auditType: req.userAudit?.auditType,
|
|
1473
|
+
storeId: req.userAudit?.storeId,
|
|
1474
|
+
moduleType: req.userAudit?.moduleType,
|
|
1475
|
+
queueName: req.userAudit?.queueName,
|
|
1476
|
+
clientId: req.userAudit?.clientId,
|
|
1477
|
+
// beforeCount: req.userAudit?.beforeCount,
|
|
1478
|
+
// afterCount: inputData.employeeCount,
|
|
1479
|
+
startTime: req.userAudit?.startTime,
|
|
1480
|
+
streamName: req.userAudit?.streamName,
|
|
1481
|
+
tempId: req.userAudit?.tempId,
|
|
1482
|
+
question: req.userAudit?.question,
|
|
1483
|
+
result: req.userAudit?.answer,
|
|
1484
|
+
endTime: Date.now(),
|
|
1485
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1486
|
+
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1487
|
+
},
|
|
1488
|
+
createdAt: Date.now(),
|
|
1489
|
+
};
|
|
1490
|
+
await insertOpenSearchData( openSearch.auditLog, logData1 );
|
|
1491
|
+
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1492
|
+
|
|
1493
|
+
break;
|
|
1494
|
+
|
|
1495
|
+
case 'camera-angle-change':
|
|
1496
|
+
let cameraquery ={
|
|
1497
|
+
_id: inputData.auditId,
|
|
1498
|
+
storeId: inputData.storeId,
|
|
1499
|
+
fileDate: inputData.fileDate,
|
|
1500
|
+
streamName: inputData.streamName,
|
|
1300
1501
|
moduleType: inputData.moduleType,
|
|
1301
1502
|
};
|
|
1302
1503
|
let cameraupdate={
|
|
@@ -1421,120 +1622,6 @@ export async function saveBinary( req, res ) {
|
|
|
1421
1622
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1422
1623
|
}
|
|
1423
1624
|
|
|
1424
|
-
case 'anomaly-audit':
|
|
1425
|
-
let anomalyQury ={
|
|
1426
|
-
_id: inputData.auditId,
|
|
1427
|
-
storeId: inputData.storeId,
|
|
1428
|
-
fileDate: inputData.fileDate,
|
|
1429
|
-
tempId: inputData.tempId,
|
|
1430
|
-
moduleType: inputData.moduleType,
|
|
1431
|
-
};
|
|
1432
|
-
|
|
1433
|
-
let anomalyRecord={
|
|
1434
|
-
auditStatus: 'completed',
|
|
1435
|
-
answer: inputData.answer,
|
|
1436
|
-
userComments: inputData.userComments || '',
|
|
1437
|
-
endTime: new Date(),
|
|
1438
|
-
timeSpent: timeDifferenceInMinutes,
|
|
1439
|
-
};
|
|
1440
|
-
let updatedAnomaly= await updateOneBinaryAuditModel( anomalyQury, anomalyRecord );
|
|
1441
|
-
if ( updatedAnomaly==0 ) {
|
|
1442
|
-
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1443
|
-
}
|
|
1444
|
-
let anomalyFilter= [
|
|
1445
|
-
{
|
|
1446
|
-
'term': {
|
|
1447
|
-
'storeId.keyword': inputData.storeId,
|
|
1448
|
-
},
|
|
1449
|
-
},
|
|
1450
|
-
{
|
|
1451
|
-
'term': {
|
|
1452
|
-
'fileDate.keyword': inputData.fileDate,
|
|
1453
|
-
},
|
|
1454
|
-
},
|
|
1455
|
-
{
|
|
1456
|
-
'term': {
|
|
1457
|
-
'moduleType.keyword': inputData.moduleType,
|
|
1458
|
-
},
|
|
1459
|
-
},
|
|
1460
|
-
{
|
|
1461
|
-
'term': {
|
|
1462
|
-
'moduleType.keyword': inputData.streamName,
|
|
1463
|
-
},
|
|
1464
|
-
},
|
|
1465
|
-
];
|
|
1466
|
-
let anomalySearchQuery={
|
|
1467
|
-
'size': 1,
|
|
1468
|
-
'query': {
|
|
1469
|
-
'bool': {
|
|
1470
|
-
'must': anomalyFilter,
|
|
1471
|
-
},
|
|
1472
|
-
},
|
|
1473
|
-
};
|
|
1474
|
-
const [ getStore, getClient ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: req.userAudit?.clientId }, { clientName: 1 } ) ] );
|
|
1475
|
-
const getData = await findOneTraxAuditData(
|
|
1476
|
-
{
|
|
1477
|
-
fileDate: inputData.fileDate,
|
|
1478
|
-
storeId: inputData.storeId,
|
|
1479
|
-
moduleType: inputData.moduleType,
|
|
1480
|
-
streamName: req.userAudit?.streamName,
|
|
1481
|
-
},
|
|
1482
|
-
);
|
|
1483
|
-
const output = {
|
|
1484
|
-
clientId: req.userAudit?.clientId,
|
|
1485
|
-
clientName: getClient?.clientName,
|
|
1486
|
-
storeId: inputData.storeId,
|
|
1487
|
-
storeName: getStore?.storeName,
|
|
1488
|
-
question: getData?.sqs?.Body?.question,
|
|
1489
|
-
spocName: getStore?.spocDetails? getStore?.spocDetails[0]?.name : '',
|
|
1490
|
-
spocEmail: getStore?.spocDetails? getStore?.spocDetails[0]?.email:'',
|
|
1491
|
-
spocContact: getStore?.spocDetails? getStore?.spocDetails[0].contact:'',
|
|
1492
|
-
address: getStore?.storeProfile?.address,
|
|
1493
|
-
fileDate: inputData.fileDate,
|
|
1494
|
-
moduleType: inputData.moduleType,
|
|
1495
|
-
Answer: inputData.answer,
|
|
1496
|
-
configTime: getData?.sqs?.Body?.configTime,
|
|
1497
|
-
inputBucketName: getData?.sqs?.Body?.inputBucketName,
|
|
1498
|
-
incidentType: getData?.sqs?.Body?.incidentType,
|
|
1499
|
-
incidentId: getData?.sqs?.Body?.incidentId,
|
|
1500
|
-
incidentTime: getData?.sqs?.Body?.incidentTime,
|
|
1501
|
-
thumnailImage: getData?.sqs?.Body?.thumnailImage,
|
|
1502
|
-
folderPath: getData?.sqs?.Body?.fileDetails[0]?.outputFilePath,
|
|
1503
|
-
createdAt: new Date(),
|
|
1504
|
-
};
|
|
1505
|
-
const anomalySearchData= await getOpenSearchData( openSearch.traxDetectionOutput, anomalySearchQuery );
|
|
1506
|
-
logger.info( { length: anomalySearchData?.body?.hits?.hits?.length, _id: anomalySearchData?.body?.hits?.hits[0]?._id, output: output } );
|
|
1507
|
-
if ( anomalySearchData?.body?.hits?.hits?.length >0 ) {
|
|
1508
|
-
await updateOpenSearchData( openSearch.traxDetectionOutput, anomalySearchData?.body?.hits?.hits[0]?._id, { doc: output } );
|
|
1509
|
-
} else {
|
|
1510
|
-
await insertOpenSearchData( openSearch.traxDetectionOutput, output );
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
const logData4 = {
|
|
1514
|
-
userId: req.user._id,
|
|
1515
|
-
userName: req.user.userName,
|
|
1516
|
-
logType: 'traxAudit',
|
|
1517
|
-
logSubType: 'auditDone',
|
|
1518
|
-
logData: {
|
|
1519
|
-
fileDate: req.userAudit?.fileDate,
|
|
1520
|
-
auditType: req.userAudit?.auditType,
|
|
1521
|
-
storeId: req.userAudit?.storeId,
|
|
1522
|
-
moduleType: req.userAudit?.moduleType,
|
|
1523
|
-
queueName: req.userAudit?.queueName,
|
|
1524
|
-
clientId: req.userAudit?.clientId,
|
|
1525
|
-
startTime: req.userAudit?.startTime,
|
|
1526
|
-
streamName: req.userAudit?.streamName,
|
|
1527
|
-
tempId: req.userAudit?.tempId,
|
|
1528
|
-
question: req.userAudit?.question,
|
|
1529
|
-
result: req.userAudit?.answer,
|
|
1530
|
-
endTime: Date.now(),
|
|
1531
|
-
timeSpent: timeDifferenceInMinutes,
|
|
1532
|
-
auditId: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1533
|
-
},
|
|
1534
|
-
createdAt: Date.now(),
|
|
1535
|
-
};
|
|
1536
|
-
await insertOpenSearchData( openSearch.auditLog, logData4 );
|
|
1537
|
-
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1538
1625
|
|
|
1539
1626
|
default:
|
|
1540
1627
|
res.sendError( 'No Data', 204 );
|
|
@@ -1649,7 +1736,6 @@ export async function userAuditHistory( req, res ) {
|
|
|
1649
1736
|
},
|
|
1650
1737
|
];
|
|
1651
1738
|
break;
|
|
1652
|
-
case 'anomaly-audit':
|
|
1653
1739
|
case 'camera-angle-change':
|
|
1654
1740
|
traxAuditDataQuery= {
|
|
1655
1741
|
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
|
|
@@ -1837,6 +1923,9 @@ export async function userAuditHistory( req, res ) {
|
|
|
1837
1923
|
timezone: 'Asia/Kolkata',
|
|
1838
1924
|
},
|
|
1839
1925
|
},
|
|
1926
|
+
// timeSpent: { $round: [
|
|
1927
|
+
// { $divide: [ '$timeSpent', 60 ] }, 2,
|
|
1928
|
+
// ] },
|
|
1840
1929
|
timeSpent: {
|
|
1841
1930
|
|
|
1842
1931
|
$cond: [
|
|
@@ -1927,7 +2016,6 @@ export async function userAuditHistory( req, res ) {
|
|
|
1927
2016
|
|
|
1928
2017
|
};
|
|
1929
2018
|
switch ( inputData.moduleType ) {
|
|
1930
|
-
case 'anomaly-audit':
|
|
1931
2019
|
case 'camera-angle-change':
|
|
1932
2020
|
temp['stream Name'] = element.streamName;
|
|
1933
2021
|
temp['Result'] = element.answer;
|
|
@@ -2305,176 +2393,58 @@ export async function clientMetrics( req, res ) {
|
|
|
2305
2393
|
'File Date': '$fileDate',
|
|
2306
2394
|
'Brand Name': '$clientName',
|
|
2307
2395
|
'Brand Id': '$clientId',
|
|
2308
|
-
'Product Type': '$value',
|
|
2309
|
-
'Installed Stores': '$installedStore',
|
|
2310
|
-
'Audit Stores': '$totalFilesCount',
|
|
2311
|
-
'Inprogress Stores': '$inprogressStoresCount',
|
|
2312
|
-
'Not Assigned Stores': '$notAssignedCount',
|
|
2313
|
-
'Completed Stores': '$completedStores',
|
|
2314
|
-
'Status': '$clientStatus',
|
|
2315
|
-
},
|
|
2316
|
-
},
|
|
2317
|
-
);
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
const result = await aggregateTraxAuditData( query );
|
|
2321
|
-
if ( result.length == 0 ) {
|
|
2322
|
-
return res.sendError( 'No Data Found', 204 );
|
|
2323
|
-
}
|
|
2324
|
-
if ( inputData.isExport ) {
|
|
2325
|
-
await download( result, res );
|
|
2326
|
-
return;
|
|
2327
|
-
}
|
|
2328
|
-
return res.sendSuccess( { result: result, count: count.length } );
|
|
2329
|
-
} catch ( error ) {
|
|
2330
|
-
const err = error.error || 'Internal Server Error';
|
|
2331
|
-
logger.error( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
2332
|
-
return res.sendError( err, 500 );
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
export async function storeMetrics( req, res ) {
|
|
2337
|
-
try {
|
|
2338
|
-
const inputData = req.body;
|
|
2339
|
-
const limit = inputData.limit || 10;
|
|
2340
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
2341
|
-
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
2342
|
-
let filter = [
|
|
2343
|
-
{ fileDateISO: { $gte: dateRange.start } },
|
|
2344
|
-
{ fileDateISO: { $lte: dateRange.end } },
|
|
2345
|
-
{ moduleType: { $eq: inputData.moduleType } },
|
|
2346
|
-
{ clientId: { $in: inputData.filterByClientId } },
|
|
2347
|
-
|
|
2348
|
-
];
|
|
2349
|
-
|
|
2350
|
-
if ( inputData.filterByStoreId && inputData.filterByStoreId?.length > 0 ) {
|
|
2351
|
-
filter.push( { storeId: { $in: inputData.filterByStoreId } } );
|
|
2352
|
-
}
|
|
2353
|
-
|
|
2354
|
-
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
2355
|
-
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
|
-
if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
|
|
2359
|
-
filter.push( { auditType: { $in: inputData.filterByAuditType } } );
|
|
2360
|
-
}
|
|
2361
|
-
let traxAuditDataQuery ={};
|
|
2362
|
-
let traxAuditDataFilter = [];
|
|
2363
|
-
switch ( inputData.moduleType ) {
|
|
2364
|
-
case 'unattended-customer':
|
|
2365
|
-
traxAuditDataQuery= {
|
|
2366
|
-
fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
|
|
2367
|
-
};
|
|
2368
|
-
traxAuditDataFilter=[ {
|
|
2369
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
2370
|
-
},
|
|
2371
|
-
{
|
|
2372
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
2373
|
-
},
|
|
2374
|
-
{
|
|
2375
|
-
$eq: [ '$tempId', '$$tempId' ],
|
|
2376
|
-
},
|
|
2377
|
-
{
|
|
2378
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
2379
|
-
},
|
|
2380
|
-
];
|
|
2381
|
-
break;
|
|
2382
|
-
case 'left-in-middle':
|
|
2383
|
-
traxAuditDataQuery= {
|
|
2384
|
-
fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
|
|
2385
|
-
};
|
|
2386
|
-
traxAuditDataFilter=[ {
|
|
2387
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
2388
|
-
},
|
|
2389
|
-
{
|
|
2390
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
2391
|
-
},
|
|
2392
|
-
{
|
|
2393
|
-
$eq: [ '$question', '$$question' ],
|
|
2394
|
-
},
|
|
2395
|
-
{
|
|
2396
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
2397
|
-
},
|
|
2398
|
-
];
|
|
2399
|
-
break;
|
|
2400
|
-
case 'uniform-detection':
|
|
2401
|
-
case 'mobile-detection':
|
|
2402
|
-
case 'scrum':
|
|
2403
|
-
case 'cleaning':
|
|
2404
|
-
traxAuditDataQuery= {
|
|
2405
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType',
|
|
2406
|
-
};
|
|
2407
|
-
traxAuditDataFilter=[ {
|
|
2408
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
2409
|
-
},
|
|
2410
|
-
{
|
|
2411
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
2412
|
-
},
|
|
2413
|
-
{
|
|
2414
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
2415
|
-
},
|
|
2416
|
-
];
|
|
2417
|
-
break;
|
|
2418
|
-
case 'anomaly-audit':
|
|
2419
|
-
case 'camera-angle-change':
|
|
2420
|
-
traxAuditDataQuery= {
|
|
2421
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
|
|
2422
|
-
};
|
|
2423
|
-
traxAuditDataFilter=[ {
|
|
2424
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
2425
|
-
},
|
|
2426
|
-
{
|
|
2427
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
2428
|
-
},
|
|
2429
|
-
{
|
|
2430
|
-
$eq: [ '$streamName', '$$streamName' ],
|
|
2431
|
-
},
|
|
2432
|
-
{
|
|
2433
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
2434
|
-
},
|
|
2435
|
-
];
|
|
2436
|
-
break;
|
|
2437
|
-
case 'hygiene':
|
|
2438
|
-
traxAuditDataQuery= {
|
|
2439
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', zoneName: '$zoneName',
|
|
2440
|
-
};
|
|
2441
|
-
traxAuditDataFilter=[ {
|
|
2442
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
2443
|
-
},
|
|
2444
|
-
{
|
|
2445
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
2446
|
-
},
|
|
2447
|
-
{
|
|
2448
|
-
$eq: [ '$zoneName', '$$zoneName' ],
|
|
2449
|
-
},
|
|
2450
|
-
{
|
|
2451
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
2452
|
-
},
|
|
2453
|
-
];
|
|
2454
|
-
break;
|
|
2455
|
-
case 'eye-test-camera':
|
|
2456
|
-
traxAuditDataQuery= {
|
|
2457
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', question: '$question', streamName: '$streamName',
|
|
2458
|
-
};
|
|
2459
|
-
traxAuditDataFilter=[ {
|
|
2460
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
2461
|
-
},
|
|
2462
|
-
{
|
|
2463
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
2464
|
-
},
|
|
2465
|
-
{
|
|
2466
|
-
$eq: [ '$question', '$$question' ],
|
|
2467
|
-
},
|
|
2468
|
-
{
|
|
2469
|
-
$eq: [ '$streamName', '$$streamName' ],
|
|
2470
|
-
},
|
|
2471
|
-
{
|
|
2472
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
2473
|
-
},
|
|
2474
|
-
];
|
|
2475
|
-
break;
|
|
2476
|
-
default:
|
|
2477
|
-
return res.sendError( 'Please give valid modueType', 400 );
|
|
2396
|
+
'Product Type': '$value',
|
|
2397
|
+
'Installed Stores': '$installedStore',
|
|
2398
|
+
'Audit Stores': '$totalFilesCount',
|
|
2399
|
+
'Inprogress Stores': '$inprogressStoresCount',
|
|
2400
|
+
'Not Assigned Stores': '$notAssignedCount',
|
|
2401
|
+
'Completed Stores': '$completedStores',
|
|
2402
|
+
'Status': '$clientStatus',
|
|
2403
|
+
},
|
|
2404
|
+
},
|
|
2405
|
+
);
|
|
2406
|
+
}
|
|
2407
|
+
|
|
2408
|
+
const result = await aggregateTraxAuditData( query );
|
|
2409
|
+
if ( result.length == 0 ) {
|
|
2410
|
+
return res.sendError( 'No Data Found', 204 );
|
|
2411
|
+
}
|
|
2412
|
+
if ( inputData.isExport ) {
|
|
2413
|
+
await download( result, res );
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
2417
|
+
} catch ( error ) {
|
|
2418
|
+
const err = error.error || 'Internal Server Error';
|
|
2419
|
+
logger.error( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
2420
|
+
return res.sendError( err, 500 );
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
export async function storeMetrics( req, res ) {
|
|
2425
|
+
try {
|
|
2426
|
+
const inputData = req.body;
|
|
2427
|
+
const limit = inputData.limit || 10;
|
|
2428
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
2429
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
2430
|
+
let filter = [
|
|
2431
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
2432
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
2433
|
+
{ moduleType: { $eq: inputData.moduleType } },
|
|
2434
|
+
{ clientId: { $in: inputData.filterByClientId } },
|
|
2435
|
+
|
|
2436
|
+
];
|
|
2437
|
+
|
|
2438
|
+
if ( inputData.filterByStoreId && inputData.filterByStoreId?.length > 0 ) {
|
|
2439
|
+
filter.push( { storeId: { $in: inputData.filterByStoreId } } );
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
2443
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
|
|
2447
|
+
filter.push( { auditType: { $in: inputData.filterByAuditType } } );
|
|
2478
2448
|
}
|
|
2479
2449
|
|
|
2480
2450
|
|
|
@@ -2515,12 +2485,24 @@ export async function storeMetrics( req, res ) {
|
|
|
2515
2485
|
{
|
|
2516
2486
|
$lookup: {
|
|
2517
2487
|
from: 'traxAuditData',
|
|
2518
|
-
let:
|
|
2488
|
+
let: {
|
|
2489
|
+
fileDate: '$fileDate', storeId: '$storeId', zoneName: '$zoneName',
|
|
2490
|
+
},
|
|
2519
2491
|
pipeline: [
|
|
2520
2492
|
{
|
|
2521
2493
|
$match: {
|
|
2522
2494
|
$expr: {
|
|
2523
|
-
$and:
|
|
2495
|
+
$and: [
|
|
2496
|
+
{
|
|
2497
|
+
$eq: [ '$fileDate', '$$fileDate' ],
|
|
2498
|
+
},
|
|
2499
|
+
{
|
|
2500
|
+
$eq: [ '$storeId', '$$storeId' ],
|
|
2501
|
+
},
|
|
2502
|
+
{
|
|
2503
|
+
$eq: [ '$zoneName', '$$zoneName' ],
|
|
2504
|
+
},
|
|
2505
|
+
],
|
|
2524
2506
|
},
|
|
2525
2507
|
},
|
|
2526
2508
|
},
|
|
@@ -2972,7 +2954,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2972
2954
|
};
|
|
2973
2955
|
switch ( inputData.moduleType ) {
|
|
2974
2956
|
case 'camera-angle-change':
|
|
2975
|
-
case 'anomaly-audit':
|
|
2976
2957
|
temp['stream Name'] = element.streamName;
|
|
2977
2958
|
temp['User Comments'] = element.userComments;
|
|
2978
2959
|
temp['Status'] = toCamelCase( element.auditStatus );
|
|
@@ -3367,125 +3348,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3367
3348
|
if ( inputData.filterByStatus.length > 0 ) {
|
|
3368
3349
|
filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3369
3350
|
}
|
|
3370
|
-
|
|
3371
|
-
let traxAuditDataQuery={};
|
|
3372
|
-
let traxAuditDataFilter = [];
|
|
3373
|
-
switch ( inputData.moduleType ) {
|
|
3374
|
-
case 'unattended-customer':
|
|
3375
|
-
traxAuditDataQuery= {
|
|
3376
|
-
fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
|
|
3377
|
-
};
|
|
3378
|
-
traxAuditDataFilter=[ {
|
|
3379
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
3380
|
-
},
|
|
3381
|
-
{
|
|
3382
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
3383
|
-
},
|
|
3384
|
-
{
|
|
3385
|
-
$eq: [ '$tempId', '$$tempId' ],
|
|
3386
|
-
},
|
|
3387
|
-
{
|
|
3388
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
3389
|
-
},
|
|
3390
|
-
];
|
|
3391
|
-
break;
|
|
3392
|
-
case 'left-in-middle':
|
|
3393
|
-
traxAuditDataQuery= {
|
|
3394
|
-
fileDate: '$fileDate', storeId: '$storeId', tempId: '$tempId', moduleType: '$moduleType',
|
|
3395
|
-
};
|
|
3396
|
-
traxAuditDataFilter=[ {
|
|
3397
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
3398
|
-
},
|
|
3399
|
-
{
|
|
3400
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
3401
|
-
},
|
|
3402
|
-
{
|
|
3403
|
-
$eq: [ '$question', '$$question' ],
|
|
3404
|
-
},
|
|
3405
|
-
{
|
|
3406
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
3407
|
-
},
|
|
3408
|
-
];
|
|
3409
|
-
break;
|
|
3410
|
-
case 'uniform-detection':
|
|
3411
|
-
case 'mobile-detection':
|
|
3412
|
-
case 'scrum':
|
|
3413
|
-
case 'cleaning':
|
|
3414
|
-
traxAuditDataQuery= {
|
|
3415
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType',
|
|
3416
|
-
};
|
|
3417
|
-
traxAuditDataFilter=[ {
|
|
3418
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
3419
|
-
},
|
|
3420
|
-
{
|
|
3421
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
3422
|
-
},
|
|
3423
|
-
{
|
|
3424
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
3425
|
-
},
|
|
3426
|
-
];
|
|
3427
|
-
break;
|
|
3428
|
-
case 'anomaly-audit':
|
|
3429
|
-
case 'camera-angle-change':
|
|
3430
|
-
traxAuditDataQuery= {
|
|
3431
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
|
|
3432
|
-
};
|
|
3433
|
-
traxAuditDataFilter=[ {
|
|
3434
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
3435
|
-
},
|
|
3436
|
-
{
|
|
3437
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
3438
|
-
},
|
|
3439
|
-
{
|
|
3440
|
-
$eq: [ '$streamName', '$$streamName' ],
|
|
3441
|
-
},
|
|
3442
|
-
{
|
|
3443
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
3444
|
-
},
|
|
3445
|
-
];
|
|
3446
|
-
break;
|
|
3447
|
-
case 'hygiene':
|
|
3448
|
-
traxAuditDataQuery= {
|
|
3449
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', zoneName: '$zoneName',
|
|
3450
|
-
};
|
|
3451
|
-
traxAuditDataFilter=[ {
|
|
3452
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
3453
|
-
},
|
|
3454
|
-
{
|
|
3455
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
3456
|
-
},
|
|
3457
|
-
{
|
|
3458
|
-
$eq: [ '$zoneName', '$$zoneName' ],
|
|
3459
|
-
},
|
|
3460
|
-
{
|
|
3461
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
3462
|
-
},
|
|
3463
|
-
];
|
|
3464
|
-
break;
|
|
3465
|
-
case 'eye-test-camera':
|
|
3466
|
-
traxAuditDataQuery= {
|
|
3467
|
-
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', question: '$question', streamName: '$streamName',
|
|
3468
|
-
};
|
|
3469
|
-
traxAuditDataFilter=[ {
|
|
3470
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
3471
|
-
},
|
|
3472
|
-
{
|
|
3473
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
3474
|
-
},
|
|
3475
|
-
{
|
|
3476
|
-
$eq: [ '$question', '$$question' ],
|
|
3477
|
-
},
|
|
3478
|
-
{
|
|
3479
|
-
$eq: [ '$streamName', '$$streamName' ],
|
|
3480
|
-
},
|
|
3481
|
-
{
|
|
3482
|
-
$eq: [ '$moduleType', '$$moduleType' ],
|
|
3483
|
-
},
|
|
3484
|
-
];
|
|
3485
|
-
break;
|
|
3486
|
-
default:
|
|
3487
|
-
return res.sendError( 'Please give valid modueType', 400 );
|
|
3488
|
-
} const query =[
|
|
3351
|
+
const query =[
|
|
3489
3352
|
{
|
|
3490
3353
|
$match: {
|
|
3491
3354
|
$and: filters,
|
|
@@ -3495,12 +3358,24 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3495
3358
|
{
|
|
3496
3359
|
$lookup: {
|
|
3497
3360
|
from: 'traxAuditData',
|
|
3498
|
-
let:
|
|
3361
|
+
let: {
|
|
3362
|
+
fileDate: '$fileDate', storeId: '$storeId', zoneName: '$zoneName',
|
|
3363
|
+
},
|
|
3499
3364
|
pipeline: [
|
|
3500
3365
|
{
|
|
3501
3366
|
$match: {
|
|
3502
3367
|
$expr: {
|
|
3503
|
-
$and:
|
|
3368
|
+
$and: [
|
|
3369
|
+
{
|
|
3370
|
+
$eq: [ '$fileDate', '$$fileDate' ],
|
|
3371
|
+
},
|
|
3372
|
+
{
|
|
3373
|
+
$eq: [ '$storeId', '$$storeId' ],
|
|
3374
|
+
},
|
|
3375
|
+
{
|
|
3376
|
+
$eq: [ '$zoneName', '$$zoneName' ],
|
|
3377
|
+
},
|
|
3378
|
+
],
|
|
3504
3379
|
},
|
|
3505
3380
|
},
|
|
3506
3381
|
},
|
|
@@ -3611,7 +3486,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3611
3486
|
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3612
3487
|
{ userEmail: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3613
3488
|
{ value: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3614
|
-
{ question: { $regex: inputData.
|
|
3489
|
+
{ question: { $regex: inputData.searchData, $options: 'i' } },
|
|
3615
3490
|
],
|
|
3616
3491
|
|
|
3617
3492
|
},
|
|
@@ -3656,7 +3531,6 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3656
3531
|
'Status': toCamelCase( element.auditStatus ),
|
|
3657
3532
|
};
|
|
3658
3533
|
switch ( inputData.moduleType ) {
|
|
3659
|
-
case 'anomaly-audit':
|
|
3660
3534
|
case 'camera-angle-change':
|
|
3661
3535
|
temp['stream Name'] = element.streamName;
|
|
3662
3536
|
break;
|
|
@@ -4122,7 +3996,6 @@ export async function overviewTable( req, res ) {
|
|
|
4122
3996
|
},
|
|
4123
3997
|
];
|
|
4124
3998
|
break;
|
|
4125
|
-
case 'anomaly-audit':
|
|
4126
3999
|
case 'camera-angle-change':
|
|
4127
4000
|
traxAuditDataQuery= {
|
|
4128
4001
|
fileDate: '$fileDate', storeId: '$storeId', moduleType: '$moduleType', streamName: '$streamName',
|
|
@@ -4180,7 +4053,6 @@ export async function overviewTable( req, res ) {
|
|
|
4180
4053
|
},
|
|
4181
4054
|
];
|
|
4182
4055
|
break;
|
|
4183
|
-
|
|
4184
4056
|
default:
|
|
4185
4057
|
return res.sendError( 'Please give valid modueType', 400 );
|
|
4186
4058
|
}
|
|
@@ -4321,7 +4193,6 @@ export async function overviewTable( req, res ) {
|
|
|
4321
4193
|
};
|
|
4322
4194
|
|
|
4323
4195
|
switch ( inputData.moduleType ) {
|
|
4324
|
-
case 'anomaly-audit':
|
|
4325
4196
|
case 'camera-angle-change':
|
|
4326
4197
|
temp['stream Name'] = element.streamName;
|
|
4327
4198
|
temp['User Comments'] = element.userComments;
|
|
@@ -4391,6 +4262,43 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4391
4262
|
const fetchData = {};
|
|
4392
4263
|
let msg = {};
|
|
4393
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
|
+
|
|
4394
4302
|
const userQuery = [
|
|
4395
4303
|
{
|
|
4396
4304
|
$match: {
|
|
@@ -4400,7 +4308,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4400
4308
|
{ auditStatus: { $nin: [ 'completed', 'skipped' ] } },
|
|
4401
4309
|
{ createdAt: { $gte: start } },
|
|
4402
4310
|
{ createdAt: { $lte: end } },
|
|
4403
|
-
{ moduleType: inputData.moduleType },
|
|
4311
|
+
{ moduleType: { $in: inputData.moduleType=='open-time'?[ 'open-time', 'close-time' ]: [ inputData.moduleType ] } },
|
|
4404
4312
|
],
|
|
4405
4313
|
},
|
|
4406
4314
|
},
|
|
@@ -4413,24 +4321,12 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4413
4321
|
{
|
|
4414
4322
|
$lookup: {
|
|
4415
4323
|
from: 'traxAuditData',
|
|
4416
|
-
let: {
|
|
4417
|
-
fileDate: '$fileDate', storeId: '$storeId', zoneName: '$zoneName',
|
|
4418
|
-
},
|
|
4324
|
+
let: { ...filterQuery, moduleType: '$moduleType' },
|
|
4419
4325
|
pipeline: [
|
|
4420
4326
|
{
|
|
4421
4327
|
$match: {
|
|
4422
4328
|
$expr: {
|
|
4423
|
-
$and: [
|
|
4424
|
-
{
|
|
4425
|
-
$eq: [ '$fileDate', '$$fileDate' ],
|
|
4426
|
-
},
|
|
4427
|
-
{
|
|
4428
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
4429
|
-
},
|
|
4430
|
-
{
|
|
4431
|
-
$eq: [ '$zoneName', '$$zoneName' ],
|
|
4432
|
-
},
|
|
4433
|
-
],
|
|
4329
|
+
$and: [ ...filter, { $eq: [ '$moduleType', '$$moduleType' ] } ],
|
|
4434
4330
|
},
|
|
4435
4331
|
},
|
|
4436
4332
|
},
|
|
@@ -4445,8 +4341,8 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4445
4341
|
];
|
|
4446
4342
|
|
|
4447
4343
|
const userDetails = await aggregateUserEmpDetection( userQuery );
|
|
4448
|
-
logger.info( { userDetails: userDetails, function: 'userDetails' } );
|
|
4449
4344
|
const auditStatus = userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
4345
|
+
logger.info( { auditStatus: auditStatus, userDetails: userDetails } );
|
|
4450
4346
|
switch ( auditStatus ) {
|
|
4451
4347
|
case null:
|
|
4452
4348
|
logger.info( 'Hit in new file', { inputData } );
|
|
@@ -4564,6 +4460,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4564
4460
|
inputBucketName: userDetails[0].inputBucketName,
|
|
4565
4461
|
folderPath: userDetails[0].folderPath,
|
|
4566
4462
|
question: userDetails[0]?.sqs[0]?.message?.question,
|
|
4463
|
+
moduleType: userDetails[0]?.moduleType,
|
|
4567
4464
|
};
|
|
4568
4465
|
break;
|
|
4569
4466
|
}
|
|
@@ -4580,39 +4477,77 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4580
4477
|
if ( inputData.nextId ) {
|
|
4581
4478
|
fetchData.ContinuationToken = decodeURIComponent( inputData.nextId );
|
|
4582
4479
|
}
|
|
4480
|
+
const openParems ={
|
|
4481
|
+
Bucket: msg.inputBucketName,
|
|
4482
|
+
Key: msg.folderPath,
|
|
4483
|
+
};
|
|
4484
|
+
inputData.moduleType= inputData.moduleType == 'open-time'? msg.moduleType : inputData.moduleType;
|
|
4583
4485
|
const list = inputData.moduleType == 'hygiene'? await checkFileExist( {
|
|
4584
4486
|
Bucket: msg.inputBucketName,
|
|
4585
4487
|
Key: msg.folderPath,
|
|
4586
|
-
} ) :
|
|
4587
|
-
|
|
4488
|
+
} ) :[ 'open-time', 'close-time' ].includes( inputData.moduleType )? await getJsonFileData( openParems ) :
|
|
4489
|
+
await listFileByPath( fetchData );
|
|
4588
4490
|
const folderPath = inputData.moduleType == 'hygiene'? list? [ {
|
|
4589
4491
|
Key: msg.folderPath,
|
|
4590
|
-
} ] : [] : list.data;
|
|
4492
|
+
} ] : [] : [ 'open-time', 'close-time' ].includes( inputData.moduleType )? list?.statusCode== 500? []:JSON.parse( list.toString( 'utf-8' ) ).data : list.data;
|
|
4591
4493
|
const nextQuery = inputData.moduleType == 'hygiene'? null : list?.pageToken;
|
|
4592
4494
|
const bucketCDN = url.traxAuditInput;
|
|
4593
4495
|
if ( folderPath?.length > 0 ) {
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
4597
|
-
|
|
4598
|
-
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4604
|
-
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
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;
|
|
4615
4549
|
}
|
|
4550
|
+
|
|
4616
4551
|
if ( userDetails.length === 0 ) {
|
|
4617
4552
|
const [ day, month, year ] = msg.fileDate.split( '-' );
|
|
4618
4553
|
const temp = `${year}-${month}-${day}`;
|