tango-app-api-audit 3.4.11-alpha.8 → 3.4.11
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 +2 -2
- package/src/controllers/audit.controllers.js +419 -354
- package/src/controllers/traxAudit.controllers.js +99 -62
- package/src/docs/audit.docs.js +56 -1
- package/src/dtos/audit.dtos.js +13 -0
- package/src/routes/audit.routes.js +5 -4
- package/src/service/auditUserWallet.service.js +4 -0
- package/src/service/auditUsers.service.js +4 -0
- package/src/validation/audit.validation.js +16 -0
- package/src/validation/traxAuditValidation.js +1 -0
|
@@ -799,11 +799,11 @@ export async function workSpace( req, res ) {
|
|
|
799
799
|
},
|
|
800
800
|
];
|
|
801
801
|
|
|
802
|
-
const auditUserCount = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
803
|
-
const userIncompleteFilesCount = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
802
|
+
const auditUserCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
803
|
+
const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
804
804
|
logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
|
|
805
805
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
806
|
-
const completedStoresCount = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
|
|
806
|
+
const completedStoresCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
|
|
807
807
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
808
808
|
const auditStoreData = await aggregateTraxAuditData(
|
|
809
809
|
auditStoreDataQuery,
|
|
@@ -980,7 +980,7 @@ export async function getAuditFile( req, res ) {
|
|
|
980
980
|
query ={
|
|
981
981
|
storeId: userDetails[0].storeId,
|
|
982
982
|
fileDate: userDetails[0].fileDate,
|
|
983
|
-
tempId: userDetails[0].tempId,
|
|
983
|
+
// tempId: userDetails[0].tempId,
|
|
984
984
|
moduleType: userDetails[0].moduleType,
|
|
985
985
|
};
|
|
986
986
|
break;
|
|
@@ -1445,7 +1445,7 @@ export async function saveBinary( req, res ) {
|
|
|
1445
1445
|
_id: inputData.auditId,
|
|
1446
1446
|
storeId: inputData.storeId,
|
|
1447
1447
|
fileDate: inputData.fileDate,
|
|
1448
|
-
tempId: inputData.tempId,
|
|
1448
|
+
// tempId: inputData.tempId,
|
|
1449
1449
|
moduleType: inputData.moduleType,
|
|
1450
1450
|
};
|
|
1451
1451
|
|
|
@@ -1841,7 +1841,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1841
1841
|
},
|
|
1842
1842
|
);
|
|
1843
1843
|
}
|
|
1844
|
-
const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1844
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1845
1845
|
if ( count.length == 0 ) {
|
|
1846
1846
|
return res.sendError( 'No Data Found', 204 );
|
|
1847
1847
|
}
|
|
@@ -1886,10 +1886,13 @@ export async function userAuditHistory( req, res ) {
|
|
|
1886
1886
|
temp['User Comments'] = element.userComments;
|
|
1887
1887
|
break;
|
|
1888
1888
|
case 'uniform-detection':
|
|
1889
|
-
temp['Customer ID'] = element.tempId;
|
|
1890
|
-
temp['Question'] = element.question;
|
|
1891
|
-
temp['Result'] = element.answer;
|
|
1892
|
-
temp['User Comments'] = element.userComments;
|
|
1889
|
+
// temp['Customer ID'] = element.tempId;
|
|
1890
|
+
// temp['Question'] = element.question;
|
|
1891
|
+
// temp['Result'] = element.answer;
|
|
1892
|
+
// temp['User Comments'] = element.userComments;
|
|
1893
|
+
temp['Before Count'] = element.beforeCount;
|
|
1894
|
+
temp['After Count'] = element.afterCount;
|
|
1895
|
+
temp['Accuracy'] = element.accuracy || '';
|
|
1893
1896
|
break;
|
|
1894
1897
|
case 'mobile-detection':
|
|
1895
1898
|
temp['Before Count'] = element.beforeCount;
|
|
@@ -1914,7 +1917,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1914
1917
|
{
|
|
1915
1918
|
$limit: limit,
|
|
1916
1919
|
} );
|
|
1917
|
-
const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1920
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1918
1921
|
|
|
1919
1922
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1920
1923
|
} catch ( error ) {
|
|
@@ -2239,7 +2242,7 @@ export async function clientMetrics( req, res ) {
|
|
|
2239
2242
|
);
|
|
2240
2243
|
}
|
|
2241
2244
|
|
|
2242
|
-
const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
2245
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
2243
2246
|
logger.info( { count: count } );
|
|
2244
2247
|
if ( count.length == 0 ) {
|
|
2245
2248
|
return res.sendError( 'No Data Found', 204 );
|
|
@@ -2306,7 +2309,7 @@ export async function clientMetrics( req, res ) {
|
|
|
2306
2309
|
);
|
|
2307
2310
|
}
|
|
2308
2311
|
|
|
2309
|
-
const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
2312
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateTraxAuditData( MappingQuery ) : await aggregateTraxAuditData( query );
|
|
2310
2313
|
if ( result.length == 0 ) {
|
|
2311
2314
|
return res.sendError( 'No Data Found', 204 );
|
|
2312
2315
|
}
|
|
@@ -2341,7 +2344,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2341
2344
|
}
|
|
2342
2345
|
|
|
2343
2346
|
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
2344
|
-
[ 'mobile-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
2347
|
+
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
2345
2348
|
}
|
|
2346
2349
|
|
|
2347
2350
|
if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
|
|
@@ -2774,7 +2777,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2774
2777
|
},
|
|
2775
2778
|
);
|
|
2776
2779
|
}
|
|
2777
|
-
const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2780
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2778
2781
|
|
|
2779
2782
|
|
|
2780
2783
|
if ( count.length == 0 ) {
|
|
@@ -2798,7 +2801,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2798
2801
|
$limit: limit,
|
|
2799
2802
|
} );
|
|
2800
2803
|
}
|
|
2801
|
-
const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2804
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2802
2805
|
if ( inputData.isExport ) {
|
|
2803
2806
|
const exportdata = [];
|
|
2804
2807
|
result.forEach( ( element ) => {
|
|
@@ -2839,11 +2842,15 @@ export async function storeMetrics( req, res ) {
|
|
|
2839
2842
|
temp['Accuracy'] = element.accuracy;
|
|
2840
2843
|
break;
|
|
2841
2844
|
case 'uniform-detection':
|
|
2842
|
-
temp['Customer ID'] = element.tempId;
|
|
2843
|
-
temp['Question'] = element.question;
|
|
2844
|
-
temp['User Comments'] = element.userComments;
|
|
2845
|
-
temp['Status'] = toCamelCase( element.auditStatus );
|
|
2846
|
-
temp['Result'] = element.answer;
|
|
2845
|
+
// temp['Customer ID'] = element.tempId;
|
|
2846
|
+
// temp['Question'] = element.question;
|
|
2847
|
+
// temp['User Comments'] = element.userComments;
|
|
2848
|
+
// temp['Status'] = toCamelCase( element.auditStatus );
|
|
2849
|
+
// temp['Result'] = element.answer;
|
|
2850
|
+
temp['Before Count'] = element.beforeCount;
|
|
2851
|
+
temp['After Count'] = element.afterCount;
|
|
2852
|
+
temp['Status'] = toCamelCase( element.status );
|
|
2853
|
+
temp['Accuracy'] = element.accuracy;
|
|
2847
2854
|
break;
|
|
2848
2855
|
}
|
|
2849
2856
|
exportdata.push( temp );
|
|
@@ -3117,7 +3124,7 @@ export async function userMetrics( req, res ) {
|
|
|
3117
3124
|
);
|
|
3118
3125
|
}
|
|
3119
3126
|
|
|
3120
|
-
const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3127
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3121
3128
|
if ( count.length == 0 ) {
|
|
3122
3129
|
return res.sendError( 'No Data Found', 204 );
|
|
3123
3130
|
}
|
|
@@ -3153,7 +3160,7 @@ export async function userMetrics( req, res ) {
|
|
|
3153
3160
|
'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
|
|
3154
3161
|
// 'Mapping Percentage': '$mappingPerc',
|
|
3155
3162
|
};
|
|
3156
|
-
[ 'mobile-detection' ].includes( inputData.moduleType )?
|
|
3163
|
+
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?
|
|
3157
3164
|
query.push(
|
|
3158
3165
|
{
|
|
3159
3166
|
$project: detection,
|
|
@@ -3167,7 +3174,7 @@ export async function userMetrics( req, res ) {
|
|
|
3167
3174
|
}
|
|
3168
3175
|
|
|
3169
3176
|
|
|
3170
|
-
const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3177
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3171
3178
|
if ( inputData.isExport ) {
|
|
3172
3179
|
await download( result, res );
|
|
3173
3180
|
return;
|
|
@@ -3311,7 +3318,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3311
3318
|
},
|
|
3312
3319
|
);
|
|
3313
3320
|
}
|
|
3314
|
-
const count = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3321
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3315
3322
|
if ( count.length == 0 ) {
|
|
3316
3323
|
return res.sendError( 'No Data Found', 204 );
|
|
3317
3324
|
}
|
|
@@ -3327,7 +3334,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3327
3334
|
} );
|
|
3328
3335
|
}
|
|
3329
3336
|
|
|
3330
|
-
const result = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3337
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3331
3338
|
if ( inputData.isExport ) {
|
|
3332
3339
|
const exportdata = [];
|
|
3333
3340
|
result.forEach( ( element ) => {
|
|
@@ -3356,8 +3363,9 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3356
3363
|
temp['Before Count'] = element.beforeCount;
|
|
3357
3364
|
break;
|
|
3358
3365
|
case 'uniform-detection':
|
|
3359
|
-
temp['Customer ID'] = element.tempId;
|
|
3360
|
-
temp['Question'] = element.question;
|
|
3366
|
+
// temp['Customer ID'] = element.tempId;
|
|
3367
|
+
// temp['Question'] = element.question;
|
|
3368
|
+
temp['Before Count'] = element.beforeCount;
|
|
3361
3369
|
break;
|
|
3362
3370
|
}
|
|
3363
3371
|
exportdata.push( temp );
|
|
@@ -3522,7 +3530,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
3522
3530
|
},
|
|
3523
3531
|
];
|
|
3524
3532
|
|
|
3525
|
-
const storeAudit = [ 'mobile-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3533
|
+
const storeAudit = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3526
3534
|
if ( storeAudit.length > 0 ) {
|
|
3527
3535
|
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
3528
3536
|
temp.completedStores = storeAudit[0].completedStores;
|
|
@@ -3710,7 +3718,7 @@ export async function summarySplit( req, res ) {
|
|
|
3710
3718
|
},
|
|
3711
3719
|
},
|
|
3712
3720
|
];
|
|
3713
|
-
const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3721
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3714
3722
|
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3715
3723
|
result[0].totalCount = totalCount[0]?.total;
|
|
3716
3724
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
@@ -3740,7 +3748,7 @@ export async function overviewTable( req, res ) {
|
|
|
3740
3748
|
}
|
|
3741
3749
|
|
|
3742
3750
|
if ( inputData.filterByStatus.length > 0 ) {
|
|
3743
|
-
[ 'mobile-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3751
|
+
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3744
3752
|
}
|
|
3745
3753
|
|
|
3746
3754
|
const query =[
|
|
@@ -3857,7 +3865,7 @@ export async function overviewTable( req, res ) {
|
|
|
3857
3865
|
},
|
|
3858
3866
|
);
|
|
3859
3867
|
}
|
|
3860
|
-
const count = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3868
|
+
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3861
3869
|
if ( count.length == 0 ) {
|
|
3862
3870
|
return res.sendError( 'No Data Found', 204 );
|
|
3863
3871
|
}
|
|
@@ -3872,7 +3880,7 @@ export async function overviewTable( req, res ) {
|
|
|
3872
3880
|
$limit: limit,
|
|
3873
3881
|
} );
|
|
3874
3882
|
}
|
|
3875
|
-
const result = [ 'mobile-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3883
|
+
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3876
3884
|
if ( inputData.isExport ) {
|
|
3877
3885
|
const exportdata = [];
|
|
3878
3886
|
result.forEach( ( element ) => {
|
|
@@ -3909,11 +3917,15 @@ export async function overviewTable( req, res ) {
|
|
|
3909
3917
|
temp['Status'] = toCamelCase( element.status );
|
|
3910
3918
|
break;
|
|
3911
3919
|
case 'uniform-detection':
|
|
3912
|
-
temp['Customer ID'] = element.tempId;
|
|
3913
|
-
temp['Question'] = element.question;
|
|
3914
|
-
temp['User Comments'] = element.userComments;
|
|
3920
|
+
// temp['Customer ID'] = element.tempId;
|
|
3921
|
+
// temp['Question'] = element.question;
|
|
3922
|
+
// temp['User Comments'] = element.userComments;
|
|
3923
|
+
// temp['Audit Type'] = element.auditType;
|
|
3924
|
+
// temp['Status'] = toCamelCase( element.auditStatus );
|
|
3925
|
+
temp['Before Count'] = element.beforeCount;
|
|
3926
|
+
temp['After Count'] = element.afterCount;
|
|
3915
3927
|
temp['Audit Type'] = element.auditType;
|
|
3916
|
-
temp['Status'] = toCamelCase( element.
|
|
3928
|
+
temp['Status'] = toCamelCase( element.status );
|
|
3917
3929
|
break;
|
|
3918
3930
|
}
|
|
3919
3931
|
exportdata.push( temp );
|
|
@@ -4509,9 +4521,10 @@ export async function save( req, res ) {
|
|
|
4509
4521
|
afterCount: inputData.employeeCount,
|
|
4510
4522
|
timeSpent: timeDifferenceInMinutes,
|
|
4511
4523
|
};
|
|
4512
|
-
|
|
4513
|
-
await updateOneStoreEmpDetection( query, storeUpdated );
|
|
4524
|
+
logger.info( { query: query, function: 'saveQuery' } );
|
|
4525
|
+
const [ userUpdate, storeUpdate ] = await Promise.all( [ updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated ), updateOneStoreEmpDetection( query, storeUpdated ) ] );
|
|
4514
4526
|
|
|
4527
|
+
logger.info( { userUpdate: userUpdate, storeUpdate: storeUpdate, function: 'saveUpdate' } );
|
|
4515
4528
|
const getFilePath = await findOneTraxAuditData(
|
|
4516
4529
|
{
|
|
4517
4530
|
fileDate: inputData.fileDate,
|
|
@@ -4522,37 +4535,61 @@ export async function save( req, res ) {
|
|
|
4522
4535
|
if ( !getFilePath ) {
|
|
4523
4536
|
return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
|
|
4524
4537
|
}
|
|
4538
|
+
const [ getStore, getClient ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: inputData.clientId }, { clientName: 1 } ) ] );
|
|
4539
|
+
|
|
4525
4540
|
const tempId=[];
|
|
4526
4541
|
if ( inputData.employeeCount > 0 ) {
|
|
4527
4542
|
for ( let i =0; i<inputData?.employee.length; i++ ) {
|
|
4528
4543
|
tempId.push( inputData?.employee[i].img_id );
|
|
4529
4544
|
}
|
|
4530
|
-
}
|
|
4531
|
-
const sqsProduceQueue = {
|
|
4532
|
-
QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
|
|
4533
|
-
MessageBody: JSON.stringify( {
|
|
4534
|
-
storeId: inputData.storeId,
|
|
4535
|
-
fileDate: inputData.fileDate,
|
|
4536
|
-
moduleType: inputData.moduleType,
|
|
4537
|
-
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
4538
|
-
tempId: tempId,
|
|
4539
|
-
count: inputData.employeeCount,
|
|
4540
|
-
folderPath: getFilePath?.sqs?.Body?.folderPath,
|
|
4541
|
-
} ),
|
|
4542
|
-
};
|
|
4543
|
-
const sqsQueue = await sendMessageToQueue(
|
|
4544
|
-
sqsProduceQueue.QueueUrl,
|
|
4545
|
-
sqsProduceQueue.MessageBody,
|
|
4546
|
-
);
|
|
4547
4545
|
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4546
|
+
const sqsProduceQueue = {
|
|
4547
|
+
QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
|
|
4548
|
+
MessageBody: JSON.stringify( {
|
|
4549
|
+
storeId: inputData.storeId,
|
|
4550
|
+
storeName: getStore?.storeName,
|
|
4551
|
+
fileDate: inputData.fileDate,
|
|
4552
|
+
moduleType: inputData.moduleType,
|
|
4553
|
+
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
4554
|
+
tempId: tempId,
|
|
4555
|
+
count: inputData.employeeCount,
|
|
4556
|
+
folderPath: getFilePath?.sqs?.Body?.folderPath,
|
|
4557
|
+
} ),
|
|
4558
|
+
};
|
|
4559
|
+
const sqsQueue = await sendMessageToQueue(
|
|
4560
|
+
sqsProduceQueue.QueueUrl,
|
|
4561
|
+
sqsProduceQueue.MessageBody,
|
|
4562
|
+
);
|
|
4563
|
+
|
|
4564
|
+
if ( sqsQueue.statusCode ) {
|
|
4565
|
+
logger.error( {
|
|
4566
|
+
error: `${sqsQueue}`,
|
|
4567
|
+
type: 'UPLOAD_ERROR',
|
|
4568
|
+
} );
|
|
4569
|
+
return res.sendError( 'SQS not sent', 500 );
|
|
4570
|
+
}
|
|
4554
4571
|
}
|
|
4555
4572
|
|
|
4573
|
+
|
|
4574
|
+
// trax output in open serach
|
|
4575
|
+
const output = {
|
|
4576
|
+
clientId: inputData.clientId,
|
|
4577
|
+
clientName: getClient?.clientName,
|
|
4578
|
+
storeId: inputData.storeId,
|
|
4579
|
+
storeName: getStore?.storeName,
|
|
4580
|
+
spocName: getStore?.spocDetails[0]?.name,
|
|
4581
|
+
spocEmail: getStore?.spocDetails[0]?.email,
|
|
4582
|
+
spocContact: getStore?.spocDetails[0].contact,
|
|
4583
|
+
address: getStore?.storeProfile?.address,
|
|
4584
|
+
fileDate: inputData.fileDate,
|
|
4585
|
+
moduleType: inputData.moduleType,
|
|
4586
|
+
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
4587
|
+
tempId: tempId,
|
|
4588
|
+
count: inputData.employeeCount,
|
|
4589
|
+
folderPath: getFilePath?.sqs?.Body?.folderPath,
|
|
4590
|
+
createdAt: new Date(),
|
|
4591
|
+
};
|
|
4592
|
+
await insertOpenSearchData( openSearch.traxDetectionOutput, output );
|
|
4556
4593
|
const logData = {
|
|
4557
4594
|
userId: req.user._id,
|
|
4558
4595
|
userName: req.user.userName,
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema, pendingSummaryTableSchema, overviewTableSchema } from '../dtos/audit.dtos.js';
|
|
1
|
+
import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema, pendingSummaryTableSchema, overviewTableSchema, auditViewlogSchema } from '../dtos/audit.dtos.js';
|
|
2
2
|
import j2s from 'joi-to-swagger';
|
|
3
3
|
|
|
4
4
|
export const auditDocs = {
|
|
@@ -544,6 +544,61 @@ export const auditDocs = {
|
|
|
544
544
|
},
|
|
545
545
|
},
|
|
546
546
|
},
|
|
547
|
+
'/v3/audit/audit-view-logs': {
|
|
548
|
+
get: {
|
|
549
|
+
tags: [ 'Audit Mapping' ],
|
|
550
|
+
description: `Get log for a store audit details`,
|
|
551
|
+
operationId: 'audit-view-logs',
|
|
552
|
+
parameters: [
|
|
553
|
+
{
|
|
554
|
+
in: 'query',
|
|
555
|
+
name: 'fileDate',
|
|
556
|
+
scema: j2s( auditViewlogSchema ).swagger,
|
|
557
|
+
require: true,
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
in: 'query',
|
|
561
|
+
name: 'storeId',
|
|
562
|
+
scema: j2s( auditViewlogSchema ).swagger,
|
|
563
|
+
require: true,
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
in: 'query',
|
|
567
|
+
name: 'moduleType',
|
|
568
|
+
scema: j2s( auditViewlogSchema ).swagger,
|
|
569
|
+
require: true,
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
in: 'query',
|
|
573
|
+
name: 'zoneName',
|
|
574
|
+
scema: j2s( auditViewlogSchema ).swagger,
|
|
575
|
+
require: false,
|
|
576
|
+
},
|
|
577
|
+
],
|
|
578
|
+
responses: {
|
|
579
|
+
200: { description: 'Successful' },
|
|
580
|
+
401: { description: 'Unauthorized User' },
|
|
581
|
+
422: { description: 'Field Error' },
|
|
582
|
+
500: { description: 'Server Error' },
|
|
583
|
+
204: { description: 'Not Found' },
|
|
584
|
+
},
|
|
585
|
+
|
|
586
|
+
},
|
|
587
|
+
},
|
|
588
|
+
'/v3/audit/get-user-credit': {
|
|
589
|
+
get: {
|
|
590
|
+
tags: [ 'Audit User Wallet' ],
|
|
591
|
+
description: 'Get single past date credit',
|
|
592
|
+
operationId: 'get-user-credit',
|
|
593
|
+
responses: {
|
|
594
|
+
200: { description: 'Successful' },
|
|
595
|
+
401: { description: 'Unauthorized User' },
|
|
596
|
+
422: { description: 'Field Error' },
|
|
597
|
+
500: { description: 'Server Error' },
|
|
598
|
+
204: { description: 'Not Found' },
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
},
|
|
547
602
|
'/v3/audit/get-user-audit-count': {
|
|
548
603
|
get: {
|
|
549
604
|
tags: [ 'Audit User Wallet' ],
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -51,6 +51,7 @@ export const saveDraftSchema = joi.object( {
|
|
|
51
51
|
storeId: joi.string().required(),
|
|
52
52
|
auditId: joi.string().required(),
|
|
53
53
|
moduleType: joi.string().required(),
|
|
54
|
+
timeSpent: joi.number().required(),
|
|
54
55
|
zoneName: joi.string().required(),
|
|
55
56
|
auditType: joi.string().required(),
|
|
56
57
|
fileDate: joi.string().required(),
|
|
@@ -89,6 +90,7 @@ export const saveSchema = joi.object( {
|
|
|
89
90
|
fileDate: joi.string().required(),
|
|
90
91
|
auditType: joi.string().required(),
|
|
91
92
|
moduleType: joi.string().required(),
|
|
93
|
+
timeSpent: joi.number().required(),
|
|
92
94
|
zoneName: joi.string().required(),
|
|
93
95
|
beforeCount: joi.number().required(),
|
|
94
96
|
junkCount: joi.number().required(),
|
|
@@ -237,6 +239,17 @@ export const overviewTableValid = {
|
|
|
237
239
|
body: overviewTableSchema,
|
|
238
240
|
};
|
|
239
241
|
|
|
242
|
+
export const auditViewlogSchema = joi.object( {
|
|
243
|
+
fileDate: joi.string().required(),
|
|
244
|
+
storeId: joi.string().required(),
|
|
245
|
+
moduleType: joi.string().required(),
|
|
246
|
+
zoneName: joi.string().optional(),
|
|
247
|
+
} );
|
|
248
|
+
|
|
249
|
+
export const auditViewLogValid = {
|
|
250
|
+
query: auditViewlogSchema,
|
|
251
|
+
};
|
|
252
|
+
|
|
240
253
|
export const overAllAuditSummarySchema = joi.object( {
|
|
241
254
|
fromDate: joi.string().required(),
|
|
242
255
|
toDate: joi.string().required(),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
-
import { isAuditDocumentExist, isAuditInputFolderExist, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
2
|
+
import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs } from '../controllers/audit.controllers.js';
|
|
5
|
-
import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
|
|
4
|
+
import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs, getUserCredit } from '../controllers/audit.controllers.js';
|
|
5
|
+
import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid, auditViewLogValid } from '../dtos/audit.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditRouter = express.Router();
|
|
8
8
|
|
|
@@ -37,9 +37,10 @@ auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate(
|
|
|
37
37
|
auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotAssignedCount );
|
|
38
38
|
|
|
39
39
|
// audit user wallet
|
|
40
|
+
auditRouter.get( '/get-user-credit', isAllowedSessionHandler, isAuditUser, getUserCredit );
|
|
40
41
|
auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditCount );
|
|
41
42
|
auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
|
|
42
43
|
|
|
43
44
|
// audit log
|
|
44
|
-
auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, auditViewLogs );
|
|
45
|
+
auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, validate( auditViewLogValid ), auditViewLogs );
|
|
45
46
|
export default auditRouter;
|
|
@@ -5,6 +5,10 @@ export function createAuditUserWallet( record ) {
|
|
|
5
5
|
return auditUserWalletModel.create( record );
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
export function findOneAuditUserWallet( record, fields, sort = { createdAt: -1 } ) {
|
|
9
|
+
return auditUserWalletModel.findOne( record, fields ).sort( sort );
|
|
10
|
+
};
|
|
11
|
+
|
|
8
12
|
export function updateManyAuditUserWallet( query, record ) {
|
|
9
13
|
return auditUserWalletModel.updateMany( query, record, { upsert: true } );
|
|
10
14
|
};
|
|
@@ -3,3 +3,7 @@ import auditUsersModel from 'tango-api-schema/schema/auditUsers.model.js';
|
|
|
3
3
|
export function aggregateAuditUsers( query ) {
|
|
4
4
|
return auditUsersModel.aggregate( query );
|
|
5
5
|
};
|
|
6
|
+
|
|
7
|
+
export function findOneAuditUsers( query, fields ) {
|
|
8
|
+
return auditUsersModel.findOne( query, fields );
|
|
9
|
+
};
|
|
@@ -2,6 +2,7 @@ import { checkFileExist, chunkArray, getJsonFileData, getObject, getQueueUrl, li
|
|
|
2
2
|
import { findOneUserAudit } from '../service/userAudit.service.js';
|
|
3
3
|
import { findOneStoreAudit } from '../service/storeAudit.service.js';
|
|
4
4
|
import AdmZip from 'adm-zip';
|
|
5
|
+
import { findOneAuditUsers } from '../service/auditUsers.service.js';
|
|
5
6
|
|
|
6
7
|
export async function isExistsQueue( req, res, next ) {
|
|
7
8
|
try {
|
|
@@ -154,6 +155,7 @@ const mapFunction = async ( chunkData, filterData ) => {
|
|
|
154
155
|
if ( mappedId.img_name === item.temp_ids ) {
|
|
155
156
|
item.temp_ids = data.img_name;
|
|
156
157
|
item.query_status = '';
|
|
158
|
+
item.demographic = data.demographic || '';
|
|
157
159
|
}
|
|
158
160
|
} );
|
|
159
161
|
}
|
|
@@ -332,4 +334,18 @@ export async function getAuditFilterData( data ) {
|
|
|
332
334
|
}
|
|
333
335
|
}
|
|
334
336
|
|
|
337
|
+
export async function isAuditUser( req, res, next ) {
|
|
338
|
+
try {
|
|
339
|
+
const userEmail = req.user?.email;
|
|
340
|
+
const getAuditUser = await findOneAuditUsers( { email: userEmail, isActive: true } );
|
|
341
|
+
if ( !getAuditUser ) {
|
|
342
|
+
return res.sendSuccess( { result: 0, isAuditUser: false } );
|
|
343
|
+
}
|
|
344
|
+
return next();
|
|
345
|
+
} catch ( error ) {
|
|
346
|
+
const err = error.message || 'Internal Server Error';
|
|
347
|
+
logger.error( { error: error, function: 'isAuditUser' } );
|
|
348
|
+
return res.sendError( err, 500 );
|
|
349
|
+
}
|
|
350
|
+
}
|
|
335
351
|
|