tango-app-api-audit 3.4.0-alpha.3 → 3.4.0-alpha.5

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,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-audit",
3
- "version": "3.4.0-alpha.3",
3
+ "version": "3.4.0-alpha.5",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  import { checkFileExist, download, getDate, getDateWithCustomizeTime, getUTC, insertOpenSearchData, listFileByPath, logger, signedUrl, sqsReceive } from 'tango-app-api-middleware';
2
2
  import { aggregateBinaryAudit, createBinaryAudit, updateOneBinaryAuditModel } from '../service/binaryAudit.service.js';
3
- import { findOneStore } from '../service/store.service.js';
3
+ import { countDocumentsStore, findOneStore } from '../service/store.service.js';
4
4
  import { findOneUser } from '../service/user.service.js';
5
5
  import { aggregateUserEmpDetection, createUserEmpDetection } from '../service/userEmpDetection.service.js';
6
6
  import { aggregateTraxAuditData, findOneTraxAuditData } from '../service/traxAuditData.service.js';
@@ -1181,6 +1181,7 @@ export async function saveBinary( req, res ) {
1181
1181
  let leftupdate={
1182
1182
  auditStatus: 'completed',
1183
1183
  answer: inputData.answer,
1184
+ userCommands: inputData.userComments || '',
1184
1185
  };
1185
1186
  let updatDataleft= await updateOneBinaryAuditModel( leftquery, leftupdate );
1186
1187
  if ( updatDataleft.modifiedCount==0 ) {
@@ -1202,6 +1203,7 @@ export async function saveBinary( req, res ) {
1202
1203
  let cameraupdate={
1203
1204
  auditStatus: 'completed',
1204
1205
  answer: inputData.answer,
1206
+ userCommands: inputData.userComments || '',
1205
1207
  };
1206
1208
  let updatDatacamera= await updateOneBinaryAuditModel( cameraquery, cameraupdate );
1207
1209
  if ( updatDatacamera.modifiedCount==0 ) {
@@ -2083,11 +2085,11 @@ export async function userMetrics( req, res ) {
2083
2085
  tempId: 1,
2084
2086
  question: 1,
2085
2087
  answer: 1,
2086
- mappingPerc: { $round: [
2087
- { $multiply: [
2088
- { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
2089
- ] }, 2,
2090
- ] },
2088
+ // mappingPerc: { $round: [
2089
+ // { $multiply: [
2090
+ // { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
2091
+ // ] }, 2,
2092
+ // ] },
2091
2093
  checkIntime: 1,
2092
2094
  checkOutTime: 1,
2093
2095
  differenceInSeconds: {
@@ -2104,7 +2106,7 @@ export async function userMetrics( req, res ) {
2104
2106
  afterCount: 1,
2105
2107
  checkIntime: 1,
2106
2108
  checkOutTime: 1,
2107
- mappingPerc: 1,
2109
+ // mappingPerc: 1,
2108
2110
  streamName: 1,
2109
2111
  tempId: 1,
2110
2112
  question: 1,
@@ -2124,7 +2126,7 @@ export async function userMetrics( req, res ) {
2124
2126
  afterCount: 1,
2125
2127
  checkIntime: 1,
2126
2128
  checkOutTime: 1,
2127
- mappingPerc: 1,
2129
+ // mappingPerc: 1,
2128
2130
  streamName: 1,
2129
2131
  tempId: 1,
2130
2132
  question: 1,
@@ -2164,7 +2166,7 @@ export async function userMetrics( req, res ) {
2164
2166
  checkIntime: 1,
2165
2167
  zoneName: 1,
2166
2168
  checkOutTime: 1,
2167
- mappingPerc: 1,
2169
+ // mappingPerc: 1,
2168
2170
  streamName: 1,
2169
2171
  tempId: 1,
2170
2172
  question: 1,
@@ -2209,7 +2211,7 @@ export async function userMetrics( req, res ) {
2209
2211
  totalCompletedFiles: 1,
2210
2212
  beforeCount: 1,
2211
2213
  afterCount: 1,
2212
- mappingPerc: 1,
2214
+ // mappingPerc: 1,
2213
2215
  streamName: 1,
2214
2216
  tempId: 1,
2215
2217
  question: 1,
@@ -2275,6 +2277,10 @@ export async function userMetrics( req, res ) {
2275
2277
  'check OutTime': '$checkOutTime',
2276
2278
  'working Hours': '$workingHours',
2277
2279
  'Mapping Percentage': '$mappingPerc',
2280
+ 'Customer ID': '$tempId',
2281
+ 'Stream Name': '$streamName',
2282
+ 'Question': '$question',
2283
+ 'Answer': '$answer',
2278
2284
  },
2279
2285
  },
2280
2286
  );
@@ -2293,3 +2299,722 @@ export async function userMetrics( req, res ) {
2293
2299
  return res.sendError( err, 500 );
2294
2300
  }
2295
2301
  }
2302
+
2303
+ export async function pendingSummaryTable( req, res ) {
2304
+ try {
2305
+ const inputData = req.body;
2306
+ const limit = inputData.limit || 10;
2307
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
2308
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
2309
+ let filters =[
2310
+ { fileDateISO: { $gte: dateRange.start } },
2311
+ { fileDateISO: { $lte: dateRange.end } },
2312
+ { auditStatus: { $ne: 'completed' } },
2313
+ { moduleType: { $eq: inputData.moduleType } },
2314
+
2315
+ ];
2316
+
2317
+ if ( inputData.clientId.length > 0 ) {
2318
+ filters.push( { clientId: { $in: inputData.clientId } } );
2319
+ }
2320
+
2321
+ if ( inputData.filterByAuditType.length > 0 ) {
2322
+ filters.push( { auditType: { $in: inputData.filterByAuditType } } );
2323
+ }
2324
+
2325
+ if ( inputData.filterByStatus.length > 0 ) {
2326
+ filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
2327
+ }
2328
+ const query =[
2329
+ {
2330
+ $match: {
2331
+ $and: filters,
2332
+ },
2333
+
2334
+ },
2335
+ {
2336
+ $project: {
2337
+ _id: 0,
2338
+ storeId: 1,
2339
+ streamName: 1,
2340
+ tempId: 1,
2341
+ question: 1,
2342
+ answer: 1,
2343
+ userCommands: 1,
2344
+ fileDate: 1,
2345
+ moduleType: 1,
2346
+ beforeCount: 1,
2347
+ startTime: { $dateToString: {
2348
+ format: '%Y-%m-%d %H:%M:%S',
2349
+ date: '$startTime',
2350
+ timezone: 'Asia/Kolkata',
2351
+ },
2352
+
2353
+ },
2354
+ auditType: 1,
2355
+ auditStatus: 1,
2356
+ userId: 1,
2357
+ },
2358
+ },
2359
+ {
2360
+ $lookup: {
2361
+ from: 'users',
2362
+ let: { userId: '$userId' },
2363
+ pipeline: [
2364
+ {
2365
+ $match: {
2366
+ $expr: {
2367
+ $eq: [ '$_id', '$$userId' ],
2368
+ },
2369
+ },
2370
+ },
2371
+ {
2372
+ $project: {
2373
+ userName: 1,
2374
+ userEmail: '$email',
2375
+ },
2376
+ },
2377
+ ], as: 'user',
2378
+ },
2379
+ },
2380
+ {
2381
+ $unwind: {
2382
+ path: '$user',
2383
+ preserveNullAndEmptyArrays: true,
2384
+ },
2385
+ },
2386
+ {
2387
+ $project: {
2388
+ storeId: 1,
2389
+ streamName: 1,
2390
+ tempId: 1,
2391
+ question: 1,
2392
+ answer: 1,
2393
+ userCommands: 1,
2394
+ fileDate: 1,
2395
+ moduleType: 1,
2396
+ beforeCount: 1,
2397
+ startTime: 1,
2398
+ endTime: 1,
2399
+ auditType: 1,
2400
+ auditStatus: 1,
2401
+ userName: '$user.userName',
2402
+ userEmail: '$user.userEmail',
2403
+
2404
+ },
2405
+ },
2406
+ ];
2407
+ if ( inputData.searchValue && inputData.searchValue!== '' ) {
2408
+ query.push( {
2409
+ $match: {
2410
+ $or: [
2411
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
2412
+ { fileDate: { $regex: inputData.searchValue, $options: 'i' } },
2413
+ { auditType: { $regex: inputData.searchValue, $options: 'i' } },
2414
+ { auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
2415
+ { userName: { $regex: inputData.searchValue, $options: 'i' } },
2416
+ { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
2417
+ ],
2418
+
2419
+ },
2420
+ } );
2421
+ }
2422
+ if ( inputData.sortColumnName ) {
2423
+ const sortBy = inputData.sortBy || -1;
2424
+ const sortColumn = inputData.sortColumnName;
2425
+ query.push( {
2426
+ $sort: { [sortColumn]: sortBy },
2427
+ },
2428
+ );
2429
+ }
2430
+ const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2431
+ if ( count.length == 0 ) {
2432
+ return res.sendError( 'No Data Found', 204 );
2433
+ }
2434
+
2435
+ if ( inputData.isExport ) {
2436
+ query.push( { $limit: 10000 } );
2437
+ } else {
2438
+ query.push( {
2439
+ $skip: offset,
2440
+ },
2441
+ {
2442
+ $limit: limit,
2443
+ } );
2444
+ }
2445
+
2446
+ const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2447
+ if ( inputData.isExport ) {
2448
+ const exportdata = [];
2449
+ result.forEach( ( element ) => {
2450
+ if ( element.moduleType == 'zone' ) {
2451
+ exportdata.push( {
2452
+ 'Store ID': element.storeId,
2453
+ 'Stream Name': element.streamName,
2454
+ 'Customer ID': element.tempId,
2455
+ 'Question': question,
2456
+ 'Answer': element.answer,
2457
+ 'userComments': element.userCommands,
2458
+ 'File Date': element.fileDate,
2459
+ 'Product Type': element.moduleType,
2460
+ 'Audit Type': element.auditType,
2461
+ 'Before Count': element.beforeCount,
2462
+ 'Start Time': element.startTime,
2463
+ 'User Name': element.userName,
2464
+ 'User Email': element.userEmail,
2465
+ 'Status': element.auditStatus,
2466
+ } );
2467
+ } else {
2468
+ exportdata.push( {
2469
+ 'Store ID': element.storeId,
2470
+ 'Stream Name': element.streamName,
2471
+ 'Customer ID': element.tempId,
2472
+ 'Question': question,
2473
+ 'Answer': element.answer,
2474
+ 'userComments': element.userCommands,
2475
+ 'File Date': element.fileDate,
2476
+ 'Product Type': element.moduleType,
2477
+ 'Audit Type': element.auditType,
2478
+ 'Before Count': element.beforeCount,
2479
+ 'Start Time': element.startTime,
2480
+ 'User Name': element.userName,
2481
+ 'User Email': element.userEmail,
2482
+ 'Status': element.auditStatus,
2483
+ } );
2484
+ }
2485
+ } );
2486
+ await download( exportdata, res );
2487
+ return;
2488
+ }
2489
+ return res.sendSuccess( { result: result, count: count.length } );
2490
+ } catch ( error ) {
2491
+ const err = error.message || 'Internal Server Error';
2492
+ logger.error( { error: error, message: req.body, function: 'pendingSummaryTable' } );
2493
+ return res.sendError( err, 500 );
2494
+ }
2495
+ }
2496
+
2497
+ export async function overAllAuditSummary( req, res ) {
2498
+ try {
2499
+ const inputData = req.body;
2500
+ let temp = {
2501
+ installedStores: 0,
2502
+ auditStores: 0,
2503
+ inprogressStores: 0,
2504
+ completedStores: 0,
2505
+ auditInprogress: 0,
2506
+ reAuditInprogress: 0,
2507
+ draft: 0,
2508
+ assigned: 0,
2509
+ notAssigned: 0,
2510
+ auditCompleted: 0,
2511
+ reAuditCompleted: 0,
2512
+
2513
+ };
2514
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
2515
+ let filters =[
2516
+ { fileDateISO: { $gte: dateRange.start } },
2517
+ { fileDateISO: { $lte: dateRange.end } },
2518
+ { moduleType: { $eq: inputData.moduleType },
2519
+ },
2520
+ ];
2521
+ if ( inputData.clientId.length > 0 ) {
2522
+ filters.push( { clientId: { $in: inputData.clientId } } );
2523
+ }
2524
+ const storeQuery = inputData.clientId.length? { 'edge.firstFile': true, 'clientId': { $in: inputData. clientId } } : { 'edge.firstFile': true };
2525
+ temp.installedStores = await countDocumentsStore( storeQuery );
2526
+ const auditClientDataQuery =[
2527
+ {
2528
+ $match: {
2529
+ $and: filters,
2530
+ },
2531
+
2532
+ },
2533
+ {
2534
+ $group: {
2535
+ _id: null,
2536
+ totalFilesCount: { $sum: 1 },
2537
+ },
2538
+ },
2539
+ {
2540
+ $project: {
2541
+ _id: 0,
2542
+ totalFilesCount: 1,
2543
+ },
2544
+ },
2545
+ ];
2546
+ const auditClientData = await aggregateTraxAuditData( auditClientDataQuery );
2547
+ if ( auditClientData.length >0 ) {
2548
+ temp.auditStores = auditClientData[0].totalFilesCount;
2549
+ }
2550
+ const storeAuditQuery =[
2551
+ {
2552
+ $match: {
2553
+ $and: filters,
2554
+ },
2555
+
2556
+ },
2557
+ {
2558
+ $project: {
2559
+ completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
2560
+ auditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
2561
+ reAuditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
2562
+ draft: { $cond: [ { $eq: [ '$status', 'drafted' ] }, 1, 0 ] },
2563
+ assigned: { $cond: [ { $eq: [ '$status', 'assigned' ] }, 1, 0 ] },
2564
+ exceptNoAssigned: { $cond: { if: { $not: { $in: [ '$status', [ 'skipped', 'not_assign' ] ] } }, then: 1, else: 0 } },
2565
+ auditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
2566
+ reAuditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
2567
+
2568
+
2569
+ },
2570
+ },
2571
+ {
2572
+ $group: {
2573
+ _id: null,
2574
+ completedStores: { $sum: '$completedStores' },
2575
+ auditInprogress: { $sum: '$auditInprogress' },
2576
+ reAuditInprogress: { $sum: '$reAuditInprogress' },
2577
+ draft: { $sum: '$draft' },
2578
+ assigned: { $sum: '$assigned' },
2579
+ exceptNoAssigned: { $sum: '$exceptNoAssigned' },
2580
+ auditCompleted: { $sum: '$auditCompleted' },
2581
+ reAuditCompleted: { $sum: '$reAuditCompleted' },
2582
+ },
2583
+ },
2584
+ {
2585
+ $project: {
2586
+ completedStores: 1,
2587
+ inprogressStores: { $subtract: [ temp.auditStores, '$completedStores' ] },
2588
+ auditInprogress: 1,
2589
+ reAuditInprogress: 1,
2590
+ draft: 1,
2591
+ assigned: 1,
2592
+ exceptNoAssigned: { $subtract: [ temp.auditStores, '$exceptNoAssigned' ] },
2593
+ auditCompleted: 1,
2594
+ reAuditCompleted: 1,
2595
+ },
2596
+ },
2597
+ ];
2598
+ const storeAudit = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( storeAuditQuery );
2599
+ if ( storeAudit.length > 0 ) {
2600
+ temp.inprogressStores= storeAudit[0].inprogressStores;
2601
+ temp.completedStores = storeAudit[0].completedStores;
2602
+ temp.auditInprogress = storeAudit[0].auditInprogress;
2603
+ temp.reAuditInprogress = storeAudit[0].reAuditInprogress;
2604
+ temp.draft = storeAudit[0].draft;
2605
+ temp.assigned = storeAudit[0].assigned;
2606
+ temp.notAssigned = storeAudit[0].exceptNoAssigned;
2607
+ temp.auditCompleted = storeAudit[0].auditCompleted;
2608
+ temp.reAuditCompleted = storeAudit[0].reAuditCompleted;
2609
+ }
2610
+
2611
+ return res.sendSuccess( { result: temp } );
2612
+ } catch ( error ) {
2613
+ const err = error.message || 'Internal Server Error';
2614
+ logger.error( { error: error, message: req.body, function: 'overAllAuditSummary' } );
2615
+ return res.sendError( err, 500 );
2616
+ }
2617
+ }
2618
+
2619
+ export async function overViewCard( req, res ) {
2620
+ try {
2621
+ const inputData = req.body;
2622
+ const temp = {
2623
+ totalCount: 0,
2624
+ auditFileCount: 0,
2625
+ ReAuditFileCount: 0,
2626
+ inprogressCount: 0,
2627
+ completedCount: 0,
2628
+ pendingCount: 0,
2629
+ };
2630
+
2631
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
2632
+ let filters =[
2633
+ { fileDateISO: { $gte: dateRange.start } },
2634
+ { fileDateISO: { $lte: dateRange.end } },
2635
+ ];
2636
+ if ( inputData.clientId.length > 0 ) {
2637
+ filters.push( { clientId: { $in: inputData.clientId } } );
2638
+ }
2639
+ const query =[
2640
+ {
2641
+ $match: {
2642
+ $and: filters,
2643
+ },
2644
+
2645
+ },
2646
+ {
2647
+ $project: {
2648
+ auditFileCount: {
2649
+ $cond: [
2650
+ { $eq: [ '$auditType', 'Audit' ] }, 1, 0,
2651
+ ],
2652
+ },
2653
+ ReAuditFileCount: {
2654
+ $cond: [
2655
+ { $eq: [ '$auditType', 'ReAudit' ] }, 1, 0,
2656
+ ],
2657
+ },
2658
+ inprogressCount: {
2659
+ $cond: [
2660
+ { $ne: [ '$status', 'completed' ] }, 1, 0,
2661
+ ],
2662
+ },
2663
+ completedCount: {
2664
+ $cond: [
2665
+ { $eq: [ '$status', 'completed' ] }, 1, 0,
2666
+ ],
2667
+ },
2668
+ },
2669
+ },
2670
+ {
2671
+ $group: {
2672
+ _id: { fileDate: '$fileDate', clientId: '$clientId' },
2673
+ totalCount: { $sum: 1 },
2674
+ auditFileCount: { $sum: '$auditFileCount' },
2675
+ ReAuditFileCount: { $sum: '$ReAuditFileCount' },
2676
+ inprogressCount: { $sum: '$inprogressCount' },
2677
+ completedCount: { $sum: '$completedCount' },
2678
+
2679
+ },
2680
+ },
2681
+ {
2682
+ $project: {
2683
+ _id: 0,
2684
+ totalCount: 1,
2685
+ auditFileCount: 1,
2686
+ ReAuditFileCount: 1,
2687
+ inprogressCount: 1,
2688
+ completedCount: 1,
2689
+ notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
2690
+ },
2691
+ },
2692
+ ];
2693
+ const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2694
+ logger.info( { result: result } );
2695
+ return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
2696
+ } catch ( error ) {
2697
+ const err = error.message || 'Internal Server Error';
2698
+ logger.error( { error: error, message: req.body, function: 'overViewCard' } );
2699
+ return res.sendError( err, 500 );
2700
+ }
2701
+ }
2702
+
2703
+ export async function summarySplit( req, res ) {
2704
+ try {
2705
+ const inputData = req.body;
2706
+ const temp = {
2707
+ total: 0,
2708
+ auditInprogress: 0,
2709
+ reAuditInprogress: 0,
2710
+ draft: 0,
2711
+ assigned: 0,
2712
+ auditCompleted: 0,
2713
+ reAuditCompleted: 0,
2714
+ };
2715
+
2716
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
2717
+ let filters =[
2718
+ { fileDateISO: { $gte: dateRange.start } },
2719
+ { fileDateISO: { $lte: dateRange.end } },
2720
+ { moduleType: { $eq: inputData.moduleType } },
2721
+ ];
2722
+ if ( inputData.clientId.length > 0 ) {
2723
+ filters.push( { clientId: { $in: inputData.clientId } } );
2724
+ }
2725
+ const query =[
2726
+ {
2727
+ $match: {
2728
+ $and: filters,
2729
+ },
2730
+
2731
+ },
2732
+ {
2733
+ $project: {
2734
+ auditInprogress: {
2735
+ $cond: [
2736
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
2737
+ ],
2738
+ },
2739
+ reAuditInprogress: {
2740
+ $cond: [
2741
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
2742
+ ],
2743
+ },
2744
+ draft: {
2745
+ $cond: [
2746
+ { $eq: [ '$status', 'drafted' ] }, 1, 0,
2747
+ ],
2748
+ },
2749
+ assigned: {
2750
+ $cond: [
2751
+ { $eq: [ '$status', 'assigned' ] }, 1, 0,
2752
+ ],
2753
+ },
2754
+
2755
+ reAuditCompleted: {
2756
+ $cond: [
2757
+ { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
2758
+ ],
2759
+ },
2760
+ auditCompleted: {
2761
+ $cond: [
2762
+ { $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
2763
+ ],
2764
+ },
2765
+ },
2766
+ },
2767
+ {
2768
+ $group: {
2769
+ _id: null,
2770
+ auditInprogress: { $sum: '$auditInprogress' },
2771
+ reAuditInprogress: { $sum: '$reAuditInprogress' },
2772
+ draft: { $sum: '$draft' },
2773
+ assigned: { $sum: '$assigned' },
2774
+ reAuditCompleted: { $sum: '$reAuditCompleted' },
2775
+ auditCompleted: { $sum: '$auditCompleted' },
2776
+
2777
+ },
2778
+ },
2779
+ {
2780
+ $project: {
2781
+ _id: 0,
2782
+ totalInprogress: 1,
2783
+ auditInprogress: 1,
2784
+ reAuditInprogress: 1,
2785
+ draft: 1,
2786
+ assigned: 1,
2787
+ reAuditCompleted: 1,
2788
+ auditCompleted: 1,
2789
+ totalCount: { $ifNull: [ 0, 0 ] },
2790
+
2791
+ },
2792
+ },
2793
+ ];
2794
+ const totalQuery = [
2795
+ {
2796
+ $match: {
2797
+ $and: filters,
2798
+ },
2799
+
2800
+ },
2801
+ {
2802
+ $group: {
2803
+ _id: null,
2804
+ total: { $sum: 1 },
2805
+ },
2806
+ },
2807
+ {
2808
+ $project: {
2809
+ _id: 0,
2810
+ total: 1,
2811
+ },
2812
+ },
2813
+ ];
2814
+ const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
2815
+ const totalCount = await aggregateTraxAuditData( totalQuery );
2816
+ result[0].totalCount = totalCount[0]?.total;
2817
+ return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
2818
+ } catch ( error ) {
2819
+ const err = error.message || 'Internal Server Error';
2820
+ logger.error( { error: error, message: req.body, function: 'summarySplit' } );
2821
+ return res.sendError( err, 500 );
2822
+ }
2823
+ }
2824
+
2825
+ export async function overviewTable( req, res ) {
2826
+ try {
2827
+ const inputData = req.body;
2828
+ const limit = inputData.limit || 10;
2829
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
2830
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
2831
+ let filters =[
2832
+ { fileDateISO: { $gte: dateRange.start } },
2833
+ { fileDateISO: { $lte: dateRange.end } },
2834
+ { moduleType: { $eq: inputData.moduleType } },
2835
+
2836
+ ];
2837
+
2838
+ if ( inputData.clientId.length > 0 ) {
2839
+ filters.push( { clientId: { $in: inputData.clientId } } );
2840
+ }
2841
+
2842
+ if ( inputData.filterByAuditType.length > 0 ) {
2843
+ filters.push( { auditType: { $in: inputData.filterByAuditType } } );
2844
+ }
2845
+
2846
+ if ( inputData.filterByStatus.length > 0 ) {
2847
+ filters.push( { status: { $in: inputData.filterByStatus } } );
2848
+ }
2849
+
2850
+ const query =[
2851
+ {
2852
+ $match: {
2853
+ $and: filters,
2854
+ },
2855
+
2856
+ },
2857
+ {
2858
+ $project: {
2859
+ _id: 0,
2860
+ storeId: 1,
2861
+ clientId: 1,
2862
+ streamName: 1,
2863
+ tempId: 1,
2864
+ question: 1,
2865
+ answer: 1,
2866
+ userCommands: 1,
2867
+ fileDate: 1,
2868
+ moduleType: 1,
2869
+ beforeCount: 1,
2870
+ afterCount: 1,
2871
+ auditType: 1,
2872
+ status: 1,
2873
+ // userId: 1,
2874
+ },
2875
+ },
2876
+ // {
2877
+ // $lookup: {
2878
+ // from: 'users',
2879
+ // let: { userId: '$userId' },
2880
+ // pipeline: [
2881
+ // {
2882
+ // $match: {
2883
+ // $expr: {
2884
+ // $eq: [ '$_id', '$$userId' ],
2885
+ // },
2886
+ // },
2887
+ // },
2888
+ // {
2889
+ // $project: {
2890
+ // userName: 1,
2891
+ // userEmail: '$email',
2892
+ // },
2893
+ // },
2894
+ // ], as: 'user',
2895
+ // },
2896
+ // },
2897
+ // {
2898
+ // $unwind: {
2899
+ // path: '$user',
2900
+ // preserveNullAndEmptyArrays: true,
2901
+ // },
2902
+ // },
2903
+ {
2904
+ $project: {
2905
+ storeId: 1,
2906
+ clientId: 1,
2907
+ streamName: 1,
2908
+ tempId: 1,
2909
+ question: 1,
2910
+ answer: 1,
2911
+ userCommands: 1,
2912
+ fileDate: 1,
2913
+ moduleType: 1,
2914
+ beforeCount: 1,
2915
+ afterCount: 1,
2916
+ auditType: 1,
2917
+ status: 1,
2918
+ // userName: '$user.userName',
2919
+ // userEmail: '$user.userEmail',
2920
+
2921
+ },
2922
+ },
2923
+ ];
2924
+ if ( inputData.searchValue && inputData.searchValue!== '' ) {
2925
+ query.push( {
2926
+ $match: {
2927
+ $or: [
2928
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
2929
+ { clientId: { $regex: inputData.searchValue, $options: 'i' } },
2930
+ { fileDate: { $regex: inputData.searchValue, $options: 'i' } },
2931
+ { auditType: { $regex: inputData.searchValue, $options: 'i' } },
2932
+ { status: { $regex: inputData.searchValue, $options: 'i' } },
2933
+ { moduleType: { $regex: inputData.searchValue, $options: 'i' } },
2934
+ { streamName: { $regex: inputData.searchValue, $options: 'i' } },
2935
+ { tempId: { $regex: inputData.searchValue, $options: 'i' } },
2936
+ { question: { $regex: inputData.searchValue, $options: 'i' } },
2937
+ { answer: { $regex: inputData.searchValue, $options: 'i' } },
2938
+ { userCommands: { $regex: inputData.searchValue, $options: 'i' } },
2939
+ // { userName: { $regex: inputData.searchValue, $options: 'i' } },
2940
+ // { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
2941
+ ],
2942
+
2943
+ },
2944
+ } );
2945
+ }
2946
+ if ( inputData.sortColumnName ) {
2947
+ const sortBy = inputData.sortBy || -1;
2948
+ const sortColumn = inputData.sortColumnName;
2949
+ query.push( {
2950
+ $sort: { [sortColumn]: sortBy },
2951
+ },
2952
+ );
2953
+ }
2954
+ const count = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2955
+ if ( count.length == 0 ) {
2956
+ return res.sendError( 'No Data Found', 204 );
2957
+ }
2958
+
2959
+ if ( inputData.isExport ) {
2960
+ query.push( { $limit: 10000 } );
2961
+ } else {
2962
+ query.push( {
2963
+ $skip: offset,
2964
+ },
2965
+ {
2966
+ $limit: limit,
2967
+ } );
2968
+ }
2969
+ const result = inputData.moduleType.includes( [ 'uniform-detection', 'mobile-detection' ] )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
2970
+ if ( inputData.isExport ) {
2971
+ const exportdata = [];
2972
+ result.forEach( ( element ) => {
2973
+ if ( element.moduleType == 'zone' ) {
2974
+ exportdata.push( {
2975
+ 'Store ID': element.storeId,
2976
+ 'Brand ID': element.clientId,
2977
+ 'Stream Name': element.streamName,
2978
+ 'Customer ID': element.tempId,
2979
+ 'Question': element.question,
2980
+ 'Answer': element.answer,
2981
+ 'User Comments': element.userCommands,
2982
+ 'File Date': element.fileDate,
2983
+ 'Product Type': element.moduleType,
2984
+ 'Audit Type': element.auditType,
2985
+ 'Before Count': element.beforeCount,
2986
+ 'After Count': element.afterCount,
2987
+ // 'User Name': element.userName,
2988
+ // 'User Email': element.userEmail,
2989
+ 'Status': element.status,
2990
+ } );
2991
+ } else {
2992
+ exportdata.push( {
2993
+ 'Store ID': element.storeId,
2994
+ 'Brand ID': element.clientId,
2995
+ 'File Date': element.fileDate,
2996
+ 'Stream Name': element.streamName,
2997
+ 'Customer ID': element.tempId,
2998
+ 'Question': element.question,
2999
+ 'Answer': element.answer,
3000
+ 'User Comments': element.userCommands,
3001
+ 'Product Type': element.moduleType,
3002
+ 'Audit Type': element.auditType,
3003
+ 'Before Count': element.beforeCount,
3004
+ 'After Count': element.afterCount,
3005
+ // 'User Name': element.userName,
3006
+ // 'User Email': element.userEmail,
3007
+ 'Status': element.status,
3008
+ } );
3009
+ }
3010
+ } );
3011
+ await download( exportdata, res );
3012
+ return;
3013
+ }
3014
+ return res.sendSuccess( { result: result, count: count.length } );
3015
+ } catch ( error ) {
3016
+ const err = error.message || 'Internal Server Error';
3017
+ logger.error( { error: error, message: req.body, function: 'overviewTable' } );
3018
+ return res.sendError( err, 500 );
3019
+ }
3020
+ }
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema } from '../dtos/traxAudit.dtos.js';
2
+ import { getFileSchema, userAuditHistorySchema, workSpaceSchema, saveSchema, clientMetricsSchema, storeMetricsSchema, userMetricsSchema, pendingSummaryTableSchema, overAllAuditSummarySchema, overviewTableSchema, summarySplitSchema, overViewCardSchema } from '../dtos/traxAudit.dtos.js';
3
3
 
4
4
  export const traxAuditDocs = {
5
5
 
@@ -178,4 +178,116 @@ export const traxAuditDocs = {
178
178
  },
179
179
  },
180
180
  },
181
+ '/v3/trax-audit/metrics/pending-summary-table': {
182
+ post: {
183
+ tags: [ 'Trax Audit' ],
184
+ description: `Get overall user taken data with some filters `,
185
+ operationId: 'metrics/pending-summary-table',
186
+ parameters: {},
187
+ requestBody: {
188
+ content: {
189
+ 'application/json': {
190
+ schema: j2s( pendingSummaryTableSchema ).swagger,
191
+ },
192
+ },
193
+ },
194
+ responses: {
195
+ 200: { description: 'Successful' },
196
+ 401: { description: 'Unauthorized User' },
197
+ 422: { description: 'Field Error' },
198
+ 500: { description: 'Server Error' },
199
+ 204: { description: 'Not Found' },
200
+ },
201
+ },
202
+ },
203
+ '/v3/trax-audit/metrics/overall-audit-summary': {
204
+ post: {
205
+ tags: [ 'Trax Audit' ],
206
+ description: `Get overall user taken data with some filters `,
207
+ operationId: 'metrics/overall-audit-summary',
208
+ parameters: {},
209
+ requestBody: {
210
+ content: {
211
+ 'application/json': {
212
+ schema: j2s( overAllAuditSummarySchema ).swagger,
213
+ },
214
+ },
215
+ },
216
+ responses: {
217
+ 200: { description: 'Successful' },
218
+ 401: { description: 'Unauthorized User' },
219
+ 422: { description: 'Field Error' },
220
+ 500: { description: 'Server Error' },
221
+ 204: { description: 'Not Found' },
222
+ },
223
+ },
224
+ },
225
+ '/v3/trax-audit/metrics/overview-card': {
226
+ post: {
227
+ tags: [ 'Trax Audit' ],
228
+ description: `Get overall high level audited files count`,
229
+ operationId: 'metrics/overview-card',
230
+ parameters: {},
231
+ requestBody: {
232
+ content: {
233
+ 'application/json': {
234
+ schema: j2s( overViewCardSchema ).swagger,
235
+ },
236
+ },
237
+ },
238
+ responses: {
239
+ 200: { description: 'Successful' },
240
+ 401: { description: 'Unauthorized User' },
241
+ 422: { description: 'Field Error' },
242
+ 500: { description: 'Server Error' },
243
+ 204: { description: 'Not Found' },
244
+ },
245
+ },
246
+ },
247
+
248
+ '/v3/trax-audit/metrics/summary-split-up': {
249
+ post: {
250
+ tags: [ 'Trax Audit' ],
251
+ description: `Get overall high level audited files count splitup`,
252
+ operationId: 'metrics/summary-split-up',
253
+ parameters: {},
254
+ requestBody: {
255
+ content: {
256
+ 'application/json': {
257
+ schema: j2s( summarySplitSchema ).swagger,
258
+ },
259
+ },
260
+ },
261
+ responses: {
262
+ 200: { description: 'Successful' },
263
+ 401: { description: 'Unauthorized User' },
264
+ 422: { description: 'Field Error' },
265
+ 500: { description: 'Server Error' },
266
+ 204: { description: 'Not Found' },
267
+ },
268
+ },
269
+ },
270
+
271
+ '/v3/trax-audit/metrics/overview-table': {
272
+ post: {
273
+ tags: [ 'Trax Audit' ],
274
+ description: `Get overall user taken data with some filters `,
275
+ operationId: 'metrics/overview-table',
276
+ parameters: {},
277
+ requestBody: {
278
+ content: {
279
+ 'application/json': {
280
+ schema: j2s( overviewTableSchema ).swagger,
281
+ },
282
+ },
283
+ },
284
+ responses: {
285
+ 200: { description: 'Successful' },
286
+ 401: { description: 'Unauthorized User' },
287
+ 422: { description: 'Field Error' },
288
+ 500: { description: 'Server Error' },
289
+ 204: { description: 'Not Found' },
290
+ },
291
+ },
292
+ },
181
293
  };
@@ -184,3 +184,85 @@ export const userMetricsSchema = joi.object(
184
184
  export const userMetricsValid = {
185
185
  body: userMetricsSchema,
186
186
  };
187
+
188
+ export const pendingSummaryTableSchema = joi.object(
189
+ {
190
+ fromDate: joi.string().required(),
191
+ toDate: joi.string().required(),
192
+ clientId: joi.array().optional(),
193
+ limit: joi.number().optional(),
194
+ offset: joi.number().optional(),
195
+ searchValue: joi.string().optional().allow( '' ),
196
+ filterByStatus: joi.array().required(),
197
+ moduleType: joi.string().required(),
198
+ filterByAuditType: joi.array().optional(),
199
+ sortColumnName: joi.string().optional(),
200
+ sortBy: joi.number().optional(),
201
+ isExport: joi.boolean().optional(),
202
+ },
203
+ );
204
+
205
+ export const pendingSummaryTableValid = {
206
+ body: pendingSummaryTableSchema,
207
+ };
208
+
209
+ export const overAllAuditSummarySchema = joi.object(
210
+ {
211
+ fromDate: joi.string().required(),
212
+ toDate: joi.string().required(),
213
+ clientId: joi.array().optional(),
214
+ moduleType: joi.string().required(),
215
+ },
216
+ );
217
+
218
+ export const overAllAuditSummaryValid = {
219
+ body: overAllAuditSummarySchema,
220
+ };
221
+
222
+
223
+ export const overViewCardSchema = joi.object(
224
+ {
225
+ fromDate: joi.string().required(),
226
+ toDate: joi.string().required(),
227
+ clientId: joi.array().optional(),
228
+ moduleType: joi.string().required(),
229
+ },
230
+ );
231
+
232
+ export const overViewCardValid = {
233
+ body: overViewCardSchema,
234
+ };
235
+
236
+ export const summarySplitSchema = joi.object(
237
+ {
238
+ fromDate: joi.string().required(),
239
+ toDate: joi.string().required(),
240
+ clientId: joi.array().optional(),
241
+ moduleType: joi.string().optional(),
242
+ },
243
+ );
244
+
245
+ export const summarySplitValid = {
246
+ body: summarySplitSchema,
247
+ };
248
+
249
+ export const overviewTableSchema = joi.object(
250
+ {
251
+ fromDate: joi.string().required(),
252
+ toDate: joi.string().required(),
253
+ clientId: joi.array().optional(),
254
+ limit: joi.number().optional(),
255
+ offset: joi.number().optional(),
256
+ searchValue: joi.string().optional().allow( '' ),
257
+ filterByStatus: joi.array().optional(),
258
+ moduleType: joi.string().optional(),
259
+ filterByAuditType: joi.array().optional(),
260
+ sortColumnName: joi.string().optional(),
261
+ sortBy: joi.number().optional(),
262
+ isExport: joi.boolean().optional(),
263
+ },
264
+ );
265
+
266
+ export const overviewTableValid= {
267
+ body: overviewTableSchema,
268
+ };
@@ -1,8 +1,8 @@
1
1
  import { Router } from 'express';
2
2
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
- import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid } from '../dtos/traxAudit.dtos.js';
3
+ import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, overViewCardValid } from '../dtos/traxAudit.dtos.js';
4
4
  import { isExistsQueue } from '../validation/audit.validation.js';
5
- import { clientMetrics, getAuditFile, getDetectionAuditFile, saveBinary, storeMetrics, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
5
+ import { clientMetrics, getAuditFile, getDetectionAuditFile, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace } from '../controllers/traxAudit.controllers.js';
6
6
  import { validateBinaryAudit } from '../validation/traxAuditValidation.js';
7
7
 
8
8
  export const traxAuditRouter = Router();
@@ -25,5 +25,13 @@ traxAuditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, va
25
25
  traxAuditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
26
26
  traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
27
27
  traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
28
+ traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
29
+ traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
30
+
31
+ // summary
32
+
33
+ traxAuditRouter.post( '/metrics/overview-card', isAllowedSessionHandler, validate( overViewCardValid ), overViewCard );
34
+ traxAuditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
35
+ traxAuditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
28
36
 
29
37
  export default traxAuditRouter;