tango-app-api-audit 3.3.0-alpha.0 → 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.0",
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 ) {
@@ -1339,6 +1345,7 @@ export async function save( req, res ) {
1339
1345
  QueueUrl: `${sqs.url}${queueName}`,
1340
1346
  MessageBody: JSON.stringify( {
1341
1347
  store_id: inputData.storeId,
1348
+ zone_id: inputData.zoneName,
1342
1349
  audit_type: 'ReAudit',
1343
1350
  curr_date: inputData.fileDate,
1344
1351
  total_count: inputData.customerCount,
@@ -1631,9 +1638,9 @@ export async function userAuditHistory( req, res ) {
1631
1638
  chunk.forEach( ( element ) => {
1632
1639
  exportData.push( {
1633
1640
 
1634
- 'Client Id': element.clientId,
1641
+ 'Client ID': element.clientId,
1635
1642
  'Client Name': element.clientName,
1636
- 'Store Id': element.storeId,
1643
+ 'Store ID': element.storeId,
1637
1644
  'Store Name': element.storeName,
1638
1645
  'Zone Name': element.zoneName,
1639
1646
  'Audit Type': element.auditType,
@@ -1850,7 +1857,7 @@ export async function clientMetrics( req, res ) {
1850
1857
  );
1851
1858
  }
1852
1859
 
1853
- const count = await aggregateAuditStoreDataSchema( query );
1860
+ const count = await aggregateAuditStoreData( query );
1854
1861
  if ( count.length == 0 ) {
1855
1862
  return res.sendError( 'No Data Found', 204 );
1856
1863
  }
@@ -1882,7 +1889,7 @@ export async function clientMetrics( req, res ) {
1882
1889
  }
1883
1890
 
1884
1891
  logger.info( { query: query } );
1885
- const result = await aggregateAuditStoreDataSchema( query );
1892
+ const result = await aggregateAuditStoreData( query );
1886
1893
  if ( result.length == 0 ) {
1887
1894
  return res.sendError( 'No Data Found', 204 );
1888
1895
  }
@@ -2144,7 +2151,7 @@ export async function storeMetrics( req, res ) {
2144
2151
  result.forEach( ( element ) => {
2145
2152
  exportdata.push( {
2146
2153
  'File Date': element.fileDate,
2147
- 'Store Id': element.storeId,
2154
+ 'Store ID': element.storeId,
2148
2155
  'Store Name': element.storeName,
2149
2156
  'Client Id': element.clientId,
2150
2157
  'Client Name': element.clientName,
@@ -2434,7 +2441,7 @@ export async function userMetrics( req, res ) {
2434
2441
  }
2435
2442
  }
2436
2443
 
2437
- export async function overViewTable( req, res ) {
2444
+ export async function pendingSummaryTable( req, res ) {
2438
2445
  try {
2439
2446
  const inputData = req.body;
2440
2447
  const limit = inputData.limit || 10;
@@ -2473,7 +2480,13 @@ export async function overViewTable( req, res ) {
2473
2480
  fileDate: 1,
2474
2481
  moduleType: 1,
2475
2482
  beforeCount: 1,
2476
- startTime: 1,
2483
+ startTime: { $dateToString: {
2484
+ format: '%Y-%m-%d %H:%M:%S',
2485
+ date: '$startTime',
2486
+ timezone: 'Asia/Kolkata',
2487
+ },
2488
+
2489
+ },
2477
2490
  auditType: 1,
2478
2491
  auditStatus: 1,
2479
2492
  userId: 1,
@@ -2514,6 +2527,7 @@ export async function overViewTable( req, res ) {
2514
2527
  moduleType: 1,
2515
2528
  beforeCount: 1,
2516
2529
  startTime: 1,
2530
+ endTime: 1,
2517
2531
  auditType: 1,
2518
2532
  auditStatus: 1,
2519
2533
  userName: '$user.userName',
@@ -2565,7 +2579,7 @@ export async function overViewTable( req, res ) {
2565
2579
  const exportdata = [];
2566
2580
  result.forEach( ( element ) => {
2567
2581
  exportdata.push( {
2568
- 'Store Id': element.storeId,
2582
+ 'Store ID': element.storeId,
2569
2583
  'zoneName': element.zoneName,
2570
2584
  'File Date': element.fileDate,
2571
2585
  'Module Type': element.moduleType,
@@ -2583,7 +2597,7 @@ export async function overViewTable( req, res ) {
2583
2597
  return res.sendSuccess( { result: result, count: count.length } );
2584
2598
  } catch ( error ) {
2585
2599
  const err = error.message || 'Internal Server Error';
2586
- logger.error( { error: error, message: req.body, function: 'summarySplit' } );
2600
+ logger.error( { error: error, message: req.body, function: 'pendingSummaryTable' } );
2587
2601
  return res.sendError( err, 500 );
2588
2602
  }
2589
2603
  }
@@ -2637,7 +2651,7 @@ export async function overAllAuditSummary( req, res ) {
2637
2651
  },
2638
2652
  },
2639
2653
  ];
2640
- const auditClientData = await aggregateAuditStoreDataSchema( auditClientDataQuery );
2654
+ const auditClientData = await aggregateAuditStoreData( auditClientDataQuery );
2641
2655
  if ( auditClientData.length >0 ) {
2642
2656
  temp.auditStores = auditClientData[0].totalFilesCount;
2643
2657
  }
@@ -2785,8 +2799,9 @@ export async function reTrigger( req, res ) {
2785
2799
  triggerId: req.user._id,
2786
2800
  triggerType: inputData.triggerType,
2787
2801
  },
2802
+ createdAt: new Date(),
2788
2803
  };
2789
- await insertOpenSearchData( openSearch.activityLog, logData );
2804
+ await insertOpenSearchData( openSearch.auditLog, logData );
2790
2805
  }
2791
2806
  break;
2792
2807
  case 'user':
@@ -2799,7 +2814,7 @@ export async function reTrigger( req, res ) {
2799
2814
  moduleType: inputData.moduleType,
2800
2815
  fileDateISO: dayjs( new Date( ( inputData.fileDate ).split( '-' ).reverse().join( '-' ) ) ).format(),
2801
2816
  auditType: inputData.auditType,
2802
- fileCount: inputData.beforeCount,
2817
+ fileCount: inputData.totalCount,
2803
2818
  queueName: queueName,
2804
2819
  userId: inputData.userId,
2805
2820
  userName: assignUser.userName,
@@ -2845,8 +2860,9 @@ export async function reTrigger( req, res ) {
2845
2860
  triggerId: req.user._id,
2846
2861
  triggerType: inputData.triggerType,
2847
2862
  },
2863
+ createdAt: new Date(),
2848
2864
  };
2849
- await insertOpenSearchData( openSearch.activityLog, logData );
2865
+ await insertOpenSearchData( openSearch.auditLog, logData );
2850
2866
  }
2851
2867
 
2852
2868
  return res.sendSuccess( { result: 'The File has been Re Trigger Succesfully' } );
@@ -2866,6 +2882,7 @@ export async function overViewCard( req, res ) {
2866
2882
  ReAuditFileCount: 0,
2867
2883
  inprogressCount: 0,
2868
2884
  completedCount: 0,
2885
+ pendingCount: 0,
2869
2886
  };
2870
2887
 
2871
2888
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -2926,6 +2943,7 @@ export async function overViewCard( req, res ) {
2926
2943
  ReAuditFileCount: 1,
2927
2944
  inprogressCount: 1,
2928
2945
  completedCount: 1,
2946
+ notAssigned: { $subtract: [ '$totalCount', { $add: [ '$inprogressCount', '$completedCount' ] } ] },
2929
2947
  },
2930
2948
  },
2931
2949
  ];
@@ -2943,14 +2961,13 @@ export async function summarySplit( req, res ) {
2943
2961
  try {
2944
2962
  const inputData = req.body;
2945
2963
  const temp = {
2946
- totalInprogress: 0,
2964
+ total: 0,
2947
2965
  auditInprogress: 0,
2948
2966
  reAuditInprogress: 0,
2949
2967
  draft: 0,
2950
2968
  assigned: 0,
2951
2969
  auditCompleted: 0,
2952
2970
  reAuditCompleted: 0,
2953
- completedCount: 0,
2954
2971
  };
2955
2972
 
2956
2973
  const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
@@ -2961,6 +2978,9 @@ export async function summarySplit( req, res ) {
2961
2978
  if ( inputData.clientId.length > 0 ) {
2962
2979
  filters.push( { clientId: { $in: inputData.clientId } } );
2963
2980
  }
2981
+ if ( inputData?.moduleType?.length > 0 ) {
2982
+ filters.push( { moduleType: { $in: inputData.moduleType } } );
2983
+ }
2964
2984
  const query =[
2965
2985
  {
2966
2986
  $match: {
@@ -2990,11 +3010,7 @@ export async function summarySplit( req, res ) {
2990
3010
  { $ne: [ '$status', 'assigned' ] }, 1, 0,
2991
3011
  ],
2992
3012
  },
2993
- completedCount: {
2994
- $cond: [
2995
- { $eq: [ '$status', 'completed' ] }, 1, 0,
2996
- ],
2997
- },
3013
+
2998
3014
  reAuditCompleted: {
2999
3015
  $cond: [
3000
3016
  { $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
@@ -3010,15 +3026,12 @@ export async function summarySplit( req, res ) {
3010
3026
  {
3011
3027
  $group: {
3012
3028
  _id: { fileDate: '$fileDate', clientId: '$clientId' },
3013
- totalInprogress: { $sum: 1 },
3014
3029
  auditInprogress: { $sum: '$auditInprogress' },
3015
3030
  reAuditInprogress: { $sum: '$reAuditInprogress' },
3016
3031
  draft: { $sum: '$draft' },
3017
3032
  assigned: { $sum: 'assigned' },
3018
- completedCount: { $sum: '$completedCount' },
3019
3033
  reAuditCompleted: { $sum: '$reAuditCompleted' },
3020
3034
  auditCompleted: { $sum: '$auditCompleted' },
3021
- completedCount: { $sum: '$completedCount' },
3022
3035
 
3023
3036
  },
3024
3037
  },
@@ -3030,14 +3043,36 @@ export async function summarySplit( req, res ) {
3030
3043
  reAuditInprogress: 1,
3031
3044
  draft: 1,
3032
3045
  assigned: 1,
3033
- completedCount: 1,
3034
3046
  reAuditCompleted: 1,
3035
3047
  auditCompleted: 1,
3048
+ totalCount: { $ifNull: [ 0, 0 ] },
3036
3049
 
3037
3050
  },
3038
3051
  },
3039
3052
  ];
3053
+ const totalQuery = [
3054
+ {
3055
+ $match: {
3056
+ $and: filters,
3057
+ },
3058
+
3059
+ },
3060
+ {
3061
+ $group: {
3062
+ _id: null,
3063
+ total: { $sum: 1 },
3064
+ },
3065
+ },
3066
+ {
3067
+ $project: {
3068
+ _id: 0,
3069
+ total: 1,
3070
+ },
3071
+ },
3072
+ ];
3040
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;
3041
3076
  logger.info( { result: result } );
3042
3077
  return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
3043
3078
  } catch ( error ) {
@@ -3046,3 +3081,241 @@ export async function summarySplit( req, res ) {
3046
3081
  return res.sendError( err, 500 );
3047
3082
  }
3048
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
  },