tango-app-api-audit 3.4.41 → 3.4.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.43",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,16 +15,18 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"adm-zip": "^0.5.15",
|
|
17
17
|
"aws-sdk": "^2.1643.0",
|
|
18
|
+
"axios": "^1.7.9",
|
|
18
19
|
"dayjs": "^1.11.11",
|
|
19
20
|
"dotenv": "^16.4.5",
|
|
20
21
|
"express": "^4.19.2",
|
|
22
|
+
"form-data": "^4.0.1",
|
|
21
23
|
"handlebars": "^4.7.8",
|
|
22
24
|
"joi-to-swagger": "^6.2.0",
|
|
23
25
|
"lodash": "^4.17.21",
|
|
24
26
|
"mongodb": "^6.7.0",
|
|
25
27
|
"nodemon": "^3.1.3",
|
|
26
28
|
"swagger-ui-express": "^5.0.1",
|
|
27
|
-
"tango-api-schema": "^2.2.
|
|
29
|
+
"tango-api-schema": "^2.2.45",
|
|
28
30
|
"tango-app-api-middleware": "^3.1.48",
|
|
29
31
|
"winston": "^3.13.0",
|
|
30
32
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive, updateOpenSearchData } from 'tango-app-api-middleware';
|
|
1
|
+
import { checkFileExist, chunkArray, download, getDate, getDateWithCustomizeTime, getObject, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive, updateOpenSearchData } from 'tango-app-api-middleware';
|
|
2
2
|
import { aggregateBinaryAudit, createBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
|
|
3
3
|
import { countDocumentsStore, findOneStore } from '../service/store.service.js';
|
|
4
4
|
import { findOneUser } from '../service/user.service.js';
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
findOneUserEmpDetection,
|
|
18
18
|
} from '../service/userEmpDetection.service.js';
|
|
19
19
|
import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.service.js';
|
|
20
|
+
import axios from 'axios';
|
|
21
|
+
import FormData from 'form-data';
|
|
20
22
|
|
|
21
23
|
export async function workSpace( req, res ) {
|
|
22
24
|
try {
|
|
@@ -56,7 +58,11 @@ export async function workSpace( req, res ) {
|
|
|
56
58
|
{ $eq: [ inputData.moduleType, 'mobile-detection' ] }, '$auditConfigs.traxQueueName.mobileDetection',
|
|
57
59
|
{
|
|
58
60
|
$cond: [
|
|
59
|
-
{ $eq: [ inputData.moduleType, 'hygiene' ] }, '$auditConfigs.traxQueueName.hygiene',
|
|
61
|
+
{ $eq: [ inputData.moduleType, 'hygiene' ] }, '$auditConfigs.traxQueueName.hygiene', {
|
|
62
|
+
$cond: [
|
|
63
|
+
{ $eq: [ inputData.moduleType, 'camera-angle-change' ] }, '$auditConfigs.traxQueueName.cameraAngleChange', '$auditConfigs.traxQueueName.eyeTestCamera' ],
|
|
64
|
+
},
|
|
65
|
+
|
|
60
66
|
],
|
|
61
67
|
},
|
|
62
68
|
],
|
|
@@ -542,8 +548,17 @@ export async function getAuditFile( req, res ) {
|
|
|
542
548
|
moduleType: userDetails[0].moduleType,
|
|
543
549
|
};
|
|
544
550
|
break;
|
|
551
|
+
case 'eye-test-camera':
|
|
552
|
+
query ={
|
|
553
|
+
storeId: userDetails[0].storeId,
|
|
554
|
+
fileDate: userDetails[0].fileDate,
|
|
555
|
+
// question: userDetails[0].question,
|
|
556
|
+
streamName: userDetails[0].streamName,
|
|
557
|
+
moduleType: userDetails[0].moduleType,
|
|
558
|
+
};
|
|
559
|
+
break;
|
|
545
560
|
default:
|
|
546
|
-
return res.sendError( 'Please give valid
|
|
561
|
+
return res.sendError( 'Please give valid moduleType', 400 );
|
|
547
562
|
}
|
|
548
563
|
logger.info( { query: query } );
|
|
549
564
|
const traxInfo = await findOneTraxAuditData( query );
|
|
@@ -660,6 +675,32 @@ export async function getAuditFile( req, res ) {
|
|
|
660
675
|
} );
|
|
661
676
|
}
|
|
662
677
|
break;
|
|
678
|
+
case 'eye-test-camera':
|
|
679
|
+
const eyeTestfiles = [];
|
|
680
|
+
|
|
681
|
+
const eyeTestparams ={
|
|
682
|
+
Bucket: msg.inputBucketName,
|
|
683
|
+
Key: msg?.filePath,
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
const isCameraExists = await checkFileExist( eyeTestparams );
|
|
687
|
+
|
|
688
|
+
if ( isCameraExists ) {
|
|
689
|
+
const url = JSON.parse( process.env.URL );
|
|
690
|
+
logger.info( { url: url, cameraBaseImage: url.cameraBaseImage } );
|
|
691
|
+
const data = `${url.cameraBaseImage}${msg?.filePath}`;
|
|
692
|
+
|
|
693
|
+
eyeTestfiles.push(
|
|
694
|
+
data,
|
|
695
|
+
);
|
|
696
|
+
} else {
|
|
697
|
+
return res.sendSuccess( 'No Data found', 204 );
|
|
698
|
+
}
|
|
699
|
+
result.push( {
|
|
700
|
+
type: 'image',
|
|
701
|
+
file: eyeTestfiles,
|
|
702
|
+
} );
|
|
703
|
+
break;
|
|
663
704
|
default:
|
|
664
705
|
return res.sendError( 'Please given valid moduleType', 400 );
|
|
665
706
|
}
|
|
@@ -703,7 +744,7 @@ export async function getAuditFile( req, res ) {
|
|
|
703
744
|
questionType: msg.questionType,
|
|
704
745
|
streamName: msg.streamName,
|
|
705
746
|
};
|
|
706
|
-
record.streamName = inputData.moduleType == 'camera-angle-change'? msg.streamName : '';
|
|
747
|
+
record.streamName = inputData.moduleType == 'camera-angle-change' || inputData.moduleType == 'eye-test-camera'? msg.streamName : '';
|
|
707
748
|
record.videoDetails = inputData.moduleType == 'left-in-middle'? {
|
|
708
749
|
'startHour': msg.startHour,
|
|
709
750
|
'inspectHour': msg.inspectHour,
|
|
@@ -862,6 +903,31 @@ export async function getUpdatedFile( req, res ) {
|
|
|
862
903
|
} );
|
|
863
904
|
}
|
|
864
905
|
break;
|
|
906
|
+
case 'eye-test-camera':
|
|
907
|
+
const eyeTestfiles = [];
|
|
908
|
+
|
|
909
|
+
const eyeTestparams ={
|
|
910
|
+
Bucket: msg.inputBucketName,
|
|
911
|
+
Key: msg?.filePath,
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
const isCameraExists = await checkFileExist( eyeTestparams );
|
|
915
|
+
|
|
916
|
+
if ( isCameraExists ) {
|
|
917
|
+
const url = JSON.parse( process.env.URL );
|
|
918
|
+
const data = `${url.cameraBaseImage}${msg?.filePath}`;
|
|
919
|
+
|
|
920
|
+
eyeTestfiles.push(
|
|
921
|
+
data,
|
|
922
|
+
);
|
|
923
|
+
} else {
|
|
924
|
+
return res.sendSuccess( 'No Data found', 204 );
|
|
925
|
+
}
|
|
926
|
+
result.push( {
|
|
927
|
+
type: 'image',
|
|
928
|
+
file: eyeTestfiles,
|
|
929
|
+
} );
|
|
930
|
+
break;
|
|
865
931
|
default:
|
|
866
932
|
return res.sendError( 'Please given valid moduleType', 400 );
|
|
867
933
|
}
|
|
@@ -924,6 +990,7 @@ export async function getUpdatedFile( req, res ) {
|
|
|
924
990
|
export async function saveBinary( req, res ) {
|
|
925
991
|
try {
|
|
926
992
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
993
|
+
const url = JSON.parse( process.env.URL );
|
|
927
994
|
const sqs = JSON.parse( process.env.SQS );
|
|
928
995
|
const inputData = req.body;
|
|
929
996
|
const isoDate = req.userAudit?.startTime;
|
|
@@ -1164,13 +1231,94 @@ export async function saveBinary( req, res ) {
|
|
|
1164
1231
|
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1165
1232
|
|
|
1166
1233
|
break;
|
|
1234
|
+
case 'eye-test-camera':
|
|
1235
|
+
if ( inputData.answer == 'approved' ) {
|
|
1236
|
+
const stores = await findOneStore( { storeId: req.userAudit?.storeId }, { storeName: 1 } );
|
|
1237
|
+
const query={
|
|
1238
|
+
streamName: req.userAudit?.streamName,
|
|
1239
|
+
fileDate: req.userAudit?.fileDate,
|
|
1240
|
+
storeId: req.userAudit?.storeId,
|
|
1241
|
+
moduleType: req.userAudit?.moduleType,
|
|
1242
|
+
};
|
|
1243
|
+
const getSqs = await findOneTraxAuditData( query, { sqs: '$sqs.Body' } );
|
|
1244
|
+
|
|
1245
|
+
const fileDateISO = req.userAudit?.fileDateISO;
|
|
1246
|
+
fileDateISO.setDate( fileDateISO.getDate() + 180 );
|
|
1247
|
+
|
|
1248
|
+
// Format the date to yyyy-MM-dd
|
|
1249
|
+
const formattedDate = fileDateISO.toISOString().split( 'T' )[0];
|
|
1250
|
+
const param ={
|
|
1251
|
+
Bucket: getSqs?.sqs?.inputBucketName,
|
|
1252
|
+
Key: getSqs?.sqs?.filePath,
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1255
|
+
const img = await getObject( param );
|
|
1256
|
+
|
|
1257
|
+
const formData = new FormData();
|
|
1258
|
+
formData.append( 'storeName', stores?.storeName );
|
|
1259
|
+
formData.append( 'taskName', 'EyeTest QR Verification' );
|
|
1260
|
+
formData.append( 'answerType', 'image' );
|
|
1261
|
+
formData.append( 'question', 'Please Upload QR image of the clinic' );
|
|
1262
|
+
formData.append( 'scheduleDate', formattedDate );
|
|
1263
|
+
formData.append( 'scheduleEndTime', '11:00 PM' );
|
|
1264
|
+
|
|
1265
|
+
formData.append( 'referenceImage', img.Body );
|
|
1266
|
+
const response = await axios.post( `${url.apiDomain}/v3/task/eyeTesttask`, formData, { headers: {
|
|
1267
|
+
...formData.getHeaders(),
|
|
1268
|
+
'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f55' },
|
|
1269
|
+
} );
|
|
1270
|
+
if ( response?.data?.code == 200 ) {
|
|
1271
|
+
let eyeTestQuery ={
|
|
1272
|
+
_id: inputData.auditId,
|
|
1273
|
+
storeId: inputData.storeId,
|
|
1274
|
+
fileDate: inputData.fileDate,
|
|
1275
|
+
streamName: inputData.streamName,
|
|
1276
|
+
moduleType: inputData.moduleType,
|
|
1277
|
+
};
|
|
1278
|
+
let eyeTestUpdate={
|
|
1279
|
+
auditStatus: 'completed',
|
|
1280
|
+
answer: inputData.answer,
|
|
1281
|
+
userComments: inputData.userComments || '',
|
|
1282
|
+
endTime: new Date(),
|
|
1283
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1284
|
+
};
|
|
1285
|
+
let updatDataEyeTest= await updateOneBinaryAuditModel( eyeTestQuery, eyeTestUpdate );
|
|
1286
|
+
if ( updatDataEyeTest.modifiedCount==0 ) {
|
|
1287
|
+
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1288
|
+
}
|
|
1289
|
+
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1290
|
+
} else {
|
|
1291
|
+
return res.sendError( 'Task creation failed', 500 );
|
|
1292
|
+
}
|
|
1293
|
+
} else {
|
|
1294
|
+
let eyeTestQuery ={
|
|
1295
|
+
_id: inputData.auditId,
|
|
1296
|
+
storeId: inputData.storeId,
|
|
1297
|
+
fileDate: inputData.fileDate,
|
|
1298
|
+
streamName: inputData.streamName,
|
|
1299
|
+
moduleType: inputData.moduleType,
|
|
1300
|
+
};
|
|
1301
|
+
let eyeTestUpdate={
|
|
1302
|
+
auditStatus: 'completed',
|
|
1303
|
+
answer: inputData.answer,
|
|
1304
|
+
userComments: inputData.userComments || '',
|
|
1305
|
+
endTime: new Date(),
|
|
1306
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1307
|
+
};
|
|
1308
|
+
let updatDataEyeTest= await updateOneBinaryAuditModel( eyeTestQuery, eyeTestUpdate );
|
|
1309
|
+
if ( updatDataEyeTest.modifiedCount==0 ) {
|
|
1310
|
+
return res.sendError( 'Update failed, it may be invalid request', 400 );
|
|
1311
|
+
}
|
|
1312
|
+
return res.sendSuccess( `Successfully updated in ${value}` );
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1167
1315
|
|
|
1168
1316
|
default:
|
|
1169
|
-
res.sendError( '
|
|
1317
|
+
res.sendError( 'No Data', 204 );
|
|
1170
1318
|
break;
|
|
1171
1319
|
}
|
|
1172
1320
|
} catch ( error ) {
|
|
1173
|
-
const err = error.mesage || 'Internal Server Error';
|
|
1321
|
+
const err = error.mesage || error.response?.data || error.response?.status ||'Internal Server Error';
|
|
1174
1322
|
logger.error( { error: error, data: req.body, function: 'saveBinary' } );
|
|
1175
1323
|
return res.sendError( err, 500 );
|
|
1176
1324
|
}
|
|
@@ -102,6 +102,15 @@ export async function isTraxAuditDocumentExist( req, res, next ) {
|
|
|
102
102
|
moduleType: inputData.moduleType,
|
|
103
103
|
};
|
|
104
104
|
break;
|
|
105
|
+
case 'eye-test-camera':
|
|
106
|
+
query ={
|
|
107
|
+
storeId: inputData.storeId,
|
|
108
|
+
fileDate: inputData.fileDate,
|
|
109
|
+
// question: inputData.question,
|
|
110
|
+
streamName: inputData.streamName,
|
|
111
|
+
moduleType: inputData.moduleType,
|
|
112
|
+
};
|
|
113
|
+
break;
|
|
105
114
|
default:
|
|
106
115
|
return res.sendError( 'Please give valid modueType', 400 );
|
|
107
116
|
}
|