tango-app-api-audit 3.4.0-alpha.15 → 3.4.0-alpha.16
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
|
@@ -950,18 +950,55 @@ export async function getAuditFile( req, res ) {
|
|
|
950
950
|
break;
|
|
951
951
|
|
|
952
952
|
case 'inprogress':
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
953
|
+
let query = {};
|
|
954
|
+
switch ( inputData.moduleType ) {
|
|
955
|
+
case 'unattended-customer':
|
|
956
|
+
query ={
|
|
957
|
+
storeId: userDetails[0].storeId,
|
|
958
|
+
fileDate: userDetails[0].fileDate,
|
|
959
|
+
tempId: userDetails[0].tempId,
|
|
960
|
+
moduleType: userDetails[0].moduleType,
|
|
961
|
+
};
|
|
962
|
+
break;
|
|
963
|
+
case 'left-in-middle':
|
|
964
|
+
query ={
|
|
965
|
+
storeId: userDetails[0].storeId,
|
|
966
|
+
fileDate: userDetails[0].fileDate,
|
|
967
|
+
question: userDetails[0].question,
|
|
968
|
+
moduleType: userDetails[0].moduleType,
|
|
969
|
+
};
|
|
970
|
+
break;
|
|
971
|
+
case 'uniform-detection':
|
|
972
|
+
query ={
|
|
973
|
+
storeId: userDetails[0].storeId,
|
|
974
|
+
fileDate: userDetails[0].fileDate,
|
|
975
|
+
moduleType: userDetails[0].moduleType,
|
|
976
|
+
};
|
|
977
|
+
break;
|
|
978
|
+
case 'mobile-detection':
|
|
979
|
+
query ={
|
|
980
|
+
storeId: userDetails[0].storeId,
|
|
981
|
+
fileDate: userDetails[0].fileDate,
|
|
982
|
+
moduleType: userDetails[0].moduleType,
|
|
983
|
+
};
|
|
984
|
+
break;
|
|
985
|
+
case 'camera-angle-change':
|
|
986
|
+
query ={
|
|
987
|
+
storeId: userDetails[0].storeId,
|
|
988
|
+
fileDate: userDetails[0].fileDate,
|
|
989
|
+
streamName: userDetails[0].streamName,
|
|
990
|
+
moduleType: userDetails[0].moduleType,
|
|
991
|
+
};
|
|
992
|
+
break;
|
|
993
|
+
default:
|
|
994
|
+
return res.sendError( 'Please give valid modueType', 400 );
|
|
995
|
+
}
|
|
996
|
+
logger.info( { query: query } );
|
|
997
|
+
const traxInfo = await findOneTraxAuditData( query );
|
|
998
|
+
if ( !traxInfo ) {
|
|
999
|
+
return res.sendError( 'The sorce record not found', 400 );
|
|
1000
|
+
}
|
|
1001
|
+
msg =traxInfo?.sqs?.Body;
|
|
965
1002
|
break;
|
|
966
1003
|
|
|
967
1004
|
default:
|
|
@@ -1186,6 +1223,175 @@ export async function getAuditFile( req, res ) {
|
|
|
1186
1223
|
}
|
|
1187
1224
|
}
|
|
1188
1225
|
|
|
1226
|
+
export async function getUpdatedFile( req, res ) {
|
|
1227
|
+
try {
|
|
1228
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
1229
|
+
const inputData = req.query;
|
|
1230
|
+
const msg = req?.TraxData?.sqs?.Body;
|
|
1231
|
+
logger.info( { msg: msg } );
|
|
1232
|
+
let result =[];
|
|
1233
|
+
switch ( inputData.moduleType ) {
|
|
1234
|
+
case 'camera-angle-change':
|
|
1235
|
+
const actualParams ={
|
|
1236
|
+
Bucket: msg.inputBucketName,
|
|
1237
|
+
Key: msg.actual,
|
|
1238
|
+
};
|
|
1239
|
+
const changedParams ={
|
|
1240
|
+
Bucket: msg.inputBucketName,
|
|
1241
|
+
Key: msg.changed,
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1244
|
+
const [ isActualExists, isChangedExists ] = await Promise.all( [ checkFileExist( actualParams ), checkFileExist( changedParams ) ] );
|
|
1245
|
+
result =[
|
|
1246
|
+
{
|
|
1247
|
+
actualCameraImage: isActualExists? await signedUrl( { Bucket: msg.inputBucketName,
|
|
1248
|
+
file_path: msg.actual } ) :'',
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
changedCameraImage: isChangedExists? await signedUrl( { Bucket: msg.inputBucketName,
|
|
1252
|
+
file_path: msg.changed } ) : '',
|
|
1253
|
+
},
|
|
1254
|
+
];
|
|
1255
|
+
break;
|
|
1256
|
+
case 'unattended-customer':
|
|
1257
|
+
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
1258
|
+
const files = [];
|
|
1259
|
+
const params ={
|
|
1260
|
+
Bucket: msg.inputBucketName,
|
|
1261
|
+
file_path: msg?.fileDetails[i]?.folderPath,
|
|
1262
|
+
MaxKeys: 1000,
|
|
1263
|
+
};
|
|
1264
|
+
const list = await listFileByPath( params );
|
|
1265
|
+
const folderPath = list.data;
|
|
1266
|
+
logger.info( { folderPath: list, params: params, list: list } );
|
|
1267
|
+
if ( folderPath?.length ) {
|
|
1268
|
+
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
1269
|
+
// const img = folderPath[i].Key.split( '/' );
|
|
1270
|
+
// const image = img[3].split( '.' );
|
|
1271
|
+
// const indexes = image[0].split( '_' );
|
|
1272
|
+
const signedParams ={
|
|
1273
|
+
Bucket: msg.inputBucketName,
|
|
1274
|
+
file_path: folderPath[i].Key,
|
|
1275
|
+
};
|
|
1276
|
+
const data = await signedUrl( signedParams );
|
|
1277
|
+
|
|
1278
|
+
files.push(
|
|
1279
|
+
data,
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
} else {
|
|
1283
|
+
logger.error( {
|
|
1284
|
+
error: { folderPath: folderPath },
|
|
1285
|
+
function: `getAuditFile - ${inputData.moduleType}`,
|
|
1286
|
+
message: 'Bucket image data not availale',
|
|
1287
|
+
} );
|
|
1288
|
+
return res.sendError( 'Bucket is Empty', 204 );
|
|
1289
|
+
}
|
|
1290
|
+
result.push( {
|
|
1291
|
+
type: msg.fileDetails[i].type,
|
|
1292
|
+
file: files,
|
|
1293
|
+
} );
|
|
1294
|
+
}
|
|
1295
|
+
break;
|
|
1296
|
+
case 'left-in-middle':
|
|
1297
|
+
for ( let i =0; i< msg.fileDetails.length; i++ ) {
|
|
1298
|
+
const files = [];
|
|
1299
|
+
const params ={
|
|
1300
|
+
Bucket: msg.inputBucketName,
|
|
1301
|
+
file_path: msg?.fileDetails[i]?.folderPath,
|
|
1302
|
+
MaxKeys: 1000,
|
|
1303
|
+
};
|
|
1304
|
+
const list = await listFileByPath( params );
|
|
1305
|
+
const folderPath = list.data;
|
|
1306
|
+
logger.info( { folderPath: list, params: params, list: list } );
|
|
1307
|
+
if ( folderPath?.length ) {
|
|
1308
|
+
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
1309
|
+
// const img = folderPath[i].Key.split( '/' );
|
|
1310
|
+
// const image = img[3].split( '.' );
|
|
1311
|
+
// const indexes = image[0].split( '_' );
|
|
1312
|
+
const signedParams ={
|
|
1313
|
+
Bucket: msg.inputBucketName,
|
|
1314
|
+
file_path: folderPath[i].Key,
|
|
1315
|
+
};
|
|
1316
|
+
const data = await signedUrl( signedParams );
|
|
1317
|
+
|
|
1318
|
+
files.push(
|
|
1319
|
+
data,
|
|
1320
|
+
);
|
|
1321
|
+
}
|
|
1322
|
+
} else {
|
|
1323
|
+
logger.error( {
|
|
1324
|
+
error: { folderPath: folderPath },
|
|
1325
|
+
function: `getAuditFile - ${inputData.moduleType}`,
|
|
1326
|
+
message: 'Bucket image data not availale',
|
|
1327
|
+
} );
|
|
1328
|
+
return res.sendError( 'Bucket is Empty', 204 );
|
|
1329
|
+
}
|
|
1330
|
+
result.push( {
|
|
1331
|
+
type: msg.fileDetails[i].type,
|
|
1332
|
+
file: files,
|
|
1333
|
+
} );
|
|
1334
|
+
}
|
|
1335
|
+
break;
|
|
1336
|
+
default:
|
|
1337
|
+
return res.sendError( 'Please given valid moduleType', 400 );
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
const userdata = await findOneUser( { _id: req.user._id } );
|
|
1341
|
+
const storeQuery = {
|
|
1342
|
+
storeId: inputData.storeId,
|
|
1343
|
+
};
|
|
1344
|
+
const storeFields = {
|
|
1345
|
+
'storeName': 1,
|
|
1346
|
+
'storeProfile.address': 1,
|
|
1347
|
+
'clientId': 1,
|
|
1348
|
+
};
|
|
1349
|
+
const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
1350
|
+
|
|
1351
|
+
const logData = {
|
|
1352
|
+
userId: req.user._id,
|
|
1353
|
+
userName: userdata.name,
|
|
1354
|
+
logType: 'audit',
|
|
1355
|
+
logSubType: 'auditStart',
|
|
1356
|
+
data: {
|
|
1357
|
+
fileDate: msg.fileDate,
|
|
1358
|
+
storeId: msg.storeId,
|
|
1359
|
+
clientId: storeInfo?.clientId,
|
|
1360
|
+
tempId: msg.tempId,
|
|
1361
|
+
value: msg.value,
|
|
1362
|
+
fileDetails: msg.fileDetails,
|
|
1363
|
+
moduleType: inputData.moduleType,
|
|
1364
|
+
question: msg.question,
|
|
1365
|
+
questionType: msg.questionType,
|
|
1366
|
+
streamName: msg.streamName,
|
|
1367
|
+
actaulImage: msg.actual,
|
|
1368
|
+
changedImage: msg.changed,
|
|
1369
|
+
},
|
|
1370
|
+
createdAt: new Date(),
|
|
1371
|
+
};
|
|
1372
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
1373
|
+
|
|
1374
|
+
return res.sendSuccess( {
|
|
1375
|
+
result: result,
|
|
1376
|
+
storeId: msg.storeId,
|
|
1377
|
+
storeName: storeInfo?.storeName,
|
|
1378
|
+
address: storeInfo?.address,
|
|
1379
|
+
customerId: msg.tempId,
|
|
1380
|
+
moduleType: inputData.moduleType,
|
|
1381
|
+
value: inputData.moduleType == 'left-in-middle'? 'Employee Left in Middle ' : ( inputData.moduleType ).split( '-' ).join( ' ' ),
|
|
1382
|
+
fileDate: msg.fileDate,
|
|
1383
|
+
question: msg.question,
|
|
1384
|
+
questionType: msg.questionType,
|
|
1385
|
+
streamName: msg.streamName,
|
|
1386
|
+
auditId: inputData.auditId,
|
|
1387
|
+
} );
|
|
1388
|
+
} catch ( error ) {
|
|
1389
|
+
const err = error.message || 'Internal Server Error';
|
|
1390
|
+
logger.error( { error: error, data: req.query, function: 'getUpdatedFile' } );
|
|
1391
|
+
return res.sendError( err, 500 );
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1189
1395
|
export async function saveBinary( req, res ) {
|
|
1190
1396
|
try {
|
|
1191
1397
|
const inputData = req.body;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema } from '../dtos/traxAudit.dtos.js';
|
|
2
|
+
import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, getUpdatedFileSchema } from '../dtos/traxAudit.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const traxAuditDocs = {
|
|
5
5
|
|
|
@@ -43,6 +43,64 @@ export const traxAuditDocs = {
|
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
|
+
'/v3/trax-audit/get-updated-file': {
|
|
47
|
+
get: {
|
|
48
|
+
tags: [ 'Trax Audit' ],
|
|
49
|
+
description: 'Get a file via queue message',
|
|
50
|
+
operationId: 'get-updated-file',
|
|
51
|
+
parameters: [
|
|
52
|
+
{
|
|
53
|
+
in: 'query',
|
|
54
|
+
name: 'storeId',
|
|
55
|
+
scema: j2s( getUpdatedFileSchema ).swagger,
|
|
56
|
+
require: true,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
in: 'query',
|
|
60
|
+
name: 'fileDate',
|
|
61
|
+
scema: j2s( getUpdatedFileSchema ).swagger,
|
|
62
|
+
require: true,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
in: 'query',
|
|
66
|
+
name: 'moduleType',
|
|
67
|
+
scema: j2s( getUpdatedFileSchema ).swagger,
|
|
68
|
+
require: true,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
in: 'query',
|
|
72
|
+
name: 'auditId',
|
|
73
|
+
scema: j2s( getUpdatedFileSchema ).swagger,
|
|
74
|
+
require: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
in: 'query',
|
|
78
|
+
name: 'streamName',
|
|
79
|
+
scema: j2s( getUpdatedFileSchema ).swagger,
|
|
80
|
+
require: false,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
in: 'query',
|
|
84
|
+
name: 'question',
|
|
85
|
+
scema: j2s( getUpdatedFileSchema ).swagger,
|
|
86
|
+
require: false,
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
in: 'query',
|
|
90
|
+
name: 'tempId',
|
|
91
|
+
scema: j2s( getUpdatedFileSchema ).swagger,
|
|
92
|
+
require: false,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
responses: {
|
|
96
|
+
200: { description: 'Successful' },
|
|
97
|
+
401: { description: 'Unauthorized User' },
|
|
98
|
+
422: { description: 'Field Error' },
|
|
99
|
+
500: { description: 'Server Error' },
|
|
100
|
+
204: { description: 'Not Found' },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
46
104
|
|
|
47
105
|
'/v3/trax-audit/work-space': {
|
|
48
106
|
post: {
|
|
@@ -12,6 +12,22 @@ export const getFileValid = {
|
|
|
12
12
|
query: getFileSchema,
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
export const getUpdatedFileSchema = joi.object(
|
|
16
|
+
{
|
|
17
|
+
fileDate: joi.string().required(),
|
|
18
|
+
storeId: joi.string().required(),
|
|
19
|
+
moduleType: joi.string().required(),
|
|
20
|
+
question: joi.string().optional(),
|
|
21
|
+
tempId: joi.number().optional(),
|
|
22
|
+
streamName: joi.string().optional(),
|
|
23
|
+
auditId: joi.string().required(),
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const getUpdatedFileValid = {
|
|
28
|
+
query: getUpdatedFileSchema,
|
|
29
|
+
};
|
|
30
|
+
|
|
15
31
|
export const getDetectionFileSchema = joi.object( {
|
|
16
32
|
queueName: joi.string().required(),
|
|
17
33
|
nextId: joi.string().optional().allow( '' ),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
2
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
-
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid } from '../dtos/traxAudit.dtos.js';
|
|
3
|
+
import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid } from '../dtos/traxAudit.dtos.js';
|
|
4
4
|
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
5
|
-
import { clientMetrics, getAuditFile, getDetectionAuditFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
|
|
6
|
-
import { validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
5
|
+
import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
|
|
6
|
+
import { isTraxAuditDocumentExist, validateBinaryAudit } from '../validation/traxAuditValidation.js';
|
|
7
7
|
|
|
8
8
|
export const traxAuditRouter = Router();
|
|
9
9
|
|
|
@@ -18,6 +18,7 @@ traxAuditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpac
|
|
|
18
18
|
|
|
19
19
|
// Y/n
|
|
20
20
|
traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
|
|
21
|
+
traxAuditRouter.get( '/get-updated-file', isAllowedSessionHandler, validate( getUpdatedFileValid ), isTraxAuditDocumentExist, getUpdatedFile );
|
|
21
22
|
traxAuditRouter.post( '/save-binary-audit', isAllowedSessionHandler, validate( saveValid ), validateBinaryAudit, saveBinary );
|
|
22
23
|
|
|
23
24
|
// metrcis
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { logger } from 'tango-app-api-middleware';
|
|
2
2
|
import { findOneBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
|
|
3
3
|
import { findOneUserEmpDetection } from '../service/userEmpDetection.service.js';
|
|
4
|
+
import { findOneTraxAuditData } from '../service/traxAuditData.service.js';
|
|
4
5
|
|
|
5
6
|
export async function validateUserEmpDetection( req, res, next ) {
|
|
6
7
|
try {
|
|
@@ -55,3 +56,63 @@ export async function validateBinaryAudit( req, res, next ) {
|
|
|
55
56
|
return res.sendError( err, 500 );
|
|
56
57
|
}
|
|
57
58
|
}
|
|
59
|
+
|
|
60
|
+
export async function isTraxAuditDocumentExist( req, res, next ) {
|
|
61
|
+
try {
|
|
62
|
+
const inputData = req.query;
|
|
63
|
+
let query = {};
|
|
64
|
+
switch ( inputData.moduleType ) {
|
|
65
|
+
case 'unattended-customer':
|
|
66
|
+
query ={
|
|
67
|
+
storeId: inputData.storeId,
|
|
68
|
+
fileDate: inputData.fileDate,
|
|
69
|
+
tempId: inputData.tempId,
|
|
70
|
+
moduleType: inputData.moduleType,
|
|
71
|
+
};
|
|
72
|
+
break;
|
|
73
|
+
case 'left-in-middle':
|
|
74
|
+
query ={
|
|
75
|
+
storeId: inputData.storeId,
|
|
76
|
+
fileDate: inputData.fileDate,
|
|
77
|
+
question: inputData.question,
|
|
78
|
+
moduleType: inputData.moduleType,
|
|
79
|
+
};
|
|
80
|
+
break;
|
|
81
|
+
case 'uniform-detection':
|
|
82
|
+
query ={
|
|
83
|
+
storeId: inputData.storeId,
|
|
84
|
+
fileDate: inputData.fileDate,
|
|
85
|
+
moduleType: inputData.moduleType,
|
|
86
|
+
};
|
|
87
|
+
break;
|
|
88
|
+
case 'mobile-detection':
|
|
89
|
+
query ={
|
|
90
|
+
storeId: inputData.storeId,
|
|
91
|
+
fileDate: inputData.fileDate,
|
|
92
|
+
moduleType: inputData.moduleType,
|
|
93
|
+
};
|
|
94
|
+
break;
|
|
95
|
+
case 'camera-angle-change':
|
|
96
|
+
query ={
|
|
97
|
+
storeId: inputData.storeId,
|
|
98
|
+
fileDate: inputData.fileDate,
|
|
99
|
+
streamName: inputData.streamName,
|
|
100
|
+
moduleType: inputData.moduleType,
|
|
101
|
+
};
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
return res.sendError( 'Please give valid modueType', 400 );
|
|
105
|
+
}
|
|
106
|
+
const auditInfo = await findOneTraxAuditData( query );
|
|
107
|
+
if ( auditInfo ) {
|
|
108
|
+
req.TraxData = auditInfo;
|
|
109
|
+
return next();
|
|
110
|
+
} else {
|
|
111
|
+
return res.sendError( 'No Inserted Record', 400 );
|
|
112
|
+
}
|
|
113
|
+
} catch ( error ) {
|
|
114
|
+
const err = error.message || 'Internal Server Error';
|
|
115
|
+
logger.error( { error: error, message: req.body, function: 'isTraxAuditDocumentExist' } );
|
|
116
|
+
return res.sendError( err, 500 );
|
|
117
|
+
}
|
|
118
|
+
}
|