tango-app-api-audit 3.3.0-alpha.2 → 3.3.0-alpha.21
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 +487 -88
- package/src/docs/audit.docs.js +64 -46
- package/src/dtos/audit.dtos.js +28 -4
- package/src/routes/audit.routes.js +8 -8
- package/src/service/auditStoreData.service.js +1 -1
- package/src/validation/audit.validation.js +9 -8
- package/src/controllers/auditMetrics.controllers.js +0 -71
- package/src/controllers/zoneAudit.controller.js +0 -1827
- package/src/docs/auditMetrics.docs.js +0 -70
- package/src/docs/zoneAudit.docs.js +0 -268
- package/src/dtos/auditMetrics.dtos.js +0 -39
- package/src/dtos/zoneAudit.dtos.js +0 -171
- package/src/routes/auditMetrics.routes.js +0 -14
- package/src/routes/zone.routes.js +0 -24
- package/src/validation/zoneAudit.validation.js +0 -167
|
@@ -42,16 +42,19 @@ import {
|
|
|
42
42
|
} from '../service/auditLog.service.js';
|
|
43
43
|
import { aggregateStore, countDocumentsStore, findOneStore } from '../service/store.service.js';
|
|
44
44
|
import {
|
|
45
|
+
getAuditFilterData,
|
|
46
|
+
getAuditImageData,
|
|
45
47
|
mapCustomer,
|
|
46
48
|
mapEmployee,
|
|
47
49
|
mapJunk,
|
|
48
50
|
splitB20000,
|
|
49
51
|
splitE0,
|
|
50
52
|
splitG20000,
|
|
53
|
+
zipDownloadImage,
|
|
51
54
|
} from '../validation/audit.validation.js';
|
|
52
55
|
import mongoose from 'mongoose';
|
|
53
56
|
import {
|
|
54
|
-
|
|
57
|
+
aggregateAuditStoreData,
|
|
55
58
|
findOneStoreData,
|
|
56
59
|
} from '../service/auditStoreData.service.js';
|
|
57
60
|
|
|
@@ -334,7 +337,7 @@ export async function getAuditFile( req, res ) {
|
|
|
334
337
|
logType: 'audit',
|
|
335
338
|
logSubType: 'auditStart',
|
|
336
339
|
logData: {
|
|
337
|
-
|
|
340
|
+
fileDate: userDetails[0].fileDate,
|
|
338
341
|
auditType: userDetails[0].auditType,
|
|
339
342
|
storeId: userDetails[0].storeId,
|
|
340
343
|
clientName: log.queueName,
|
|
@@ -342,9 +345,10 @@ export async function getAuditFile( req, res ) {
|
|
|
342
345
|
moduleType: userDetails[0].moduleType,
|
|
343
346
|
zoneName: userDetails[0].zoneName,
|
|
344
347
|
},
|
|
348
|
+
createdAt: new Date(),
|
|
345
349
|
};
|
|
346
350
|
logger.info( { logData: logData } );
|
|
347
|
-
await insertOpenSearchData( openSearch.
|
|
351
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
348
352
|
}
|
|
349
353
|
const storeQuery = {
|
|
350
354
|
storeId: userDetails[0].storeId,
|
|
@@ -443,8 +447,9 @@ export async function getAuditFile( req, res ) {
|
|
|
443
447
|
zoneName: msg.zone_id,
|
|
444
448
|
moduleType: inputData.moduleType,
|
|
445
449
|
},
|
|
450
|
+
createdAt: new Date(),
|
|
446
451
|
};
|
|
447
|
-
await insertOpenSearchData( openSearch.
|
|
452
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
448
453
|
}
|
|
449
454
|
|
|
450
455
|
const storeQuery = {
|
|
@@ -491,7 +496,6 @@ export async function getAuditFile( req, res ) {
|
|
|
491
496
|
const list = await listFileByPath( fetchData );
|
|
492
497
|
const folderPath = list.data;
|
|
493
498
|
const nextQuery = list.pageToken;
|
|
494
|
-
logger.info( { nextQuery: folderPath } );
|
|
495
499
|
if ( folderPath?.length > 0 ) {
|
|
496
500
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
497
501
|
const img = folderPath[i].Key.split( '/' );
|
|
@@ -595,8 +599,9 @@ export async function getAuditFile( req, res ) {
|
|
|
595
599
|
zoneName: msg.zone_id,
|
|
596
600
|
moduleType: inputData.moduleType,
|
|
597
601
|
},
|
|
602
|
+
createdAt: new Date(),
|
|
598
603
|
};
|
|
599
|
-
await insertOpenSearchData( openSearch.
|
|
604
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
600
605
|
}
|
|
601
606
|
logger.info( { storeInfo: storeInfo } );
|
|
602
607
|
return res.sendSuccess( {
|
|
@@ -711,8 +716,6 @@ export async function getAuditImage( msg ) {
|
|
|
711
716
|
|
|
712
717
|
export const getReauditImg = async ( filter, image ) => {
|
|
713
718
|
const chunkedMappingData = await chunkArray( image, 10 );
|
|
714
|
-
logger.info( { chunkedMappingData: chunkedMappingData, level: 5 } );
|
|
715
|
-
|
|
716
719
|
const promises = chunkedMappingData.map( async ( chunk ) => {
|
|
717
720
|
return mapFunction( chunk, filter );
|
|
718
721
|
} );
|
|
@@ -734,27 +737,35 @@ export const mapFunction = async ( chunk, filter ) => {
|
|
|
734
737
|
|
|
735
738
|
export async function workSpace( req, res ) {
|
|
736
739
|
try {
|
|
737
|
-
const inputData = req.
|
|
740
|
+
const inputData = req.body;
|
|
738
741
|
const limit = inputData.limit || 10;
|
|
739
742
|
const offset = inputData.offset ?
|
|
740
743
|
( inputData.offset - 1 ) * limit :
|
|
741
744
|
0;
|
|
742
745
|
const dateRange = await getUTC( new Date(), new Date() );
|
|
743
|
-
|
|
746
|
+
const filter =[
|
|
747
|
+
{ status: { $in: [ 'active', 'hold' ] } },
|
|
748
|
+
{ 'auditConfigs.audit': { $eq: true } },
|
|
749
|
+
];
|
|
750
|
+
if ( inputData?.clientId?.length > 0 ) {
|
|
751
|
+
filter.push( { clientId: { $in: inputData.clientId } } );
|
|
752
|
+
}
|
|
744
753
|
const temp = [];
|
|
745
754
|
const clientQuery = [
|
|
746
755
|
{
|
|
747
756
|
$match: {
|
|
748
|
-
$and:
|
|
749
|
-
{ status: { $in: [ 'active', 'hold' ] } },
|
|
750
|
-
{ 'auditConfigs.audit': { $eq: true } },
|
|
751
|
-
],
|
|
757
|
+
$and: filter,
|
|
752
758
|
},
|
|
753
759
|
},
|
|
754
760
|
{
|
|
755
761
|
$project: {
|
|
756
762
|
clientName: 1,
|
|
757
763
|
clientId: 1,
|
|
764
|
+
queueName: {
|
|
765
|
+
$cond: [
|
|
766
|
+
{ $eq: [ inputData.moduleType, 'zone' ] }, '$auditConfigs.zoneQueueName', '$auditConfigs.trafficQueueName',
|
|
767
|
+
],
|
|
768
|
+
},
|
|
758
769
|
},
|
|
759
770
|
},
|
|
760
771
|
];
|
|
@@ -772,9 +783,9 @@ export async function workSpace( req, res ) {
|
|
|
772
783
|
}
|
|
773
784
|
if ( inputData.sortColumnName ) {
|
|
774
785
|
const sortBy = inputData.sortBy || -1;
|
|
775
|
-
|
|
786
|
+
const sortColumn = inputData.sortColumnName;
|
|
776
787
|
clientQuery.push( {
|
|
777
|
-
$sort: { [
|
|
788
|
+
$sort: { [sortColumn]: sortBy },
|
|
778
789
|
},
|
|
779
790
|
);
|
|
780
791
|
}
|
|
@@ -811,7 +822,7 @@ export async function workSpace( req, res ) {
|
|
|
811
822
|
clientId: { $last: '$clientId' },
|
|
812
823
|
clientName: { $last: '$clientName' },
|
|
813
824
|
installedStore: { $last: '$installedStore' },
|
|
814
|
-
queueName: { $last: '$queueName' },
|
|
825
|
+
// queueName: { $last: '$queueName' },
|
|
815
826
|
totalCount: { $sum: 1 },
|
|
816
827
|
},
|
|
817
828
|
},
|
|
@@ -1008,7 +1019,7 @@ export async function workSpace( req, res ) {
|
|
|
1008
1019
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
1009
1020
|
const completedStoresCount = await aggregateStoreAudit( completedStores );
|
|
1010
1021
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
1011
|
-
const auditStoreData = await
|
|
1022
|
+
const auditStoreData = await aggregateAuditStoreData(
|
|
1012
1023
|
auditStoreDataQuery,
|
|
1013
1024
|
);
|
|
1014
1025
|
|
|
@@ -1157,6 +1168,7 @@ export async function saveDraft( req, res ) {
|
|
|
1157
1168
|
logType: 'audit',
|
|
1158
1169
|
logSubType: 'auditDraft',
|
|
1159
1170
|
logData: {
|
|
1171
|
+
fileDate: inputData.fileDate,
|
|
1160
1172
|
auditType: inputData.auditType,
|
|
1161
1173
|
storeId: inputData.storeId,
|
|
1162
1174
|
clientName: inputData.queueName,
|
|
@@ -1166,8 +1178,9 @@ export async function saveDraft( req, res ) {
|
|
|
1166
1178
|
moduleType: inputData.moduleType,
|
|
1167
1179
|
zoneName: inputData.zoneName,
|
|
1168
1180
|
},
|
|
1181
|
+
createdAt: new Date(),
|
|
1169
1182
|
};
|
|
1170
|
-
await insertOpenSearchData( openSearch.
|
|
1183
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
1171
1184
|
}
|
|
1172
1185
|
await createAuditLog( inputData );
|
|
1173
1186
|
await updateOneUserAudit( userQuery, userRecord );
|
|
@@ -1195,8 +1208,8 @@ export async function getDraftedData( req, res ) {
|
|
|
1195
1208
|
};
|
|
1196
1209
|
const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
|
|
1197
1210
|
|
|
1198
|
-
if ( result
|
|
1199
|
-
return res.sendError( 'No Data Found',
|
|
1211
|
+
if ( !result ) {
|
|
1212
|
+
return res.sendError( 'No Data Found', 204 );
|
|
1200
1213
|
}
|
|
1201
1214
|
return res.sendSuccess( { result: result } );
|
|
1202
1215
|
} catch ( error ) {
|
|
@@ -1469,7 +1482,9 @@ export async function userAuditHistory( req, res ) {
|
|
|
1469
1482
|
auditStatus: { $in: inputData.filterByStatus },
|
|
1470
1483
|
} );
|
|
1471
1484
|
}
|
|
1472
|
-
|
|
1485
|
+
if ( inputData?.clientId?.length > 0 ) {
|
|
1486
|
+
filter.push( { clientId: { $in: inputData.clientId } } );
|
|
1487
|
+
}
|
|
1473
1488
|
const query = [
|
|
1474
1489
|
{
|
|
1475
1490
|
$match: {
|
|
@@ -1614,9 +1629,10 @@ export async function userAuditHistory( req, res ) {
|
|
|
1614
1629
|
}
|
|
1615
1630
|
|
|
1616
1631
|
if ( inputData.sortColumnName ) {
|
|
1617
|
-
const sortBy =inputData.sortBy || -1;
|
|
1632
|
+
const sortBy = inputData.sortBy || -1;
|
|
1633
|
+
const sortColumn = inputData.sortColumnName;
|
|
1618
1634
|
query.push( {
|
|
1619
|
-
$sort: { [
|
|
1635
|
+
$sort: { [sortColumn]: sortBy },
|
|
1620
1636
|
},
|
|
1621
1637
|
);
|
|
1622
1638
|
}
|
|
@@ -1632,18 +1648,18 @@ export async function userAuditHistory( req, res ) {
|
|
|
1632
1648
|
chunk.forEach( ( element ) => {
|
|
1633
1649
|
exportData.push( {
|
|
1634
1650
|
|
|
1635
|
-
'
|
|
1636
|
-
'
|
|
1637
|
-
'Store
|
|
1651
|
+
'Brand ID': element.clientId,
|
|
1652
|
+
'Brand Name': element.clientName,
|
|
1653
|
+
'Store ID': element.storeId,
|
|
1638
1654
|
'Store Name': element.storeName,
|
|
1639
1655
|
'Zone Name': element.zoneName,
|
|
1640
1656
|
'Audit Type': element.auditType,
|
|
1641
1657
|
'Module Type': element.moduleType,
|
|
1642
1658
|
'Before Count': element.beforeCount,
|
|
1643
|
-
'After Count': element.afterCount,
|
|
1644
|
-
'Accuracy': element.accuracy,
|
|
1659
|
+
'After Count': element.afterCount || '',
|
|
1660
|
+
'Accuracy': element.accuracy || '',
|
|
1645
1661
|
'Start Time': element.startTime,
|
|
1646
|
-
'End Time': element.endTime,
|
|
1662
|
+
'End Time': element.endTime || '',
|
|
1647
1663
|
'Time Spent': element.timeSpent,
|
|
1648
1664
|
'Audit Status': element.auditStatus,
|
|
1649
1665
|
'CreatedAt': dayjs( element.createdAt ).format( 'YYYY,MMM D' ),
|
|
@@ -1654,8 +1670,8 @@ export async function userAuditHistory( req, res ) {
|
|
|
1654
1670
|
} );
|
|
1655
1671
|
const mappedArrays = await Promise.all( promises );
|
|
1656
1672
|
mappedArrays.flat();
|
|
1657
|
-
|
|
1658
|
-
await download( mappedArrays, res );
|
|
1673
|
+
logger.info( { mappedArrays: mappedArrays[0] } );
|
|
1674
|
+
await download( mappedArrays[0], res );
|
|
1659
1675
|
return;
|
|
1660
1676
|
}
|
|
1661
1677
|
|
|
@@ -1845,13 +1861,14 @@ export async function clientMetrics( req, res ) {
|
|
|
1845
1861
|
}
|
|
1846
1862
|
if ( inputData.sortColumnName ) {
|
|
1847
1863
|
const sortBy = inputData.sortBy || -1;
|
|
1864
|
+
const sortColumn = inputData.sortColumnName;
|
|
1848
1865
|
query.push( {
|
|
1849
|
-
$sort: { [
|
|
1866
|
+
$sort: { [sortColumn]: sortBy },
|
|
1850
1867
|
},
|
|
1851
1868
|
);
|
|
1852
1869
|
}
|
|
1853
1870
|
|
|
1854
|
-
const count = await
|
|
1871
|
+
const count = await aggregateAuditStoreData( query );
|
|
1855
1872
|
if ( count.length == 0 ) {
|
|
1856
1873
|
return res.sendError( 'No Data Found', 204 );
|
|
1857
1874
|
}
|
|
@@ -1883,7 +1900,7 @@ export async function clientMetrics( req, res ) {
|
|
|
1883
1900
|
}
|
|
1884
1901
|
|
|
1885
1902
|
logger.info( { query: query } );
|
|
1886
|
-
const result = await
|
|
1903
|
+
const result = await aggregateAuditStoreData( query );
|
|
1887
1904
|
if ( result.length == 0 ) {
|
|
1888
1905
|
return res.sendError( 'No Data Found', 204 );
|
|
1889
1906
|
}
|
|
@@ -1970,7 +1987,7 @@ export async function storeMetrics( req, res ) {
|
|
|
1970
1987
|
_id: 0,
|
|
1971
1988
|
fileDate: 1,
|
|
1972
1989
|
storeId: 1,
|
|
1973
|
-
storeName: '$
|
|
1990
|
+
storeName: '$stores.storeName',
|
|
1974
1991
|
clientName: '',
|
|
1975
1992
|
clientId: 1,
|
|
1976
1993
|
zoneName: 1,
|
|
@@ -1981,13 +1998,12 @@ export async function storeMetrics( req, res ) {
|
|
|
1981
1998
|
auditType: 1,
|
|
1982
1999
|
beforeCount: 1,
|
|
1983
2000
|
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
1984
|
-
accuracy: { $round: [
|
|
1985
|
-
{
|
|
1986
|
-
|
|
1987
|
-
|
|
2001
|
+
accuracy: { $cond: [ { $eq: [ '$status', 'completed' ] }, { $round: [
|
|
2002
|
+
{
|
|
2003
|
+
$multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
|
|
2004
|
+
}, 1,
|
|
1988
2005
|
],
|
|
1989
|
-
|
|
1990
|
-
},
|
|
2006
|
+
}, null ] },
|
|
1991
2007
|
timeSpent: 1,
|
|
1992
2008
|
status: 1,
|
|
1993
2009
|
},
|
|
@@ -2052,7 +2068,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2052
2068
|
_id: 0,
|
|
2053
2069
|
fileDate: 1,
|
|
2054
2070
|
storeId: 1,
|
|
2055
|
-
storeName:
|
|
2071
|
+
storeName: 1,
|
|
2056
2072
|
userName: '$users.userName',
|
|
2057
2073
|
userEmail: '$users.userEmail',
|
|
2058
2074
|
clientId: 1,
|
|
@@ -2062,13 +2078,12 @@ export async function storeMetrics( req, res ) {
|
|
|
2062
2078
|
auditType: 1,
|
|
2063
2079
|
beforeCount: 1,
|
|
2064
2080
|
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
2065
|
-
accuracy: { $round: [
|
|
2066
|
-
{
|
|
2067
|
-
|
|
2068
|
-
|
|
2081
|
+
accuracy: { $cond: [ { $eq: [ '$status', 'completed' ] }, { $round: [
|
|
2082
|
+
{
|
|
2083
|
+
$multiply: [ { $divide: [ '$afterCount', '$beforeCount' ] }, 100 ],
|
|
2084
|
+
}, 1,
|
|
2069
2085
|
],
|
|
2070
|
-
|
|
2071
|
-
},
|
|
2086
|
+
}, null ] },
|
|
2072
2087
|
timeSpent: {
|
|
2073
2088
|
|
|
2074
2089
|
$cond: [
|
|
@@ -2119,8 +2134,9 @@ export async function storeMetrics( req, res ) {
|
|
|
2119
2134
|
|
|
2120
2135
|
if ( inputData.sortColumnName ) {
|
|
2121
2136
|
const sortBy = inputData.sortBy || -1;
|
|
2137
|
+
const sortColumn = inputData.sortColumnName;
|
|
2122
2138
|
query.push( {
|
|
2123
|
-
$sort: { [
|
|
2139
|
+
$sort: { [sortColumn]: sortBy },
|
|
2124
2140
|
},
|
|
2125
2141
|
);
|
|
2126
2142
|
}
|
|
@@ -2145,7 +2161,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2145
2161
|
result.forEach( ( element ) => {
|
|
2146
2162
|
exportdata.push( {
|
|
2147
2163
|
'File Date': element.fileDate,
|
|
2148
|
-
'Store
|
|
2164
|
+
'Store ID': element.storeId,
|
|
2149
2165
|
'Store Name': element.storeName,
|
|
2150
2166
|
'Client Id': element.clientId,
|
|
2151
2167
|
'Client Name': element.clientName,
|
|
@@ -2281,6 +2297,7 @@ export async function userMetrics( req, res ) {
|
|
|
2281
2297
|
afterCount: 1,
|
|
2282
2298
|
checkIntime: 1,
|
|
2283
2299
|
checkOutTime: 1,
|
|
2300
|
+
mappingPerc: 1,
|
|
2284
2301
|
hours: {
|
|
2285
2302
|
$cond: {
|
|
2286
2303
|
if: { $lt: [ '$hours', 10 ] },
|
|
@@ -2316,6 +2333,7 @@ export async function userMetrics( req, res ) {
|
|
|
2316
2333
|
checkIntime: 1,
|
|
2317
2334
|
zoneName: 1,
|
|
2318
2335
|
checkOutTime: 1,
|
|
2336
|
+
mappingPerc: 1,
|
|
2319
2337
|
workingHours: {
|
|
2320
2338
|
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
2321
2339
|
},
|
|
@@ -2356,6 +2374,7 @@ export async function userMetrics( req, res ) {
|
|
|
2356
2374
|
totalCompletedFiles: 1,
|
|
2357
2375
|
beforeCount: 1,
|
|
2358
2376
|
afterCount: 1,
|
|
2377
|
+
mappingPerc: 1,
|
|
2359
2378
|
checkIntime: {
|
|
2360
2379
|
$dateToString: {
|
|
2361
2380
|
format: '%Y-%m-%d %H:%M:%S',
|
|
@@ -2387,8 +2406,9 @@ export async function userMetrics( req, res ) {
|
|
|
2387
2406
|
}
|
|
2388
2407
|
if ( inputData.sortColumnName ) {
|
|
2389
2408
|
const sortBy = inputData.sortBy || -1;
|
|
2409
|
+
const sortColumn = inputData.sortColumnName;
|
|
2390
2410
|
query.push( {
|
|
2391
|
-
$sort: { [
|
|
2411
|
+
$sort: { [sortColumn]: sortBy },
|
|
2392
2412
|
},
|
|
2393
2413
|
);
|
|
2394
2414
|
}
|
|
@@ -2409,13 +2429,13 @@ export async function userMetrics( req, res ) {
|
|
|
2409
2429
|
'_id': 0,
|
|
2410
2430
|
'File Date': '$fileDate',
|
|
2411
2431
|
'User Name': '$userName',
|
|
2412
|
-
'User Id': '$userId',
|
|
2413
2432
|
'Total Completed Files Count': '$totalCompletedFiles',
|
|
2414
|
-
'Total
|
|
2433
|
+
'Total Before Count': '$beforeCount',
|
|
2415
2434
|
'Total After Count': '$afterCount',
|
|
2416
2435
|
'check Intime': '$checkIntime',
|
|
2417
2436
|
'check OutTime': '$checkOutTime',
|
|
2418
2437
|
'working Hours': '$workingHours',
|
|
2438
|
+
'Mapping Percentage': '$mappingPerc',
|
|
2419
2439
|
},
|
|
2420
2440
|
},
|
|
2421
2441
|
);
|
|
@@ -2430,12 +2450,12 @@ export async function userMetrics( req, res ) {
|
|
|
2430
2450
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
2431
2451
|
} catch ( error ) {
|
|
2432
2452
|
const err = error.error || 'Internal Server Error';
|
|
2433
|
-
logger.info( { error: error, message: req.body, function: '
|
|
2453
|
+
logger.info( { error: error, message: req.body, function: 'userMetrics' } );
|
|
2434
2454
|
return res.sendError( err, 500 );
|
|
2435
2455
|
}
|
|
2436
2456
|
}
|
|
2437
2457
|
|
|
2438
|
-
export async function
|
|
2458
|
+
export async function pendingSummaryTable( req, res ) {
|
|
2439
2459
|
try {
|
|
2440
2460
|
const inputData = req.body;
|
|
2441
2461
|
const limit = inputData.limit || 10;
|
|
@@ -2444,7 +2464,7 @@ export async function overViewTable( req, res ) {
|
|
|
2444
2464
|
let filters =[
|
|
2445
2465
|
{ fileDateISO: { $gte: dateRange.start } },
|
|
2446
2466
|
{ fileDateISO: { $lte: dateRange.end } },
|
|
2447
|
-
{ auditStatus: { $
|
|
2467
|
+
{ auditStatus: { $ne: 'completed' } },
|
|
2448
2468
|
|
|
2449
2469
|
];
|
|
2450
2470
|
|
|
@@ -2459,6 +2479,10 @@ export async function overViewTable( req, res ) {
|
|
|
2459
2479
|
if ( inputData.filterByAuditType.length > 0 ) {
|
|
2460
2480
|
filters.push( { auditType: { $in: inputData.filterByAuditType } } );
|
|
2461
2481
|
}
|
|
2482
|
+
|
|
2483
|
+
if ( inputData.filterByStatus.length > 0 ) {
|
|
2484
|
+
filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
2485
|
+
}
|
|
2462
2486
|
const query =[
|
|
2463
2487
|
{
|
|
2464
2488
|
$match: {
|
|
@@ -2474,7 +2498,13 @@ export async function overViewTable( req, res ) {
|
|
|
2474
2498
|
fileDate: 1,
|
|
2475
2499
|
moduleType: 1,
|
|
2476
2500
|
beforeCount: 1,
|
|
2477
|
-
startTime:
|
|
2501
|
+
startTime: { $dateToString: {
|
|
2502
|
+
format: '%Y-%m-%d %H:%M:%S',
|
|
2503
|
+
date: '$startTime',
|
|
2504
|
+
timezone: 'Asia/Kolkata',
|
|
2505
|
+
},
|
|
2506
|
+
|
|
2507
|
+
},
|
|
2478
2508
|
auditType: 1,
|
|
2479
2509
|
auditStatus: 1,
|
|
2480
2510
|
userId: 1,
|
|
@@ -2515,6 +2545,7 @@ export async function overViewTable( req, res ) {
|
|
|
2515
2545
|
moduleType: 1,
|
|
2516
2546
|
beforeCount: 1,
|
|
2517
2547
|
startTime: 1,
|
|
2548
|
+
endTime: 1,
|
|
2518
2549
|
auditType: 1,
|
|
2519
2550
|
auditStatus: 1,
|
|
2520
2551
|
userName: '$user.userName',
|
|
@@ -2540,8 +2571,9 @@ export async function overViewTable( req, res ) {
|
|
|
2540
2571
|
}
|
|
2541
2572
|
if ( inputData.sortColumnName ) {
|
|
2542
2573
|
const sortBy = inputData.sortBy || -1;
|
|
2574
|
+
const sortColumn = inputData.sortColumnName;
|
|
2543
2575
|
query.push( {
|
|
2544
|
-
$sort: { [
|
|
2576
|
+
$sort: { [sortColumn]: sortBy },
|
|
2545
2577
|
},
|
|
2546
2578
|
);
|
|
2547
2579
|
}
|
|
@@ -2566,7 +2598,7 @@ export async function overViewTable( req, res ) {
|
|
|
2566
2598
|
const exportdata = [];
|
|
2567
2599
|
result.forEach( ( element ) => {
|
|
2568
2600
|
exportdata.push( {
|
|
2569
|
-
'Store
|
|
2601
|
+
'Store ID': element.storeId,
|
|
2570
2602
|
'zoneName': element.zoneName,
|
|
2571
2603
|
'File Date': element.fileDate,
|
|
2572
2604
|
'Module Type': element.moduleType,
|
|
@@ -2584,7 +2616,7 @@ export async function overViewTable( req, res ) {
|
|
|
2584
2616
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
2585
2617
|
} catch ( error ) {
|
|
2586
2618
|
const err = error.message || 'Internal Server Error';
|
|
2587
|
-
logger.error( { error: error, message: req.body, function: '
|
|
2619
|
+
logger.error( { error: error, message: req.body, function: 'pendingSummaryTable' } );
|
|
2588
2620
|
return res.sendError( err, 500 );
|
|
2589
2621
|
}
|
|
2590
2622
|
}
|
|
@@ -2595,7 +2627,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2595
2627
|
let temp = {
|
|
2596
2628
|
installedStores: 0,
|
|
2597
2629
|
auditStores: 0,
|
|
2598
|
-
|
|
2630
|
+
inprogressStores: 0,
|
|
2599
2631
|
completedStores: 0,
|
|
2600
2632
|
auditInprogress: 0,
|
|
2601
2633
|
reAuditInprogress: 0,
|
|
@@ -2638,7 +2670,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2638
2670
|
},
|
|
2639
2671
|
},
|
|
2640
2672
|
];
|
|
2641
|
-
const auditClientData = await
|
|
2673
|
+
const auditClientData = await aggregateAuditStoreData( auditClientDataQuery );
|
|
2642
2674
|
if ( auditClientData.length >0 ) {
|
|
2643
2675
|
temp.auditStores = auditClientData[0].totalFilesCount;
|
|
2644
2676
|
}
|
|
@@ -2655,8 +2687,8 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2655
2687
|
auditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
|
|
2656
2688
|
reAuditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
|
|
2657
2689
|
draft: { $cond: [ { $eq: [ '$status', 'drafted' ] }, 1, 0 ] },
|
|
2658
|
-
assigned: { $cond: [ { $eq: [ '$status', '
|
|
2659
|
-
exceptNoAssigned: { $cond:
|
|
2690
|
+
assigned: { $cond: [ { $eq: [ '$status', 'assigned' ] }, 1, 0 ] },
|
|
2691
|
+
exceptNoAssigned: { $cond: { if: { $not: { $in: [ '$status', [ 'skipped', 'not_assign' ] ] } }, then: 1, else: 0 } },
|
|
2660
2692
|
auditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
|
|
2661
2693
|
reAuditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
|
|
2662
2694
|
|
|
@@ -2684,7 +2716,6 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2684
2716
|
reAuditInprogress: 1,
|
|
2685
2717
|
draft: 1,
|
|
2686
2718
|
assigned: 1,
|
|
2687
|
-
exceptNoAssigned1: 1,
|
|
2688
2719
|
exceptNoAssigned: { $subtract: [ temp.auditStores, '$exceptNoAssigned' ] },
|
|
2689
2720
|
auditCompleted: 1,
|
|
2690
2721
|
reAuditCompleted: 1,
|
|
@@ -2693,7 +2724,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2693
2724
|
];
|
|
2694
2725
|
const storeAudit = await aggregateStoreAudit( storeAuditQuery );
|
|
2695
2726
|
if ( storeAudit.length > 0 ) {
|
|
2696
|
-
temp.
|
|
2727
|
+
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
2697
2728
|
temp.completedStores = storeAudit[0].completedStores;
|
|
2698
2729
|
temp.auditInprogress = storeAudit[0].auditInprogress;
|
|
2699
2730
|
temp.reAuditInprogress = storeAudit[0].reAuditInprogress;
|
|
@@ -2707,7 +2738,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
2707
2738
|
return res.sendSuccess( { result: temp } );
|
|
2708
2739
|
} catch ( error ) {
|
|
2709
2740
|
const err = error.message || 'Internal Server Error';
|
|
2710
|
-
logger.error( { error: error, message: req.body, function: '
|
|
2741
|
+
logger.error( { error: error, message: req.body, function: 'overAllAuditSummary' } );
|
|
2711
2742
|
return res.sendError( err, 500 );
|
|
2712
2743
|
}
|
|
2713
2744
|
}
|
|
@@ -2786,8 +2817,9 @@ export async function reTrigger( req, res ) {
|
|
|
2786
2817
|
triggerId: req.user._id,
|
|
2787
2818
|
triggerType: inputData.triggerType,
|
|
2788
2819
|
},
|
|
2820
|
+
createdAt: new Date(),
|
|
2789
2821
|
};
|
|
2790
|
-
await insertOpenSearchData( openSearch.
|
|
2822
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
2791
2823
|
}
|
|
2792
2824
|
break;
|
|
2793
2825
|
case 'user':
|
|
@@ -2800,7 +2832,7 @@ export async function reTrigger( req, res ) {
|
|
|
2800
2832
|
moduleType: inputData.moduleType,
|
|
2801
2833
|
fileDateISO: dayjs( new Date( ( inputData.fileDate ).split( '-' ).reverse().join( '-' ) ) ).format(),
|
|
2802
2834
|
auditType: inputData.auditType,
|
|
2803
|
-
fileCount: inputData.
|
|
2835
|
+
fileCount: inputData.totalCount,
|
|
2804
2836
|
queueName: queueName,
|
|
2805
2837
|
userId: inputData.userId,
|
|
2806
2838
|
userName: assignUser.userName,
|
|
@@ -2846,14 +2878,15 @@ export async function reTrigger( req, res ) {
|
|
|
2846
2878
|
triggerId: req.user._id,
|
|
2847
2879
|
triggerType: inputData.triggerType,
|
|
2848
2880
|
},
|
|
2881
|
+
createdAt: new Date(),
|
|
2849
2882
|
};
|
|
2850
|
-
await insertOpenSearchData( openSearch.
|
|
2883
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
2851
2884
|
}
|
|
2852
2885
|
|
|
2853
2886
|
return res.sendSuccess( { result: 'The File has been Re Trigger Succesfully' } );
|
|
2854
2887
|
} catch ( error ) {
|
|
2855
2888
|
const err = error.message;
|
|
2856
|
-
logger.error( { error: error, message: req.body } );
|
|
2889
|
+
logger.error( { error: error, message: req.body, function: 'reTrigger' } );
|
|
2857
2890
|
return res.sendError( err, 500 );
|
|
2858
2891
|
}
|
|
2859
2892
|
}
|
|
@@ -2867,6 +2900,7 @@ export async function overViewCard( req, res ) {
|
|
|
2867
2900
|
ReAuditFileCount: 0,
|
|
2868
2901
|
inprogressCount: 0,
|
|
2869
2902
|
completedCount: 0,
|
|
2903
|
+
pendingCount: 0,
|
|
2870
2904
|
};
|
|
2871
2905
|
|
|
2872
2906
|
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
@@ -2927,6 +2961,7 @@ export async function overViewCard( req, res ) {
|
|
|
2927
2961
|
ReAuditFileCount: 1,
|
|
2928
2962
|
inprogressCount: 1,
|
|
2929
2963
|
completedCount: 1,
|
|
2964
|
+
notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
|
|
2930
2965
|
},
|
|
2931
2966
|
},
|
|
2932
2967
|
];
|
|
@@ -2944,14 +2979,13 @@ export async function summarySplit( req, res ) {
|
|
|
2944
2979
|
try {
|
|
2945
2980
|
const inputData = req.body;
|
|
2946
2981
|
const temp = {
|
|
2947
|
-
|
|
2982
|
+
total: 0,
|
|
2948
2983
|
auditInprogress: 0,
|
|
2949
2984
|
reAuditInprogress: 0,
|
|
2950
2985
|
draft: 0,
|
|
2951
2986
|
assigned: 0,
|
|
2952
2987
|
auditCompleted: 0,
|
|
2953
2988
|
reAuditCompleted: 0,
|
|
2954
|
-
completedCount: 0,
|
|
2955
2989
|
};
|
|
2956
2990
|
|
|
2957
2991
|
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
@@ -2962,6 +2996,9 @@ export async function summarySplit( req, res ) {
|
|
|
2962
2996
|
if ( inputData.clientId.length > 0 ) {
|
|
2963
2997
|
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
2964
2998
|
}
|
|
2999
|
+
if ( inputData?.moduleType?.length > 0 ) {
|
|
3000
|
+
filters.push( { moduleType: { $in: inputData.moduleType } } );
|
|
3001
|
+
}
|
|
2965
3002
|
const query =[
|
|
2966
3003
|
{
|
|
2967
3004
|
$match: {
|
|
@@ -2983,19 +3020,15 @@ export async function summarySplit( req, res ) {
|
|
|
2983
3020
|
},
|
|
2984
3021
|
draft: {
|
|
2985
3022
|
$cond: [
|
|
2986
|
-
{ $
|
|
3023
|
+
{ $eq: [ '$status', 'drafted' ] }, 1, 0,
|
|
2987
3024
|
],
|
|
2988
3025
|
},
|
|
2989
3026
|
assigned: {
|
|
2990
3027
|
$cond: [
|
|
2991
|
-
{ $
|
|
2992
|
-
],
|
|
2993
|
-
},
|
|
2994
|
-
completedCount: {
|
|
2995
|
-
$cond: [
|
|
2996
|
-
{ $eq: [ '$status', 'completed' ] }, 1, 0,
|
|
3028
|
+
{ $eq: [ '$status', 'assigned' ] }, 1, 0,
|
|
2997
3029
|
],
|
|
2998
3030
|
},
|
|
3031
|
+
|
|
2999
3032
|
reAuditCompleted: {
|
|
3000
3033
|
$cond: [
|
|
3001
3034
|
{ $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
|
|
@@ -3010,16 +3043,13 @@ export async function summarySplit( req, res ) {
|
|
|
3010
3043
|
},
|
|
3011
3044
|
{
|
|
3012
3045
|
$group: {
|
|
3013
|
-
_id:
|
|
3014
|
-
totalInprogress: { $sum: 1 },
|
|
3046
|
+
_id: null,
|
|
3015
3047
|
auditInprogress: { $sum: '$auditInprogress' },
|
|
3016
3048
|
reAuditInprogress: { $sum: '$reAuditInprogress' },
|
|
3017
3049
|
draft: { $sum: '$draft' },
|
|
3018
|
-
assigned: { $sum: 'assigned' },
|
|
3019
|
-
completedCount: { $sum: '$completedCount' },
|
|
3050
|
+
assigned: { $sum: '$assigned' },
|
|
3020
3051
|
reAuditCompleted: { $sum: '$reAuditCompleted' },
|
|
3021
3052
|
auditCompleted: { $sum: '$auditCompleted' },
|
|
3022
|
-
completedCount: { $sum: '$completedCount' },
|
|
3023
3053
|
|
|
3024
3054
|
},
|
|
3025
3055
|
},
|
|
@@ -3031,15 +3061,36 @@ export async function summarySplit( req, res ) {
|
|
|
3031
3061
|
reAuditInprogress: 1,
|
|
3032
3062
|
draft: 1,
|
|
3033
3063
|
assigned: 1,
|
|
3034
|
-
completedCount: 1,
|
|
3035
3064
|
reAuditCompleted: 1,
|
|
3036
3065
|
auditCompleted: 1,
|
|
3066
|
+
totalCount: { $ifNull: [ 0, 0 ] },
|
|
3037
3067
|
|
|
3038
3068
|
},
|
|
3039
3069
|
},
|
|
3040
3070
|
];
|
|
3071
|
+
const totalQuery = [
|
|
3072
|
+
{
|
|
3073
|
+
$match: {
|
|
3074
|
+
$and: filters,
|
|
3075
|
+
},
|
|
3076
|
+
|
|
3077
|
+
},
|
|
3078
|
+
{
|
|
3079
|
+
$group: {
|
|
3080
|
+
_id: null,
|
|
3081
|
+
total: { $sum: 1 },
|
|
3082
|
+
},
|
|
3083
|
+
},
|
|
3084
|
+
{
|
|
3085
|
+
$project: {
|
|
3086
|
+
_id: 0,
|
|
3087
|
+
total: 1,
|
|
3088
|
+
},
|
|
3089
|
+
},
|
|
3090
|
+
];
|
|
3041
3091
|
const result = await aggregateStoreAudit( query );
|
|
3042
|
-
|
|
3092
|
+
const totalCount = await aggregateAuditStoreData( totalQuery );
|
|
3093
|
+
result[0].totalCount = totalCount[0]?.total;
|
|
3043
3094
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
3044
3095
|
} catch ( error ) {
|
|
3045
3096
|
const err = error.message || 'Internal Server Error';
|
|
@@ -3047,3 +3098,351 @@ export async function summarySplit( req, res ) {
|
|
|
3047
3098
|
return res.sendError( err, 500 );
|
|
3048
3099
|
}
|
|
3049
3100
|
}
|
|
3101
|
+
|
|
3102
|
+
export async function overviewTable( req, res ) {
|
|
3103
|
+
try {
|
|
3104
|
+
const inputData = req.body;
|
|
3105
|
+
const limit = inputData.limit || 10;
|
|
3106
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
3107
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
3108
|
+
let filters =[
|
|
3109
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
3110
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
3111
|
+
|
|
3112
|
+
];
|
|
3113
|
+
|
|
3114
|
+
if ( inputData.clientId.length > 0 ) {
|
|
3115
|
+
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
if ( inputData.filterByModuleType.length > 0 ) {
|
|
3119
|
+
filters.push( { moduleType: { $in: inputData.filterByModuleType } } );
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
if ( inputData.filterByAuditType.length > 0 ) {
|
|
3123
|
+
filters.push( { auditType: { $in: inputData.filterByAuditType } } );
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
if ( inputData.filterByStatus.length > 0 ) {
|
|
3127
|
+
filters.push( { status: { $in: inputData.filterByStatus } } );
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
const query =[
|
|
3131
|
+
{
|
|
3132
|
+
$match: {
|
|
3133
|
+
$and: filters,
|
|
3134
|
+
},
|
|
3135
|
+
|
|
3136
|
+
},
|
|
3137
|
+
{
|
|
3138
|
+
$project: {
|
|
3139
|
+
_id: 0,
|
|
3140
|
+
storeId: 1,
|
|
3141
|
+
clientId: 1,
|
|
3142
|
+
zoneName: 1,
|
|
3143
|
+
fileDate: 1,
|
|
3144
|
+
moduleType: 1,
|
|
3145
|
+
beforeCount: 1,
|
|
3146
|
+
afterCount: 1,
|
|
3147
|
+
auditType: 1,
|
|
3148
|
+
status: 1,
|
|
3149
|
+
// userId: 1,
|
|
3150
|
+
},
|
|
3151
|
+
},
|
|
3152
|
+
// {
|
|
3153
|
+
// $lookup: {
|
|
3154
|
+
// from: 'users',
|
|
3155
|
+
// let: { userId: '$userId' },
|
|
3156
|
+
// pipeline: [
|
|
3157
|
+
// {
|
|
3158
|
+
// $match: {
|
|
3159
|
+
// $expr: {
|
|
3160
|
+
// $eq: [ '$_id', '$$userId' ],
|
|
3161
|
+
// },
|
|
3162
|
+
// },
|
|
3163
|
+
// },
|
|
3164
|
+
// {
|
|
3165
|
+
// $project: {
|
|
3166
|
+
// userName: 1,
|
|
3167
|
+
// userEmail: '$email',
|
|
3168
|
+
// },
|
|
3169
|
+
// },
|
|
3170
|
+
// ], as: 'user',
|
|
3171
|
+
// },
|
|
3172
|
+
// },
|
|
3173
|
+
// {
|
|
3174
|
+
// $unwind: {
|
|
3175
|
+
// path: '$user',
|
|
3176
|
+
// preserveNullAndEmptyArrays: true,
|
|
3177
|
+
// },
|
|
3178
|
+
// },
|
|
3179
|
+
{
|
|
3180
|
+
$project: {
|
|
3181
|
+
storeId: 1,
|
|
3182
|
+
clientId: 1,
|
|
3183
|
+
zoneName: 1,
|
|
3184
|
+
fileDate: 1,
|
|
3185
|
+
moduleType: 1,
|
|
3186
|
+
beforeCount: 1,
|
|
3187
|
+
afterCount: 1,
|
|
3188
|
+
auditType: 1,
|
|
3189
|
+
status: 1,
|
|
3190
|
+
// userName: '$user.userName',
|
|
3191
|
+
// userEmail: '$user.userEmail',
|
|
3192
|
+
|
|
3193
|
+
},
|
|
3194
|
+
},
|
|
3195
|
+
];
|
|
3196
|
+
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
3197
|
+
query.push( {
|
|
3198
|
+
$match: {
|
|
3199
|
+
$or: [
|
|
3200
|
+
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3201
|
+
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3202
|
+
{ fileDate: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3203
|
+
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3204
|
+
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3205
|
+
{ moduleType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3206
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3207
|
+
// { userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3208
|
+
// { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3209
|
+
],
|
|
3210
|
+
|
|
3211
|
+
},
|
|
3212
|
+
} );
|
|
3213
|
+
}
|
|
3214
|
+
if ( inputData.sortColumnName ) {
|
|
3215
|
+
const sortBy = inputData.sortBy || -1;
|
|
3216
|
+
const sortColumn = inputData.sortColumnName;
|
|
3217
|
+
query.push( {
|
|
3218
|
+
$sort: { [sortColumn]: sortBy },
|
|
3219
|
+
},
|
|
3220
|
+
);
|
|
3221
|
+
}
|
|
3222
|
+
const count = await aggregateStoreAudit( query );
|
|
3223
|
+
if ( count.length == 0 ) {
|
|
3224
|
+
return res.sendError( 'No Data Found', 204 );
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3227
|
+
if ( inputData.isExport ) {
|
|
3228
|
+
query.push( { $limit: 10000 } );
|
|
3229
|
+
} else {
|
|
3230
|
+
query.push( {
|
|
3231
|
+
$skip: offset,
|
|
3232
|
+
},
|
|
3233
|
+
{
|
|
3234
|
+
$limit: limit,
|
|
3235
|
+
} );
|
|
3236
|
+
}
|
|
3237
|
+
|
|
3238
|
+
const result = await aggregateStoreAudit( query );
|
|
3239
|
+
if ( inputData.isExport ) {
|
|
3240
|
+
const exportdata = [];
|
|
3241
|
+
result.forEach( ( element ) => {
|
|
3242
|
+
exportdata.push( {
|
|
3243
|
+
'Store ID': element.storeId,
|
|
3244
|
+
'Client ID': element.clientId,
|
|
3245
|
+
'zoneName': element.zoneName,
|
|
3246
|
+
'File Date': element.fileDate,
|
|
3247
|
+
'Module Type': element.moduleType,
|
|
3248
|
+
'Audit Type': element.auditType,
|
|
3249
|
+
'Before Count': element.beforeCount,
|
|
3250
|
+
'After Count': element.afterCount,
|
|
3251
|
+
// 'User Name': element.userName,
|
|
3252
|
+
// 'User Email': element.userEmail,
|
|
3253
|
+
'Status': element.status,
|
|
3254
|
+
} );
|
|
3255
|
+
} );
|
|
3256
|
+
await download( exportdata, res );
|
|
3257
|
+
return;
|
|
3258
|
+
}
|
|
3259
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
3260
|
+
} catch ( error ) {
|
|
3261
|
+
const err = error.message || 'Internal Server Error';
|
|
3262
|
+
logger.error( { error: error, message: req.body, function: 'overviewTable' } );
|
|
3263
|
+
return res.sendError( err, 500 );
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
|
|
3267
|
+
export async function totalNotAssignedCount( req, res ) {
|
|
3268
|
+
try {
|
|
3269
|
+
let notAssignedCount = {
|
|
3270
|
+
totalAuditCount: 0,
|
|
3271
|
+
totalZoneCount: 0,
|
|
3272
|
+
totalTrafficCount: 0,
|
|
3273
|
+
};
|
|
3274
|
+
const getStoreData = await findOneStoreData(
|
|
3275
|
+
{},
|
|
3276
|
+
{ fileDate: 1 },
|
|
3277
|
+
{ createdAt: -1 },
|
|
3278
|
+
);
|
|
3279
|
+
const latestDate = getStoreData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
3280
|
+
const query = [
|
|
3281
|
+
{
|
|
3282
|
+
$match: {
|
|
3283
|
+
fileDate: { $eq: latestDate },
|
|
3284
|
+
},
|
|
3285
|
+
},
|
|
3286
|
+
{
|
|
3287
|
+
$project: {
|
|
3288
|
+
totalZoneCount: { $cond: [
|
|
3289
|
+
{ $eq: [ '$moduleType', 'zone' ] }, 1, 0,
|
|
3290
|
+
] },
|
|
3291
|
+
totalTrafficCount: { $cond: [
|
|
3292
|
+
{ $eq: [ '$moduleType', 'traffic' ] }, 1, 0,
|
|
3293
|
+
] },
|
|
3294
|
+
|
|
3295
|
+
},
|
|
3296
|
+
},
|
|
3297
|
+
{
|
|
3298
|
+
$group: {
|
|
3299
|
+
_id: null,
|
|
3300
|
+
totalAuditCount: { $sum: 1 },
|
|
3301
|
+
totalZoneCount: { $sum: '$totalZoneCount' },
|
|
3302
|
+
totalTrafficCount: { $sum: '$totalTrafficCount' },
|
|
3303
|
+
|
|
3304
|
+
},
|
|
3305
|
+
},
|
|
3306
|
+
{
|
|
3307
|
+
$project: {
|
|
3308
|
+
_id: 0,
|
|
3309
|
+
totalAuditCount: 1,
|
|
3310
|
+
totalZoneCount: 1,
|
|
3311
|
+
totalTrafficCount: 1,
|
|
3312
|
+
},
|
|
3313
|
+
},
|
|
3314
|
+
];
|
|
3315
|
+
const inprogressCount=[
|
|
3316
|
+
{
|
|
3317
|
+
$match: {
|
|
3318
|
+
fileDate: { $eq: latestDate },
|
|
3319
|
+
},
|
|
3320
|
+
},
|
|
3321
|
+
{
|
|
3322
|
+
$project: {
|
|
3323
|
+
inprogressAuditCount: {
|
|
3324
|
+
$cond: [
|
|
3325
|
+
{ $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] }, 1, 0,
|
|
3326
|
+
],
|
|
3327
|
+
},
|
|
3328
|
+
inprogressZoneCount: { $cond: [
|
|
3329
|
+
{ $and: [ { $eq: [ '$moduleType', 'zone' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3330
|
+
] },
|
|
3331
|
+
inprogressTrafficCount: { $cond: [
|
|
3332
|
+
{ $and: [ { $eq: [ '$moduleType', 'traffic' ] }, { $in: [ '$status', [ 'completed', 'not_assign', 'skipped' ] ] } ] }, 1, 0,
|
|
3333
|
+
] },
|
|
3334
|
+
|
|
3335
|
+
},
|
|
3336
|
+
},
|
|
3337
|
+
{
|
|
3338
|
+
$group: {
|
|
3339
|
+
_id: null,
|
|
3340
|
+
inprogressAuditCount: { $sum: '$inprogressAuditCount' },
|
|
3341
|
+
inprogressZoneCount: { $sum: '$inprogressZoneCount' },
|
|
3342
|
+
inprogressTrafficCount: { $sum: '$inprogressTrafficCount' },
|
|
3343
|
+
|
|
3344
|
+
},
|
|
3345
|
+
},
|
|
3346
|
+
{
|
|
3347
|
+
$project: {
|
|
3348
|
+
_id: 0,
|
|
3349
|
+
inprogressAuditCount: { $ifNull: [ '$inprogressAuditCount', 0 ] },
|
|
3350
|
+
inprogressZoneCount: { $ifNull: [ '$inprogressZoneCount', 0 ] },
|
|
3351
|
+
inprogressTrafficCount: { $ifNull: [ '$inprogressTrafficCount', 0 ] },
|
|
3352
|
+
},
|
|
3353
|
+
},
|
|
3354
|
+
];
|
|
3355
|
+
const getTotalcount = await aggregateAuditStoreData( query );
|
|
3356
|
+
|
|
3357
|
+
const getInprogressCount = await aggregateStoreAudit( inprogressCount );
|
|
3358
|
+
if ( getTotalcount.length == 0 ) {
|
|
3359
|
+
return res.sendError( 'No Data Found', 204 );
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
if ( getInprogressCount.length >0 ) {
|
|
3363
|
+
notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount - getInprogressCount[0]?.inprogressAuditCount;
|
|
3364
|
+
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount - getInprogressCount[0]?.inprogressZoneCount;
|
|
3365
|
+
notAssignedCount.totalTrafficCount = getTotalcount[0].totalTrafficCount - getInprogressCount[0]?.inprogressTrafficCount;
|
|
3366
|
+
} else {
|
|
3367
|
+
notAssignedCount.totalAuditCount = getTotalcount[0].totalAuditCount;
|
|
3368
|
+
notAssignedCount.totalZoneCount = getTotalcount[0].totalZoneCount;
|
|
3369
|
+
notAssignedCount.totalTrafficCount= getTotalcount[0].totalTrafficCount;
|
|
3370
|
+
}
|
|
3371
|
+
return res.sendSuccess( { result: notAssignedCount } );
|
|
3372
|
+
} catch ( error ) {
|
|
3373
|
+
const err = error.message || 'Internal Server Error';
|
|
3374
|
+
logger.info( { error: error, message: req.body, function: 'totalNotAssignedCount' } );
|
|
3375
|
+
return res.sendError( err, 500 );
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
export async function auditImages( req, res ) {
|
|
3380
|
+
try {
|
|
3381
|
+
const inputData = req.query;
|
|
3382
|
+
let auditImageDownload = '';
|
|
3383
|
+
switch ( inputData.imageType ) {
|
|
3384
|
+
case 'BC':
|
|
3385
|
+
const auditImageBC = await getAuditImageData( inputData );
|
|
3386
|
+
if ( auditImageBC?.errorCode ) {
|
|
3387
|
+
const error = auditImageBC?.error || 'Internal Server Error- get BC from Bucket';
|
|
3388
|
+
const code = auditImageBC?.errorCode;
|
|
3389
|
+
return res.sendError( { error: error }, code );
|
|
3390
|
+
}
|
|
3391
|
+
if ( auditImageBC?.length == 0 ) {
|
|
3392
|
+
return res.sendError( 'No Data Found', 204 );
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
if ( inputData.export==true ) {
|
|
3396
|
+
auditImageDownload= await zipDownloadImage( auditImageBC );
|
|
3397
|
+
// Set response headers for the zip file
|
|
3398
|
+
res.set( 'Content-Type', 'application/zip' );
|
|
3399
|
+
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
3400
|
+
|
|
3401
|
+
// Send the zip file as the API response
|
|
3402
|
+
return res.send( auditImageDownload );
|
|
3403
|
+
}
|
|
3404
|
+
res.sendSuccess( { result: auditImageBC } );
|
|
3405
|
+
|
|
3406
|
+
break;
|
|
3407
|
+
|
|
3408
|
+
case 'AC':
|
|
3409
|
+
|
|
3410
|
+
const [ filterData, auditImageAC ] = await Promise.all( [ getAuditFilterData( inputData ), getAuditImageData( inputData ) ] );
|
|
3411
|
+
|
|
3412
|
+
if ( filterData?.errorCode || auditImageAC?.errorCode ) {
|
|
3413
|
+
const error = ( filterData?.error || auditImageAC.error ) || 'Internal Server Error- get AC from Bucket';
|
|
3414
|
+
const code = filterData?.errorCode || auditImageAC.errorCode;
|
|
3415
|
+
return res.sendError( { error: error }, code );
|
|
3416
|
+
}
|
|
3417
|
+
|
|
3418
|
+
const reauditImg = await getReauditImg( filterData, auditImageAC );
|
|
3419
|
+
logger.info( { reauditImg: reauditImg } );
|
|
3420
|
+
if ( reauditImg?.length == 0 ) {
|
|
3421
|
+
return res.sendError( 'No Data Found', 204 );
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
logger.info( { auditImageAC: auditImageAC, filterData: filterData, reauditImg: reauditImg } );
|
|
3425
|
+
if ( inputData.export==true ) {
|
|
3426
|
+
auditImageDownload= await zipDownloadImage( reauditImg );
|
|
3427
|
+
// Set response headers for the zip file
|
|
3428
|
+
res.set( 'Content-Type', 'application/zip' );
|
|
3429
|
+
res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
|
|
3430
|
+
|
|
3431
|
+
// Send the zip file as the API response
|
|
3432
|
+
return res.send( auditImageDownload );
|
|
3433
|
+
}
|
|
3434
|
+
res.sendSuccess( { result: reauditImg } );
|
|
3435
|
+
break;
|
|
3436
|
+
default:
|
|
3437
|
+
res.sendError( 'No Data Found', 204 );
|
|
3438
|
+
break;
|
|
3439
|
+
}
|
|
3440
|
+
|
|
3441
|
+
|
|
3442
|
+
// return res.sendSuccess( { result: inputData } );
|
|
3443
|
+
} catch ( error ) {
|
|
3444
|
+
const err = error.message || 'Internal Server Error';
|
|
3445
|
+
logger.info( { error: error, message: req.body, function: 'auditImages' } );
|
|
3446
|
+
return res.sendError( err, 500 );
|
|
3447
|
+
}
|
|
3448
|
+
}
|