tango-app-api-audit 3.3.0-alpha.1 → 3.3.0-alpha.10

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.3.0-alpha.1",
3
+ "version": "3.3.0-alpha.10",
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.152",
28
- "tango-app-api-middleware": "^3.1.30",
27
+ "tango-api-schema": "^2.0.154",
28
+ "tango-app-api-middleware": "^3.3.0-alpha.0",
29
29
  "winston": "^3.13.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -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
- aggregateAuditStoreDataSchema,
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
- file_date: userDetails[0].fileDate,
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.activityLog, logData );
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.activityLog, logData );
452
+ await insertOpenSearchData( openSearch.auditLog, logData );
448
453
  }
449
454
 
450
455
  const storeQuery = {
@@ -595,8 +600,9 @@ export async function getAuditFile( req, res ) {
595
600
  zoneName: msg.zone_id,
596
601
  moduleType: inputData.moduleType,
597
602
  },
603
+ createdAt: new Date(),
598
604
  };
599
- await insertOpenSearchData( openSearch.activityLog, logData );
605
+ await insertOpenSearchData( openSearch.auditLog, logData );
600
606
  }
601
607
  logger.info( { storeInfo: storeInfo } );
602
608
  return res.sendSuccess( {
@@ -632,7 +638,7 @@ export async function getFilterData( msg ) {
632
638
  try {
633
639
  const bucket = JSON.parse( process.env.BUCKET );
634
640
  const params = {
635
- Bucket: `${bucket.auditOutput}`,
641
+ Bucket: `${bucket.auditUploadBucket}`,
636
642
  Key: `${msg.store_id}/${msg.zone_id}/${msg.curr_date}/${bucket.masterJsonFile}`,
637
643
  };
638
644
  const mappingFile = await getJsonFileData( params );
@@ -711,8 +717,6 @@ export async function getAuditImage( msg ) {
711
717
 
712
718
  export const getReauditImg = async ( filter, image ) => {
713
719
  const chunkedMappingData = await chunkArray( image, 10 );
714
- logger.info( { chunkedMappingData: chunkedMappingData, level: 5 } );
715
-
716
720
  const promises = chunkedMappingData.map( async ( chunk ) => {
717
721
  return mapFunction( chunk, filter );
718
722
  } );
@@ -1008,7 +1012,7 @@ export async function workSpace( req, res ) {
1008
1012
  const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
1009
1013
  const completedStoresCount = await aggregateStoreAudit( completedStores );
1010
1014
  const clientAssignedCount = await aggregateAssignAudit( clientAssign );
1011
- const auditStoreData = await aggregateAuditStoreDataSchema(
1015
+ const auditStoreData = await aggregateAuditStoreData(
1012
1016
  auditStoreDataQuery,
1013
1017
  );
1014
1018
 
@@ -1157,6 +1161,7 @@ export async function saveDraft( req, res ) {
1157
1161
  logType: 'audit',
1158
1162
  logSubType: 'auditDraft',
1159
1163
  logData: {
1164
+ fileDate: inputData.fileDate,
1160
1165
  auditType: inputData.auditType,
1161
1166
  storeId: inputData.storeId,
1162
1167
  clientName: inputData.queueName,
@@ -1166,8 +1171,9 @@ export async function saveDraft( req, res ) {
1166
1171
  moduleType: inputData.moduleType,
1167
1172
  zoneName: inputData.zoneName,
1168
1173
  },
1174
+ createdAt: new Date(),
1169
1175
  };
1170
- await insertOpenSearchData( openSearch.activityLog, logData );
1176
+ await insertOpenSearchData( openSearch.auditLog, logData );
1171
1177
  }
1172
1178
  await createAuditLog( inputData );
1173
1179
  await updateOneUserAudit( userQuery, userRecord );
@@ -1195,8 +1201,8 @@ export async function getDraftedData( req, res ) {
1195
1201
  };
1196
1202
  const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
1197
1203
 
1198
- if ( result.length == 0 ) {
1199
- return res.sendError( 'No Data Found', 500 );
1204
+ if ( !result ) {
1205
+ return res.sendError( 'No Data Found', 204 );
1200
1206
  }
1201
1207
  return res.sendSuccess( { result: result } );
1202
1208
  } catch ( error ) {
@@ -1632,9 +1638,9 @@ export async function userAuditHistory( req, res ) {
1632
1638
  chunk.forEach( ( element ) => {
1633
1639
  exportData.push( {
1634
1640
 
1635
- 'Client Id': element.clientId,
1641
+ 'Client ID': element.clientId,
1636
1642
  'Client Name': element.clientName,
1637
- 'Store Id': element.storeId,
1643
+ 'Store ID': element.storeId,
1638
1644
  'Store Name': element.storeName,
1639
1645
  'Zone Name': element.zoneName,
1640
1646
  'Audit Type': element.auditType,
@@ -1851,7 +1857,7 @@ export async function clientMetrics( req, res ) {
1851
1857
  );
1852
1858
  }
1853
1859
 
1854
- const count = await aggregateAuditStoreDataSchema( query );
1860
+ const count = await aggregateAuditStoreData( query );
1855
1861
  if ( count.length == 0 ) {
1856
1862
  return res.sendError( 'No Data Found', 204 );
1857
1863
  }
@@ -1883,7 +1889,7 @@ export async function clientMetrics( req, res ) {
1883
1889
  }
1884
1890
 
1885
1891
  logger.info( { query: query } );
1886
- const result = await aggregateAuditStoreDataSchema( query );
1892
+ const result = await aggregateAuditStoreData( query );
1887
1893
  if ( result.length == 0 ) {
1888
1894
  return res.sendError( 'No Data Found', 204 );
1889
1895
  }
@@ -2145,7 +2151,7 @@ export async function storeMetrics( req, res ) {
2145
2151
  result.forEach( ( element ) => {
2146
2152
  exportdata.push( {
2147
2153
  'File Date': element.fileDate,
2148
- 'Store Id': element.storeId,
2154
+ 'Store ID': element.storeId,
2149
2155
  'Store Name': element.storeName,
2150
2156
  'Client Id': element.clientId,
2151
2157
  'Client Name': element.clientName,
@@ -2435,7 +2441,7 @@ export async function userMetrics( req, res ) {
2435
2441
  }
2436
2442
  }
2437
2443
 
2438
- export async function overViewTable( req, res ) {
2444
+ export async function pendingSummaryTable( req, res ) {
2439
2445
  try {
2440
2446
  const inputData = req.body;
2441
2447
  const limit = inputData.limit || 10;
@@ -2474,7 +2480,13 @@ export async function overViewTable( req, res ) {
2474
2480
  fileDate: 1,
2475
2481
  moduleType: 1,
2476
2482
  beforeCount: 1,
2477
- startTime: 1,
2483
+ startTime: { $dateToString: {
2484
+ format: '%Y-%m-%d %H:%M:%S',
2485
+ date: '$startTime',
2486
+ timezone: 'Asia/Kolkata',
2487
+ },
2488
+
2489
+ },
2478
2490
  auditType: 1,
2479
2491
  auditStatus: 1,
2480
2492
  userId: 1,
@@ -2515,6 +2527,7 @@ export async function overViewTable( req, res ) {
2515
2527
  moduleType: 1,
2516
2528
  beforeCount: 1,
2517
2529
  startTime: 1,
2530
+ endTime: 1,
2518
2531
  auditType: 1,
2519
2532
  auditStatus: 1,
2520
2533
  userName: '$user.userName',
@@ -2566,7 +2579,7 @@ export async function overViewTable( req, res ) {
2566
2579
  const exportdata = [];
2567
2580
  result.forEach( ( element ) => {
2568
2581
  exportdata.push( {
2569
- 'Store Id': element.storeId,
2582
+ 'Store ID': element.storeId,
2570
2583
  'zoneName': element.zoneName,
2571
2584
  'File Date': element.fileDate,
2572
2585
  'Module Type': element.moduleType,
@@ -2584,7 +2597,7 @@ export async function overViewTable( req, res ) {
2584
2597
  return res.sendSuccess( { result: result, count: count.length } );
2585
2598
  } catch ( error ) {
2586
2599
  const err = error.message || 'Internal Server Error';
2587
- logger.error( { error: error, message: req.body, function: 'summarySplit' } );
2600
+ logger.error( { error: error, message: req.body, function: 'pendingSummaryTable' } );
2588
2601
  return res.sendError( err, 500 );
2589
2602
  }
2590
2603
  }
@@ -2638,7 +2651,7 @@ export async function overAllAuditSummary( req, res ) {
2638
2651
  },
2639
2652
  },
2640
2653
  ];
2641
- const auditClientData = await aggregateAuditStoreDataSchema( auditClientDataQuery );
2654
+ const auditClientData = await aggregateAuditStoreData( auditClientDataQuery );
2642
2655
  if ( auditClientData.length >0 ) {
2643
2656
  temp.auditStores = auditClientData[0].totalFilesCount;
2644
2657
  }
@@ -2786,8 +2799,9 @@ export async function reTrigger( req, res ) {
2786
2799
  triggerId: req.user._id,
2787
2800
  triggerType: inputData.triggerType,
2788
2801
  },
2802
+ createdAt: new Date(),
2789
2803
  };
2790
- await insertOpenSearchData( openSearch.activityLog, logData );
2804
+ await insertOpenSearchData( openSearch.auditLog, logData );
2791
2805
  }
2792
2806
  break;
2793
2807
  case 'user':
@@ -2800,7 +2814,7 @@ export async function reTrigger( req, res ) {
2800
2814
  moduleType: inputData.moduleType,
2801
2815
  fileDateISO: dayjs( new Date( ( inputData.fileDate ).split( '-' ).reverse().join( '-' ) ) ).format(),
2802
2816
  auditType: inputData.auditType,
2803
- fileCount: inputData.beforeCount,
2817
+ fileCount: inputData.totalCount,
2804
2818
  queueName: queueName,
2805
2819
  userId: inputData.userId,
2806
2820
  userName: assignUser.userName,
@@ -2846,8 +2860,9 @@ export async function reTrigger( req, res ) {
2846
2860
  triggerId: req.user._id,
2847
2861
  triggerType: inputData.triggerType,
2848
2862
  },
2863
+ createdAt: new Date(),
2849
2864
  };
2850
- await insertOpenSearchData( openSearch.activityLog, logData );
2865
+ await insertOpenSearchData( openSearch.auditLog, logData );
2851
2866
  }
2852
2867
 
2853
2868
  return res.sendSuccess( { result: 'The File has been Re Trigger Succesfully' } );
@@ -2867,6 +2882,7 @@ export async function overViewCard( req, res ) {
2867
2882
  ReAuditFileCount: 0,
2868
2883
  inprogressCount: 0,
2869
2884
  completedCount: 0,
2885
+ pendingCount: 0,
2870
2886
  };
2871
2887
 
2872
2888
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -2927,6 +2943,7 @@ export async function overViewCard( req, res ) {
2927
2943
  ReAuditFileCount: 1,
2928
2944
  inprogressCount: 1,
2929
2945
  completedCount: 1,
2946
+ notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
2930
2947
  },
2931
2948
  },
2932
2949
  ];
@@ -2944,14 +2961,13 @@ export async function summarySplit( req, res ) {
2944
2961
  try {
2945
2962
  const inputData = req.body;
2946
2963
  const temp = {
2947
- totalInprogress: 0,
2964
+ total: 0,
2948
2965
  auditInprogress: 0,
2949
2966
  reAuditInprogress: 0,
2950
2967
  draft: 0,
2951
2968
  assigned: 0,
2952
2969
  auditCompleted: 0,
2953
2970
  reAuditCompleted: 0,
2954
- completedCount: 0,
2955
2971
  };
2956
2972
 
2957
2973
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -2962,6 +2978,9 @@ export async function summarySplit( req, res ) {
2962
2978
  if ( inputData.clientId.length > 0 ) {
2963
2979
  filters.push( { clientId: { $in: inputData.clientId } } );
2964
2980
  }
2981
+ if ( inputData?.moduleType?.length > 0 ) {
2982
+ filters.push( { moduleType: { $in: inputData.moduleType } } );
2983
+ }
2965
2984
  const query =[
2966
2985
  {
2967
2986
  $match: {
@@ -2991,11 +3010,7 @@ export async function summarySplit( req, res ) {
2991
3010
  { $ne: [ '$status', 'assigned' ] }, 1, 0,
2992
3011
  ],
2993
3012
  },
2994
- completedCount: {
2995
- $cond: [
2996
- { $eq: [ '$status', 'completed' ] }, 1, 0,
2997
- ],
2998
- },
3013
+
2999
3014
  reAuditCompleted: {
3000
3015
  $cond: [
3001
3016
  { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
@@ -3011,15 +3026,12 @@ export async function summarySplit( req, res ) {
3011
3026
  {
3012
3027
  $group: {
3013
3028
  _id: { fileDate: '$fileDate', clientId: '$clientId' },
3014
- totalInprogress: { $sum: 1 },
3015
3029
  auditInprogress: { $sum: '$auditInprogress' },
3016
3030
  reAuditInprogress: { $sum: '$reAuditInprogress' },
3017
3031
  draft: { $sum: '$draft' },
3018
3032
  assigned: { $sum: 'assigned' },
3019
- completedCount: { $sum: '$completedCount' },
3020
3033
  reAuditCompleted: { $sum: '$reAuditCompleted' },
3021
3034
  auditCompleted: { $sum: '$auditCompleted' },
3022
- completedCount: { $sum: '$completedCount' },
3023
3035
 
3024
3036
  },
3025
3037
  },
@@ -3031,14 +3043,36 @@ export async function summarySplit( req, res ) {
3031
3043
  reAuditInprogress: 1,
3032
3044
  draft: 1,
3033
3045
  assigned: 1,
3034
- completedCount: 1,
3035
3046
  reAuditCompleted: 1,
3036
3047
  auditCompleted: 1,
3048
+ totalCount: { $ifNull: [ 0, 0 ] },
3049
+
3050
+ },
3051
+ },
3052
+ ];
3053
+ const totalQuery = [
3054
+ {
3055
+ $match: {
3056
+ $and: filters,
3057
+ },
3037
3058
 
3059
+ },
3060
+ {
3061
+ $group: {
3062
+ _id: null,
3063
+ total: { $sum: 1 },
3064
+ },
3065
+ },
3066
+ {
3067
+ $project: {
3068
+ _id: 0,
3069
+ total: 1,
3038
3070
  },
3039
3071
  },
3040
3072
  ];
3041
3073
  const result = await aggregateStoreAudit( query );
3074
+ const totalCount = await aggregateAuditStoreData( totalQuery );
3075
+ result[0].totalCount = totalCount[0]?.total? totalCount[0].total : delete result[0].totalCount;
3042
3076
  logger.info( { result: result } );
3043
3077
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
3044
3078
  } catch ( error ) {
@@ -3047,3 +3081,241 @@ export async function summarySplit( req, res ) {
3047
3081
  return res.sendError( err, 500 );
3048
3082
  }
3049
3083
  }
3084
+
3085
+ export async function overviewTable( req, res ) {
3086
+ try {
3087
+ const inputData = req.body;
3088
+ const limit = inputData.limit || 10;
3089
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
3090
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
3091
+ let filters =[
3092
+ { fileDateISO: { $gte: dateRange.start } },
3093
+ { fileDateISO: { $lte: dateRange.end } },
3094
+
3095
+ ];
3096
+
3097
+ if ( inputData.clientId.length > 0 ) {
3098
+ filters.push( { clientId: { $in: inputData.clientId } } );
3099
+ }
3100
+
3101
+ if ( inputData.filterByModuleType.length > 0 ) {
3102
+ filters.push( { moduleType: { $in: inputData.filterByModuleType } } );
3103
+ }
3104
+
3105
+ if ( inputData.filterByAuditType.length > 0 ) {
3106
+ filters.push( { auditType: { $in: inputData.filterByAuditType } } );
3107
+ }
3108
+
3109
+ if ( inputData.filterByStatus.length > 0 ) {
3110
+ filters.push( { status: { $in: inputData.filterByStatus } } );
3111
+ }
3112
+
3113
+ const query =[
3114
+ {
3115
+ $match: {
3116
+ $and: filters,
3117
+ },
3118
+
3119
+ },
3120
+ {
3121
+ $project: {
3122
+ _id: 0,
3123
+ storeId: 1,
3124
+ clientId: 1,
3125
+ zoneName: 1,
3126
+ fileDate: 1,
3127
+ moduleType: 1,
3128
+ beforeCount: 1,
3129
+ afterCount: 1,
3130
+ auditType: 1,
3131
+ status: 1,
3132
+ // userId: 1,
3133
+ },
3134
+ },
3135
+ // {
3136
+ // $lookup: {
3137
+ // from: 'users',
3138
+ // let: { userId: '$userId' },
3139
+ // pipeline: [
3140
+ // {
3141
+ // $match: {
3142
+ // $expr: {
3143
+ // $eq: [ '$_id', '$$userId' ],
3144
+ // },
3145
+ // },
3146
+ // },
3147
+ // {
3148
+ // $project: {
3149
+ // userName: 1,
3150
+ // userEmail: '$email',
3151
+ // },
3152
+ // },
3153
+ // ], as: 'user',
3154
+ // },
3155
+ // },
3156
+ // {
3157
+ // $unwind: {
3158
+ // path: '$user',
3159
+ // preserveNullAndEmptyArrays: true,
3160
+ // },
3161
+ // },
3162
+ {
3163
+ $project: {
3164
+ storeId: 1,
3165
+ clientId: 1,
3166
+ zoneName: 1,
3167
+ fileDate: 1,
3168
+ moduleType: 1,
3169
+ beforeCount: 1,
3170
+ afterCount: 1,
3171
+ auditType: 1,
3172
+ status: 1,
3173
+ // userName: '$user.userName',
3174
+ // userEmail: '$user.userEmail',
3175
+
3176
+ },
3177
+ },
3178
+ ];
3179
+ if ( inputData.searchValue && inputData.searchValue!== '' ) {
3180
+ query.push( {
3181
+ $match: {
3182
+ $or: [
3183
+ { storeId: { $regex: inputData.searchValue, $options: 'i' } },
3184
+ { clientId: { $regex: inputData.searchValue, $options: 'i' } },
3185
+ { fileDate: { $regex: inputData.searchValue, $options: 'i' } },
3186
+ { auditType: { $regex: inputData.searchValue, $options: 'i' } },
3187
+ { status: { $regex: inputData.searchValue, $options: 'i' } },
3188
+ { moduleType: { $regex: inputData.searchValue, $options: 'i' } },
3189
+ { zoneName: { $regex: inputData.searchValue, $options: 'i' } },
3190
+ // { userName: { $regex: inputData.searchValue, $options: 'i' } },
3191
+ // { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
3192
+ ],
3193
+
3194
+ },
3195
+ } );
3196
+ }
3197
+ if ( inputData.sortColumnName ) {
3198
+ const sortBy = inputData.sortBy || -1;
3199
+ query.push( {
3200
+ $sort: { [inputData.sortColumName]: sortBy },
3201
+ },
3202
+ );
3203
+ }
3204
+ const count = await aggregateStoreAudit( query );
3205
+ if ( count.length == 0 ) {
3206
+ return res.sendError( 'No Data Found', 204 );
3207
+ }
3208
+
3209
+ if ( inputData.isExport ) {
3210
+ query.push( { $limit: 10000 } );
3211
+ } else {
3212
+ query.push( {
3213
+ $skip: offset,
3214
+ },
3215
+ {
3216
+ $limit: limit,
3217
+ } );
3218
+ }
3219
+
3220
+ const result = await aggregateStoreAudit( query );
3221
+ if ( inputData.isExport ) {
3222
+ const exportdata = [];
3223
+ result.forEach( ( element ) => {
3224
+ exportdata.push( {
3225
+ 'Store ID': element.storeId,
3226
+ 'Client ID': element.clientId,
3227
+ 'zoneName': element.zoneName,
3228
+ 'File Date': element.fileDate,
3229
+ 'Module Type': element.moduleType,
3230
+ 'Audit Type': element.auditType,
3231
+ 'Before Count': element.beforeCount,
3232
+ 'After Count': element.afterCount,
3233
+ 'Start Time': element.startTime,
3234
+ 'End Time': element.endTime,
3235
+ // 'User Name': element.userName,
3236
+ // 'User Email': element.userEmail,
3237
+ 'Status': element.auditStatus,
3238
+ } );
3239
+ } );
3240
+ await download( exportdata, res );
3241
+ return;
3242
+ }
3243
+ return res.sendSuccess( { result: result, count: count.length } );
3244
+ } catch ( error ) {
3245
+ const err = error.message || 'Internal Server Error';
3246
+ logger.error( { error: error, message: req.body, function: 'overviewTable' } );
3247
+ return res.sendError( err, 500 );
3248
+ }
3249
+ }
3250
+
3251
+
3252
+ export async function auditImages( req, res ) {
3253
+ try {
3254
+ const inputData = req.query;
3255
+ let auditImageDownload = '';
3256
+ switch ( inputData.imageType ) {
3257
+ case 'BC':
3258
+ const auditImageBC = await getAuditImageData( inputData );
3259
+ if ( auditImageBC?.errorCode ) {
3260
+ const error = auditImageBC?.error || 'Internal Server Error- get BC from Bucket';
3261
+ const code = auditImageBC?.errorCode;
3262
+ return res.sendError( { error: error }, code );
3263
+ }
3264
+ if ( auditImageBC?.length == 0 ) {
3265
+ return res.sendError( 'No Data Found', 204 );
3266
+ }
3267
+
3268
+ if ( inputData.export==true ) {
3269
+ auditImageDownload= await zipDownloadImage( auditImageBC );
3270
+ // Set response headers for the zip file
3271
+ res.set( 'Content-Type', 'application/zip' );
3272
+ res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
3273
+
3274
+ // Send the zip file as the API response
3275
+ return res.send( auditImageDownload );
3276
+ }
3277
+ res.sendSuccess( { result: auditImageBC } );
3278
+
3279
+ break;
3280
+
3281
+ case 'AC':
3282
+
3283
+ const [ filterData, auditImageAC ] = await Promise.all( [ getAuditFilterData( inputData ), getAuditImageData( inputData ) ] );
3284
+
3285
+ if ( filterData?.errorCode || auditImageAC?.errorCode ) {
3286
+ const error = ( filterData?.error || auditImageAC.error ) || 'Internal Server Error- get AC from Bucket';
3287
+ const code = filterData?.errorCode || auditImageAC.errorCode;
3288
+ return res.sendError( { error: error }, code );
3289
+ }
3290
+
3291
+ const reauditImg = await getReauditImg( filterData, auditImageAC );
3292
+ logger.info( { reauditImg: reauditImg } );
3293
+ if ( reauditImg?.length == 0 ) {
3294
+ return res.sendError( 'No Data Found', 204 );
3295
+ }
3296
+
3297
+ logger.info( { auditImageAC: auditImageAC, filterData: filterData, reauditImg: reauditImg } );
3298
+ if ( inputData.export==true ) {
3299
+ auditImageDownload= await zipDownloadImage( reauditImg );
3300
+ // Set response headers for the zip file
3301
+ res.set( 'Content-Type', 'application/zip' );
3302
+ res.set( 'Content-Disposition', `attachment; filename=${inputData.storeId}_${inputData.fileDate}_${inputData.imageType}.zip` );
3303
+
3304
+ // Send the zip file as the API response
3305
+ return res.send( auditImageDownload );
3306
+ }
3307
+ res.sendSuccess( { result: reauditImg } );
3308
+ break;
3309
+ default:
3310
+ res.sendError( 'No Data Found', 204 );
3311
+ break;
3312
+ }
3313
+
3314
+
3315
+ // return res.sendSuccess( { result: inputData } );
3316
+ } catch ( error ) {
3317
+ const err = error.message || 'Internal Server Error';
3318
+ logger.info( { error: error, message: req.body, function: 'beforeCountImages' } );
3319
+ return res.sendError( err, 500 );
3320
+ }
3321
+ }
@@ -1,4 +1,4 @@
1
- import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, overViewTableSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema } from '../dtos/audit.dtos.js';
1
+ import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema, pendingSummaryTableSchema, overviewTableSchema } from '../dtos/audit.dtos.js';
2
2
  import j2s from 'joi-to-swagger';
3
3
 
4
4
  export const auditDocs = {
@@ -170,6 +170,24 @@ export const auditDocs = {
170
170
  in: 'query',
171
171
  name: 'storeId',
172
172
  scema: j2s( getDraftedDataSchema ).swagger,
173
+ require: true,
174
+ },
175
+ {
176
+ in: 'query',
177
+ name: 'moduleType',
178
+ scema: j2s( getDraftedDataSchema ).swagger,
179
+ require: true,
180
+ },
181
+ {
182
+ in: 'query',
183
+ name: 'zoneName',
184
+ scema: j2s( getDraftedDataSchema ).swagger,
185
+ require: true,
186
+ },
187
+ {
188
+ in: 'query',
189
+ name: 'userId',
190
+ scema: j2s( getDraftedDataSchema ).swagger,
173
191
  require: false,
174
192
  },
175
193
  ],
@@ -353,6 +371,29 @@ export const auditDocs = {
353
371
  },
354
372
  },
355
373
  },
374
+ '/v3/audit/metrics/pending-summary-table': {
375
+ post: {
376
+ tags: [ 'Audit Metrics' ],
377
+ description: `Get overall user taken data with some filters `,
378
+ operationId: 'metrics/pending-summary-table',
379
+ parameters: {},
380
+ requestBody: {
381
+ content: {
382
+ 'application/json': {
383
+ schema: j2s( pendingSummaryTableSchema ).swagger,
384
+ },
385
+ },
386
+ },
387
+ responses: {
388
+ 200: { description: 'Successful' },
389
+ 401: { description: 'Unauthorized User' },
390
+ 422: { description: 'Field Error' },
391
+ 500: { description: 'Server Error' },
392
+ 204: { description: 'Not Found' },
393
+ },
394
+ },
395
+ },
396
+
356
397
  '/v3/audit/metrics/overview-table': {
357
398
  post: {
358
399
  tags: [ 'Audit Metrics' ],
@@ -362,7 +403,7 @@ export const auditDocs = {
362
403
  requestBody: {
363
404
  content: {
364
405
  'application/json': {
365
- schema: j2s( overViewTableSchema ).swagger,
406
+ schema: j2s( overviewTableSchema ).swagger,
366
407
  },
367
408
  },
368
409
  },