tango-app-api-audit 3.5.14 → 3.5.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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.16",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "nodemon --exec \"eslint --fix . && node
|
|
8
|
+
"start": "nodemon --exec \"eslint --fix . && node app.js\""
|
|
9
9
|
},
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=18.10.0"
|
|
@@ -276,26 +276,26 @@ export async function getAuditFile( req, res ) {
|
|
|
276
276
|
logger.info( 'Hit in user assign', { inputData } );
|
|
277
277
|
userAssign[0].auditType == 'Audit' ?
|
|
278
278
|
( msg = {
|
|
279
|
-
store_id: userAssign[0]
|
|
280
|
-
curr_date: userAssign[0]
|
|
281
|
-
total_count: userAssign[0]
|
|
282
|
-
zone_id: userAssign[0]
|
|
283
|
-
index_name: auditInsertData[0]?.sqs?.index_name,
|
|
279
|
+
store_id: userAssign?.[0]?.storeId,
|
|
280
|
+
curr_date: userAssign?.[0]?.fileDate,
|
|
281
|
+
total_count: userAssign?.[0]?.fileCount,
|
|
282
|
+
zone_id: userAssign?.[0]?.zoneName,
|
|
283
|
+
index_name: auditInsertData?.[0]?.sqs?.index_name,
|
|
284
284
|
} ) :
|
|
285
285
|
( msg = {
|
|
286
|
-
store_id: userAssign[0]
|
|
287
|
-
curr_date: userAssign[0]
|
|
288
|
-
audit_type: userAssign[0]
|
|
289
|
-
total_count: userAssign[0]
|
|
290
|
-
zone_id: userAssign[0]
|
|
291
|
-
index_name: auditInsertData[0]?.sqs?.index_name,
|
|
286
|
+
store_id: userAssign?.[0]?.storeId,
|
|
287
|
+
curr_date: userAssign?.[0]?.fileDate,
|
|
288
|
+
audit_type: userAssign?.[0]?.auditType,
|
|
289
|
+
total_count: userAssign?.[0]?.fileCount,
|
|
290
|
+
zone_id: userAssign?.[0]?.zoneName,
|
|
291
|
+
index_name: auditInsertData?.[0]?.sqs?.index_name,
|
|
292
292
|
} );
|
|
293
293
|
await updateOneAssignAudit(
|
|
294
|
-
{ _id: userAssign[0]
|
|
294
|
+
{ _id: userAssign?.[0]?._id },
|
|
295
295
|
{ isCompleted: true },
|
|
296
296
|
);
|
|
297
297
|
logger.info( 'Hit in auditUserAssignModel updateOne', {
|
|
298
|
-
_id: userAssign[0]
|
|
298
|
+
_id: userAssign?.[0]?._id,
|
|
299
299
|
isCompleted: true,
|
|
300
300
|
} );
|
|
301
301
|
} else {
|
|
@@ -767,7 +767,6 @@ export async function getAuditFile( req, res ) {
|
|
|
767
767
|
}
|
|
768
768
|
function addUniqueFile( files, newFile ) {
|
|
769
769
|
const exists = files.some( ( file ) => file.img_name === newFile.img_name );
|
|
770
|
-
logger.info( { files: files, exists: exists, newFile: newFile, message: '.........1' } );
|
|
771
770
|
if ( !exists ) {
|
|
772
771
|
files.push( newFile );
|
|
773
772
|
}
|
|
@@ -4177,58 +4176,213 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
4177
4176
|
export async function auditImages( req, res ) {
|
|
4178
4177
|
try {
|
|
4179
4178
|
const inputData = req.query;
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
const
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
}
|
|
4189
|
-
if ( auditImageBC?.length == 0 ) {
|
|
4190
|
-
return res.sendError( 'No Data Found', 204 );
|
|
4191
|
-
}
|
|
4179
|
+
const url = JSON.parse( process.env.URL );
|
|
4180
|
+
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
4181
|
+
if ( inputData?.moduleType == 'track' ) {
|
|
4182
|
+
switch ( inputData.imageType ) {
|
|
4183
|
+
case 'BC':
|
|
4184
|
+
const getQuery = {
|
|
4185
|
+
size: 10000,
|
|
4186
|
+
_source: [ 'module', 'status', 'date', 'store_id', 'personPath', 'REIDCluster', 'EmployeeStatusProposed', 'isJunk', 'EmployeeStatusFinal' ], // Only fetch necessary fields
|
|
4192
4187
|
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4188
|
+
query: {
|
|
4189
|
+
bool: {
|
|
4190
|
+
'must': [
|
|
4191
|
+
{
|
|
4192
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
4193
|
+
},
|
|
4194
|
+
{
|
|
4195
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
4196
|
+
},
|
|
4197
|
+
{
|
|
4198
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
4199
|
+
},
|
|
4200
|
+
{
|
|
4201
|
+
term: { 'status.keyword': 'PP_CLUSTER_FORMED' },
|
|
4202
|
+
},
|
|
4203
|
+
{
|
|
4204
|
+
terms: { EmployeeStatusProposed: [ 1, 2 ] },
|
|
4205
|
+
},
|
|
4206
|
+
],
|
|
4207
|
+
},
|
|
4208
|
+
},
|
|
4197
4209
|
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4210
|
+
};
|
|
4211
|
+
const files = [];
|
|
4212
|
+
const list = await searchOpenSearchData( openSearch.trackerInput, getQuery );
|
|
4213
|
+
const folderPath = list?.body?.hits?.hits;
|
|
4214
|
+
if ( folderPath?.length > 0 ) {
|
|
4215
|
+
for ( const trackData of folderPath ) {
|
|
4216
|
+
const img =trackData?._source?.personPath?.split( '/' );
|
|
4217
|
+
const image = img[3]?.split( '.' );
|
|
4218
|
+
const indexes = trackData?._source?.REIDCluster;
|
|
4219
|
+
const data = inputData.export === true ? trackData?._source?.personPath :`${url.trackInput}${trackData?._source?.personPath}`;
|
|
4220
|
+
logger.info( { img: img, image: image, indexes: indexes, data: data } );
|
|
4221
|
+
addUniqueFile( files, {
|
|
4222
|
+
img_path: data,
|
|
4223
|
+
img_name: indexes,
|
|
4224
|
+
img_id: image[0],
|
|
4225
|
+
} );
|
|
4226
|
+
}
|
|
4227
|
+
if ( inputData.export !== true ) {
|
|
4228
|
+
return res.sendSuccess( { result: files } );
|
|
4229
|
+
}
|
|
4230
|
+
} else {
|
|
4231
|
+
logger.error( {
|
|
4232
|
+
error: { folderPath: folderPath },
|
|
4233
|
+
function: 'getAuditFile',
|
|
4234
|
+
message: 'Bucket image data not availale',
|
|
4235
|
+
} );
|
|
4236
|
+
return res.sendError( 'Bucket is Empty', 204 );
|
|
4237
|
+
}
|
|
4238
|
+
if ( files?.length == 0 ) {
|
|
4239
|
+
return res.sendError( 'No Data Found', 204 );
|
|
4240
|
+
}
|
|
4201
4241
|
|
|
4202
|
-
|
|
4242
|
+
if ( inputData.export == true ) {
|
|
4243
|
+
const auditImageDownload = await zipDownloadImage( files, inputData?.moduleType );
|
|
4244
|
+
res.set( 'Content-Type', 'application/zip' );
|
|
4245
|
+
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
4203
4246
|
|
|
4204
|
-
|
|
4247
|
+
return res.send( auditImageDownload );
|
|
4248
|
+
}
|
|
4205
4249
|
|
|
4206
|
-
const [ filterData, auditImageAC ] = await Promise.all( [ getAuditFilterData( inputData ), getAuditImageData( inputData ) ] );
|
|
4207
|
-
if ( filterData?.errorCode || auditImageAC?.errorCode ) {
|
|
4208
|
-
const error = ( filterData?.error || auditImageAC.error ) || 'Internal Server Error- get AC from Bucket';
|
|
4209
|
-
const code = filterData?.errorCode || auditImageAC.errorCode;
|
|
4210
|
-
return res.sendError( { error: error }, code );
|
|
4211
|
-
}
|
|
4212
4250
|
|
|
4213
|
-
|
|
4214
|
-
|
|
4251
|
+
break;
|
|
4252
|
+
|
|
4253
|
+
case 'AC':
|
|
4254
|
+
|
|
4255
|
+
|
|
4256
|
+
const getACQuery = {
|
|
4257
|
+
size: 10000,
|
|
4258
|
+
_source: [ 'module', 'status', 'date', 'store_id', 'outputCluster', 'personPath', 'REIDCluster', 'isEmployee', 'isJunk', 'EmployeeStatusFinal' ], // Only fetch necessary fields
|
|
4259
|
+
|
|
4260
|
+
query: {
|
|
4261
|
+
bool: {
|
|
4262
|
+
'must': [
|
|
4263
|
+
{
|
|
4264
|
+
term: { 'store_id.keyword': inputData.storeId },
|
|
4265
|
+
},
|
|
4266
|
+
{
|
|
4267
|
+
term: { 'date.keyword': inputData.fileDate },
|
|
4268
|
+
},
|
|
4269
|
+
{
|
|
4270
|
+
term: { 'module.keyword': 'CUSTOMER' },
|
|
4271
|
+
},
|
|
4272
|
+
{
|
|
4273
|
+
term: { 'status.keyword': 'PP_CLUSTER_FORMED' },
|
|
4274
|
+
},
|
|
4275
|
+
{
|
|
4276
|
+
terms: { EmployeeStatusFinal: [ 1, 2 ] },
|
|
4277
|
+
},
|
|
4278
|
+
],
|
|
4279
|
+
'should': [
|
|
4280
|
+
{ 'term': { 'isJunk': false } },
|
|
4281
|
+
{ 'bool': { 'must_not': { 'exists': { 'field': 'isJunk' } } } },
|
|
4282
|
+
],
|
|
4283
|
+
'minimum_should_match': 1,
|
|
4284
|
+
},
|
|
4285
|
+
},
|
|
4286
|
+
|
|
4287
|
+
};
|
|
4288
|
+
const filesAC = [];
|
|
4289
|
+
const listAC = await searchOpenSearchData( openSearch.trackerInput, getACQuery );
|
|
4290
|
+
const folderPathAC = listAC?.body?.hits?.hits;
|
|
4291
|
+
if ( folderPathAC?.length > 0 ) {
|
|
4292
|
+
for ( const trackData of folderPathAC ) {
|
|
4293
|
+
const img =trackData?._source?.personPath?.split( '/' );
|
|
4294
|
+
const image = img[3]?.split( '.' );
|
|
4295
|
+
const indexes = trackData?._source?.outputCluster ===50000? trackData?._source?.REIDCluster:trackData?._source?.outputCluster;
|
|
4296
|
+
const data = inputData.export === true ? trackData?._source?.personPath :`${url.trackInput}${trackData?._source?.personPath}`;
|
|
4297
|
+
logger.info( { img: img, image: image, indexes: indexes, data: data } );
|
|
4298
|
+
addUniqueFile( filesAC, {
|
|
4299
|
+
img_path: data,
|
|
4300
|
+
img_name: indexes,
|
|
4301
|
+
img_id: image[0],
|
|
4302
|
+
} );
|
|
4303
|
+
}
|
|
4304
|
+
if ( inputData.export !== true ) {
|
|
4305
|
+
return res.sendSuccess( { result: filesAC } );
|
|
4306
|
+
}
|
|
4307
|
+
} else {
|
|
4308
|
+
logger.error( {
|
|
4309
|
+
error: { folderPathAC: folderPathAC },
|
|
4310
|
+
function: 'getAuditFile',
|
|
4311
|
+
message: 'Bucket image data not availale',
|
|
4312
|
+
} );
|
|
4313
|
+
return res.sendError( 'Bucket is Empty', 204 );
|
|
4314
|
+
}
|
|
4315
|
+
if ( filesAC?.length == 0 ) {
|
|
4316
|
+
return res.sendError( 'No Data Found', 204 );
|
|
4317
|
+
}
|
|
4318
|
+
|
|
4319
|
+
if ( inputData.export == true ) {
|
|
4320
|
+
const auditImageDownload = await zipDownloadImage( filesAC, inputData?.moduleType );
|
|
4321
|
+
res.set( 'Content-Type', 'application/zip' );
|
|
4322
|
+
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
4323
|
+
|
|
4324
|
+
return res.send( auditImageDownload );
|
|
4325
|
+
}
|
|
4326
|
+
break;
|
|
4327
|
+
default:
|
|
4215
4328
|
return res.sendError( 'No Data Found', 204 );
|
|
4216
|
-
|
|
4329
|
+
break;
|
|
4330
|
+
}
|
|
4331
|
+
} else {
|
|
4332
|
+
let auditImageDownload = '';
|
|
4333
|
+
switch ( inputData.imageType ) {
|
|
4334
|
+
case 'BC':
|
|
4335
|
+
const auditImageBC = await getAuditImageData( inputData );
|
|
4336
|
+
if ( auditImageBC?.errorCode ) {
|
|
4337
|
+
const error = auditImageBC?.error || 'Internal Server Error- get BC from Bucket';
|
|
4338
|
+
const code = auditImageBC?.errorCode;
|
|
4339
|
+
return res.sendError( { error: error }, code );
|
|
4340
|
+
}
|
|
4341
|
+
if ( auditImageBC?.length == 0 ) {
|
|
4342
|
+
return res.sendError( 'No Data Found', 204 );
|
|
4343
|
+
}
|
|
4217
4344
|
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
res.set( 'Content-Type', 'application/zip' );
|
|
4222
|
-
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
4345
|
+
if ( inputData.export == true ) {
|
|
4346
|
+
auditImageDownload = await zipDownloadImage( auditImageBC, inputData?.moduleType );
|
|
4347
|
+
res.set( 'Content-Type', 'application/zip' );
|
|
4223
4348
|
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4349
|
+
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
4350
|
+
|
|
4351
|
+
return res.send( auditImageDownload );
|
|
4352
|
+
}
|
|
4353
|
+
return res.sendSuccess( { result: auditImageBC } );
|
|
4354
|
+
|
|
4355
|
+
break;
|
|
4356
|
+
|
|
4357
|
+
case 'AC':
|
|
4358
|
+
|
|
4359
|
+
const [ filterData, auditImageAC ] = await Promise.all( [ getAuditFilterData( inputData ), getAuditImageData( inputData ) ] );
|
|
4360
|
+
if ( filterData?.errorCode || auditImageAC?.errorCode ) {
|
|
4361
|
+
const error = ( filterData?.error || auditImageAC.error ) || 'Internal Server Error- get AC from Bucket';
|
|
4362
|
+
const code = filterData?.errorCode || auditImageAC.errorCode;
|
|
4363
|
+
return res.sendError( { error: error }, code );
|
|
4364
|
+
}
|
|
4365
|
+
|
|
4366
|
+
const reauditImg = await getReauditImg( filterData, auditImageAC );
|
|
4367
|
+
if ( reauditImg?.length == 0 ) {
|
|
4368
|
+
return res.sendError( 'No Data Found', 204 );
|
|
4369
|
+
}
|
|
4370
|
+
|
|
4371
|
+
if ( inputData.export == true ) {
|
|
4372
|
+
auditImageDownload = await zipDownloadImage( reauditImg, inputData?.moduleType );
|
|
4373
|
+
// Set response headers for the zip file
|
|
4374
|
+
res.set( 'Content-Type', 'application/zip' );
|
|
4375
|
+
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
4376
|
+
|
|
4377
|
+
// Send the zip file as the API response
|
|
4378
|
+
return res.send( auditImageDownload );
|
|
4379
|
+
}
|
|
4380
|
+
return res.sendSuccess( { result: reauditImg } );
|
|
4381
|
+
break;
|
|
4382
|
+
default:
|
|
4383
|
+
return res.sendError( 'No Data Found', 204 );
|
|
4384
|
+
break;
|
|
4385
|
+
}
|
|
4232
4386
|
}
|
|
4233
4387
|
} catch ( error ) {
|
|
4234
4388
|
const err = error.message || 'Internal Server Error';
|
|
@@ -277,21 +277,22 @@ export async function getAuditImageData( data ) {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
export async function zipDownloadImage( data ) {
|
|
280
|
+
export async function zipDownloadImage( data, modueType ) {
|
|
281
281
|
try {
|
|
282
|
-
logger.info( { zipDownloadImage: data } );
|
|
283
282
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
284
283
|
const zip = new AdmZip();
|
|
285
284
|
const split = await chunkArray( data, 10 );
|
|
286
285
|
const promises = await split.map( async ( chunk ) => {
|
|
287
|
-
for ( let
|
|
286
|
+
for ( let item of chunk ) {
|
|
288
287
|
const params ={
|
|
289
|
-
Bucket:
|
|
290
|
-
Key:
|
|
288
|
+
Bucket: modueType === 'track' ? bucket.trackInput :`${bucket.auditInput}`,
|
|
289
|
+
Key: modueType === 'track' ? item.img_path: item.imgFile.Key,
|
|
291
290
|
};
|
|
292
|
-
|
|
291
|
+
|
|
293
292
|
const fileBuffer = await getObject( params );
|
|
294
|
-
|
|
293
|
+
const splitItem = modueType === 'track'?item.img_path.split( '/' ) :null;
|
|
294
|
+
const key = modueType === 'track' ? `${splitItem[0]}/${splitItem[1]}/${splitItem[3]}`: item.imgFile.Key;
|
|
295
|
+
zip.addFile( key, fileBuffer.Body );
|
|
295
296
|
}
|
|
296
297
|
return zip;
|
|
297
298
|
} );
|