tango-app-api-audit 3.3.0-beta.1 → 3.3.0-beta.3
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 +3 -3
- package/src/controllers/audit.controllers.js +148 -78
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tango-app-api-audit",
|
|
3
|
-
"version": "3.3.0-beta.
|
|
3
|
+
"version": "3.3.0-beta.3",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"mongodb": "^6.7.0",
|
|
25
25
|
"nodemon": "^3.1.3",
|
|
26
26
|
"swagger-ui-express": "^5.0.1",
|
|
27
|
-
"tango-api-schema": "^2.0.
|
|
28
|
-
"tango-app-api-middleware": "^3.
|
|
27
|
+
"tango-api-schema": "^2.0.159",
|
|
28
|
+
"tango-app-api-middleware": "^3.1.32",
|
|
29
29
|
"winston": "^3.13.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
31
31
|
},
|
|
@@ -496,7 +496,6 @@ export async function getAuditFile( req, res ) {
|
|
|
496
496
|
const list = await listFileByPath( fetchData );
|
|
497
497
|
const folderPath = list.data;
|
|
498
498
|
const nextQuery = list.pageToken;
|
|
499
|
-
logger.info( { nextQuery: folderPath } );
|
|
500
499
|
if ( folderPath?.length > 0 ) {
|
|
501
500
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
502
501
|
const img = folderPath[i].Key.split( '/' );
|
|
@@ -762,6 +761,11 @@ export async function workSpace( req, res ) {
|
|
|
762
761
|
$project: {
|
|
763
762
|
clientName: 1,
|
|
764
763
|
clientId: 1,
|
|
764
|
+
queueName: {
|
|
765
|
+
$cond: [
|
|
766
|
+
{ $eq: [ inputData.moduleType, 'zone' ] }, '$auditConfigs.zoneQueueName', '$auditConfigs.trafficQueueName',
|
|
767
|
+
],
|
|
768
|
+
},
|
|
765
769
|
},
|
|
766
770
|
},
|
|
767
771
|
];
|
|
@@ -818,7 +822,7 @@ export async function workSpace( req, res ) {
|
|
|
818
822
|
clientId: { $last: '$clientId' },
|
|
819
823
|
clientName: { $last: '$clientName' },
|
|
820
824
|
installedStore: { $last: '$installedStore' },
|
|
821
|
-
queueName: { $last: '$queueName' },
|
|
825
|
+
// queueName: { $last: '$queueName' },
|
|
822
826
|
totalCount: { $sum: 1 },
|
|
823
827
|
},
|
|
824
828
|
},
|
|
@@ -1642,25 +1646,46 @@ export async function userAuditHistory( req, res ) {
|
|
|
1642
1646
|
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
1643
1647
|
const exportData = [];
|
|
1644
1648
|
chunk.forEach( ( element ) => {
|
|
1645
|
-
|
|
1649
|
+
if ( element.moduleType == 'zone' ) {
|
|
1650
|
+
exportData.push( {
|
|
1651
|
+
'File Date': element.fileDate,
|
|
1652
|
+
'Brand ID': element.clientId,
|
|
1653
|
+
'Brand Name': element.clientName,
|
|
1654
|
+
'Store ID': element.storeId,
|
|
1655
|
+
'Store Name': element.storeName,
|
|
1656
|
+
'Zone Name': element.zoneName,
|
|
1657
|
+
'Audit Type': element.auditType,
|
|
1658
|
+
'Product Type': element.moduleType,
|
|
1659
|
+
'Before Count': element.beforeCount,
|
|
1660
|
+
'After Count': element.afterCount || '',
|
|
1661
|
+
'Accuracy': element.accuracy || '',
|
|
1662
|
+
'Start Time': element.startTime,
|
|
1663
|
+
'End Time': element.endTime || '',
|
|
1664
|
+
'Time Spent': element.timeSpent,
|
|
1665
|
+
'Audit Status': element.auditStatus,
|
|
1666
|
+
'Audited Date': dayjs( element.createdAt ).format( 'YYYY,MMM D' ),
|
|
1646
1667
|
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1668
|
+
} );
|
|
1669
|
+
} else {
|
|
1670
|
+
exportData.push( {
|
|
1671
|
+
'File Date': element.fileDate,
|
|
1672
|
+
'Brand ID': element.clientId,
|
|
1673
|
+
'Brand Name': element.clientName,
|
|
1674
|
+
'Store ID': element.storeId,
|
|
1675
|
+
'Store Name': element.storeName,
|
|
1676
|
+
'Audit Type': element.auditType,
|
|
1677
|
+
'Product Type': element.moduleType,
|
|
1678
|
+
'Before Count': element.beforeCount,
|
|
1679
|
+
'After Count': element.afterCount || '',
|
|
1680
|
+
'Accuracy': element.accuracy || '',
|
|
1681
|
+
'Start Time': element.startTime,
|
|
1682
|
+
'End Time': element.endTime || '',
|
|
1683
|
+
'Time Spent': element.timeSpent,
|
|
1684
|
+
'Audit Status': element.auditStatus,
|
|
1685
|
+
'Audited Date': dayjs( element.createdAt ).format( 'YYYY,MMM D' ),
|
|
1662
1686
|
|
|
1663
|
-
|
|
1687
|
+
} );
|
|
1688
|
+
}
|
|
1664
1689
|
} );
|
|
1665
1690
|
return exportData;
|
|
1666
1691
|
} );
|
|
@@ -1784,7 +1809,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1784
1809
|
completedStores: 1,
|
|
1785
1810
|
inprogressStores: 1,
|
|
1786
1811
|
notAssignedStores: 1,
|
|
1787
|
-
fileCount:
|
|
1812
|
+
fileCount: { $ifNull: [ '$fileCount', 0 ] },
|
|
1788
1813
|
completionPercentage: { $ifNull: [
|
|
1789
1814
|
{
|
|
1790
1815
|
$round: [ {
|
|
@@ -1824,8 +1849,8 @@ export async function clientMetrics( req, res ) {
|
|
|
1824
1849
|
// notAssignedStores: '$storeAudit.notAssignedStores',
|
|
1825
1850
|
inprogressStoresCount: '$storeAudit.inprogressStores',
|
|
1826
1851
|
// fileCount: '$storeAudit.fileCount',
|
|
1827
|
-
notAssignedCount:
|
|
1828
|
-
clientStatus: { $cond: [ { $eq: [ '$storeAudit.fileCount', 0 ] }, 'not-taken', { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$storeAudit.notAssignedStores', 0 ] } ] }
|
|
1852
|
+
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$storeAudit.fileCount', 0 ] }, { $ifNull: [ '$storeAudit.notAssignedStores', 0 ] } ] } ] },
|
|
1853
|
+
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$storeAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$storeAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$storeAudit.notAssignedStores', 0 ] } ] }
|
|
1829
1854
|
completedStores: '$storeAudit.completedStores',
|
|
1830
1855
|
completionPercentage: '$storeAudit.completionPercentage',
|
|
1831
1856
|
|
|
@@ -1881,7 +1906,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1881
1906
|
'File Date': '$fileDate',
|
|
1882
1907
|
'Client Name': '$clientName',
|
|
1883
1908
|
'Client Id': '$clientId',
|
|
1884
|
-
'
|
|
1909
|
+
'Product Type': '$moduleType',
|
|
1885
1910
|
'Completed Percentage': '$completionPercentage',
|
|
1886
1911
|
'Installed Stores': '$installedStore',
|
|
1887
1912
|
'Audit Stores': '$totalFilesCount',
|
|
@@ -1994,13 +2019,12 @@ export async function storeMetrics( req, res ) {
|
|
|
1994
2019
|
auditType: 1,
|
|
1995
2020
|
beforeCount: 1,
|
|
1996
2021
|
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
1997
|
-
accuracy: { $round: [
|
|
1998
|
-
{
|
|
1999
|
-
|
|
2000
|
-
|
|
2022
|
+
accuracy: { $cond: [ { $eq: [ '$status', 'completed' ] }, { $round: [
|
|
2023
|
+
{
|
|
2024
|
+
$multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
|
|
2025
|
+
}, 1,
|
|
2001
2026
|
],
|
|
2002
|
-
|
|
2003
|
-
},
|
|
2027
|
+
}, null ] },
|
|
2004
2028
|
timeSpent: 1,
|
|
2005
2029
|
status: 1,
|
|
2006
2030
|
},
|
|
@@ -2075,13 +2099,12 @@ export async function storeMetrics( req, res ) {
|
|
|
2075
2099
|
auditType: 1,
|
|
2076
2100
|
beforeCount: 1,
|
|
2077
2101
|
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
2078
|
-
accuracy: { $round: [
|
|
2079
|
-
{
|
|
2080
|
-
|
|
2081
|
-
|
|
2102
|
+
accuracy: { $cond: [ { $eq: [ '$status', 'completed' ] }, { $round: [
|
|
2103
|
+
{
|
|
2104
|
+
$multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
|
|
2105
|
+
}, 1,
|
|
2082
2106
|
],
|
|
2083
|
-
|
|
2084
|
-
},
|
|
2107
|
+
}, null ] },
|
|
2085
2108
|
timeSpent: {
|
|
2086
2109
|
|
|
2087
2110
|
$cond: [
|
|
@@ -2125,6 +2148,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2125
2148
|
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2126
2149
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2127
2150
|
{ moduleType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2151
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2128
2152
|
],
|
|
2129
2153
|
},
|
|
2130
2154
|
} );
|
|
@@ -2157,19 +2181,36 @@ export async function storeMetrics( req, res ) {
|
|
|
2157
2181
|
if ( inputData.isExport ) {
|
|
2158
2182
|
const exportdata = [];
|
|
2159
2183
|
result.forEach( ( element ) => {
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2184
|
+
if ( element.moduleType == 'zone' ) {
|
|
2185
|
+
exportdata.push( {
|
|
2186
|
+
'File Date': element.fileDate,
|
|
2187
|
+
'Store ID': element.storeId,
|
|
2188
|
+
'Store Name': element.storeName,
|
|
2189
|
+
'Client Id': element.clientId,
|
|
2190
|
+
'Client Name': element.clientName,
|
|
2191
|
+
'Zone Name': element.zoneName,
|
|
2192
|
+
'User Name': element.userName,
|
|
2193
|
+
'User Email': element.userEmail,
|
|
2194
|
+
'Audit Type': element.auditType,
|
|
2195
|
+
'Accuracy': element.accuracy,
|
|
2196
|
+
'Time Spent': element.timeSpent,
|
|
2197
|
+
'Status': element.status,
|
|
2198
|
+
} );
|
|
2199
|
+
} else {
|
|
2200
|
+
exportdata.push( {
|
|
2201
|
+
'File Date': element.fileDate,
|
|
2202
|
+
'Store ID': element.storeId,
|
|
2203
|
+
'Store Name': element.storeName,
|
|
2204
|
+
'Client Id': element.clientId,
|
|
2205
|
+
'Client Name': element.clientName,
|
|
2206
|
+
'User Name': element.userName,
|
|
2207
|
+
'User Email': element.userEmail,
|
|
2208
|
+
'Audit Type': element.auditType,
|
|
2209
|
+
'Accuracy': element.accuracy,
|
|
2210
|
+
'Time Spent': element.timeSpent,
|
|
2211
|
+
'Status': element.status,
|
|
2212
|
+
} );
|
|
2213
|
+
}
|
|
2173
2214
|
} );
|
|
2174
2215
|
await download( exportdata, res );
|
|
2175
2216
|
return;
|
|
@@ -2595,18 +2636,32 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
2595
2636
|
if ( inputData.isExport ) {
|
|
2596
2637
|
const exportdata = [];
|
|
2597
2638
|
result.forEach( ( element ) => {
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2639
|
+
if ( element.moduleType == 'zone' ) {
|
|
2640
|
+
exportdata.push( {
|
|
2641
|
+
'Store ID': element.storeId,
|
|
2642
|
+
'zoneName': element.zoneName,
|
|
2643
|
+
'File Date': element.fileDate,
|
|
2644
|
+
'Product Type': element.moduleType,
|
|
2645
|
+
'Audit Type': element.auditType,
|
|
2646
|
+
'Before Count': element.beforeCount,
|
|
2647
|
+
'Start Time': element.startTime,
|
|
2648
|
+
'User Name': element.userName,
|
|
2649
|
+
'User Email': element.userEmail,
|
|
2650
|
+
'Status': element.auditStatus,
|
|
2651
|
+
} );
|
|
2652
|
+
} else {
|
|
2653
|
+
exportdata.push( {
|
|
2654
|
+
'Store ID': element.storeId,
|
|
2655
|
+
'File Date': element.fileDate,
|
|
2656
|
+
'Product Type': element.moduleType,
|
|
2657
|
+
'Audit Type': element.auditType,
|
|
2658
|
+
'Before Count': element.beforeCount,
|
|
2659
|
+
'Start Time': element.startTime,
|
|
2660
|
+
'User Name': element.userName,
|
|
2661
|
+
'User Email': element.userEmail,
|
|
2662
|
+
'Status': element.auditStatus,
|
|
2663
|
+
} );
|
|
2664
|
+
}
|
|
2610
2665
|
} );
|
|
2611
2666
|
await download( exportdata, res );
|
|
2612
2667
|
return;
|
|
@@ -2625,7 +2680,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2625
2680
|
let temp = {
|
|
2626
2681
|
installedStores: 0,
|
|
2627
2682
|
auditStores: 0,
|
|
2628
|
-
|
|
2683
|
+
inprogressStores: 0,
|
|
2629
2684
|
completedStores: 0,
|
|
2630
2685
|
auditInprogress: 0,
|
|
2631
2686
|
reAuditInprogress: 0,
|
|
@@ -2722,7 +2777,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2722
2777
|
];
|
|
2723
2778
|
const storeAudit = await aggregateStoreAudit( storeAuditQuery );
|
|
2724
2779
|
if ( storeAudit.length > 0 ) {
|
|
2725
|
-
temp.
|
|
2780
|
+
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
2726
2781
|
temp.completedStores = storeAudit[0].completedStores;
|
|
2727
2782
|
temp.auditInprogress = storeAudit[0].auditInprogress;
|
|
2728
2783
|
temp.reAuditInprogress = storeAudit[0].reAuditInprogress;
|
|
@@ -2881,7 +2936,7 @@ export async function reTrigger( req, res ) {
|
|
|
2881
2936
|
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
2882
2937
|
}
|
|
2883
2938
|
|
|
2884
|
-
return res.sendSuccess( { result: 'The File has been Re
|
|
2939
|
+
return res.sendSuccess( { result: 'The File has been Re-Trigger Succesfully' } );
|
|
2885
2940
|
} catch ( error ) {
|
|
2886
2941
|
const err = error.message;
|
|
2887
2942
|
logger.error( { error: error, message: req.body, function: 'reTrigger' } );
|
|
@@ -3237,19 +3292,34 @@ export async function overviewTable( req, res ) {
|
|
|
3237
3292
|
if ( inputData.isExport ) {
|
|
3238
3293
|
const exportdata = [];
|
|
3239
3294
|
result.forEach( ( element ) => {
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3295
|
+
if ( element.moduleType == 'zone' ) {
|
|
3296
|
+
exportdata.push( {
|
|
3297
|
+
'Store ID': element.storeId,
|
|
3298
|
+
'Brand ID': element.clientId,
|
|
3299
|
+
'Zone Name': element.zoneName,
|
|
3300
|
+
'File Date': element.fileDate,
|
|
3301
|
+
'Product Type': element.moduleType,
|
|
3302
|
+
'Audit Type': element.auditType,
|
|
3303
|
+
'Before Count': element.beforeCount,
|
|
3304
|
+
'After Count': element.afterCount,
|
|
3305
|
+
// 'User Name': element.userName,
|
|
3306
|
+
// 'User Email': element.userEmail,
|
|
3307
|
+
'Status': element.status,
|
|
3308
|
+
} );
|
|
3309
|
+
} else {
|
|
3310
|
+
exportdata.push( {
|
|
3311
|
+
'Store ID': element.storeId,
|
|
3312
|
+
'Brand ID': element.clientId,
|
|
3313
|
+
'File Date': element.fileDate,
|
|
3314
|
+
'Product Type': element.moduleType,
|
|
3315
|
+
'Audit Type': element.auditType,
|
|
3316
|
+
'Before Count': element.beforeCount,
|
|
3317
|
+
'After Count': element.afterCount,
|
|
3318
|
+
// 'User Name': element.userName,
|
|
3319
|
+
// 'User Email': element.userEmail,
|
|
3320
|
+
'Status': element.status,
|
|
3321
|
+
} );
|
|
3322
|
+
}
|
|
3253
3323
|
} );
|
|
3254
3324
|
await download( exportdata, res );
|
|
3255
3325
|
return;
|
|
@@ -3275,7 +3345,7 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3275
3345
|
{ createdAt: -1 },
|
|
3276
3346
|
);
|
|
3277
3347
|
const latestDate = getStoreData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
3278
|
-
const query =[
|
|
3348
|
+
const query = [
|
|
3279
3349
|
{
|
|
3280
3350
|
$match: {
|
|
3281
3351
|
fileDate: { $eq: latestDate },
|
|
@@ -3364,7 +3434,7 @@ export async function totalNotAssignedCount( req, res ) {
|
|
|
3364
3434
|
} else {
|
|
3365
3435
|
notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount;
|
|
3366
3436
|
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount;
|
|
3367
|
-
notAssignedCount.totalTrafficCount;
|
|
3437
|
+
notAssignedCount.totalTrafficCount= getTotalcount[0].totalTrafficCount;
|
|
3368
3438
|
}
|
|
3369
3439
|
return res.sendSuccess( { result: notAssignedCount } );
|
|
3370
3440
|
} catch ( error ) {
|