tango-app-api-audit 3.4.18 → 3.4.20

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.18",
3
+ "version": "3.4.20",
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.1.53",
28
- "tango-app-api-middleware": "^3.1.33",
27
+ "tango-api-schema": "^2.2.12",
28
+ "tango-app-api-middleware": "^3.1.48",
29
29
  "winston": "^3.13.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -3917,11 +3917,23 @@ export async function getUserCredit( req, res ) {
3917
3917
 
3918
3918
  export async function getUserAuditCount( req, res ) {
3919
3919
  try {
3920
- for ( let i =4; i<15; i++ ) {
3920
+ // const options = { timeZone: 'Asia/Kolkata', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' };
3921
+ // const istTime = new Intl.DateTimeFormat( 'en-IN', options ).format( new Date( '' ) );
3922
+
3923
+ // // Get the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
3924
+ // const dayOfWeek = istTime.getDay();
3925
+
3926
+ // // Check if today is Monday (if weeks start on Monday)
3927
+ // const isFirstDay = dayOfWeek === 1; // Monday = 1
3928
+ // logger.info( { isFirstDay: isFirstDay } );
3929
+ // if ( isFirstDay ) {
3930
+ // await updateManyAuditUsers( {}, { lateLogin: 0 } );
3931
+ // }
3932
+ for ( let i =1; i<7; i++ ) {
3921
3933
  const userWallet = JSON.parse( process.env.USER_WALLET );
3922
3934
  const previousDate = dayjs( new Date() ).subtract( i, 'days' );
3923
3935
  const fileDate = dayjs( previousDate ).format( 'DD-MM-YYYY' );
3924
- const configTimeSpentSec = userWallet.minTimeSpentSec; // 18000;
3936
+ const configTimeSpentSec = userWallet.minTimeSpentSec; // 21600 seconds / 6 hours;
3925
3937
  // const beforeCountX = userWallet.beforeCountCreditPerc; // 0.0335;
3926
3938
  // const afterCountY = userWallet.afterCountCreditPerc; // 0.0035;
3927
3939
  const reduce = userWallet.reductionPerc; // 0.05;
@@ -4312,7 +4324,7 @@ export async function getUserAuditCount( req, res ) {
4312
4324
  if ( result.length == 0 ) {
4313
4325
  return res.sendError( 'No Record Inserted', 500 );
4314
4326
  }
4315
- if ( i == 14 ) {
4327
+ if ( i == 6 ) {
4316
4328
  return res.sendSuccess( { message: 'Inserted successfully!' } );
4317
4329
  }
4318
4330
  }
@@ -17,454 +17,6 @@ import {
17
17
  findOneUserEmpDetection,
18
18
  } from '../service/userEmpDetection.service.js';
19
19
  import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.service.js';
20
- // export async function getDetectionAuditFile( req, res ) {
21
- // try {
22
- // const bucket = JSON.parse( process.env.BUCKET );
23
- // const openSearch = JSON.parse( process.env.OPENSEARCH );
24
- // const inputData = req.query;
25
- // const previousDate = new Date( new Date() - 1 );
26
- // const data = await getDate( previousDate, new Date() );
27
- // logger.info( { data: data, function: 'data', newDate: new Date() } );
28
- // logger.info( { userId: req.user._id, queueName: inputData.queueName, moduleType: inputData.moduleType } );
29
- // const start = data.start;
30
- // const end = data.end;
31
- // const fetchData = {};
32
- // let msg = {};
33
- // const userQuery = [
34
- // {
35
- // $match: {
36
- // $and: [
37
- // { userId: req.user._id },
38
- // { queueName: inputData.queueName },
39
- // { auditStatus: { $nin: [ 'completed', 'skipped' ] } },
40
- // { createdAt: { $gte: start } },
41
- // { createdAt: { $lte: end } },
42
- // { moduleType: inputData.moduleType },
43
- // ],
44
- // },
45
- // },
46
- // {
47
- // $sort: { createdAt: -1 },
48
- // },
49
- // {
50
- // $limit: 1,
51
- // },
52
- // ];
53
-
54
- // const userDetails = await aggregateUserEmpDetection( userQuery );
55
- // logger.info( { userDetails: userDetails, function: 'userDetails' } );
56
- // const auditStatus =
57
- // userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
58
- // switch ( auditStatus ) {
59
- // case null:
60
- // const query = [
61
- // {
62
- // $match: {
63
- // $and: [
64
- // { userId: { $eq: req.user._id } },
65
- // { isCompleted: { $eq: false } },
66
- // { queueName: inputData.queueName },
67
- // { moduleType: inputData.moduleType },
68
- // ],
69
- // },
70
- // },
71
- // ];
72
- // const userAssign = await aggregateAssignAudit( query );
73
- // if ( userAssign.length > 0 ) {
74
- // logger.info( 'Hit in user assign', { inputData } );
75
- // userAssign[0].auditType == 'Audit' ?
76
- // ( msg = {
77
- // store_id: userAssign[0].storeId,
78
- // curr_date: userAssign[0].fileDate,
79
- // total_count: userAssign[0].fileCount,
80
- // zone_id: userAssign[0].zoneName,
81
- // } ) :
82
- // ( msg = {
83
- // store_id: userAssign[0].storeId,
84
- // curr_date: userAssign[0].fileDate,
85
- // audit_type: userAssign[0].auditType,
86
- // total_count: userAssign[0].fileCount,
87
- // zone_id: userAssign[0].zoneName,
88
- // } );
89
- // await updateOneAssignAudit(
90
- // { _id: userAssign[0]._id },
91
- // { isCompleted: true },
92
- // );
93
- // logger.info( 'Hit in auditUserAssignModel updateOne', {
94
- // _id: userAssign[0]._id,
95
- // isCompleted: true,
96
- // } );
97
- // } else {
98
- // logger.info( 'Hit in new file', { inputData } );
99
- // const consumer = await sqsReceive( inputData.queueName );
100
- // if ( !consumer ) {
101
- // logger.error( {
102
- // error: consumer,
103
- // function: 'getAuditFile',
104
- // message: 'SQS Receive queue is empty',
105
- // } );
106
- // return res.sendError( `${inputData.queueName} is Empty`, 204 );
107
- // }
108
- // msg = JSON.parse( consumer );
109
- // }
110
- // break;
111
-
112
- // case 'drafted':
113
- // logger.info( 'userDetails drafted', { inputData } );
114
- // const log = await findOneAuditLog(
115
- // {
116
- // userId: userDetails[0].userId,
117
- // fileDate: userDetails[0].fileDate,
118
- // storeId: userDetails[0].storeId,
119
- // totalCount: userDetails[0].beforeCount,
120
- // moduleType: userDetails[0].moduleType,
121
- // zoneName: userDetails[0].zoneName,
122
- // },
123
- // {},
124
- // { createdAt: -1 },
125
- // );
126
- // if ( !log ) {
127
- // await updateOneUserAudit(
128
- // { _id: userDetails[0]._id },
129
- // { $set: { isDraft: false, auditStatus: 'skipped' } },
130
- // );
131
- // logger.info( 'audit update in drafted', {
132
- // _id: userDetails[0]._id,
133
- // isDraft: false,
134
- // auditStatus: 'skipped',
135
- // } );
136
- // return res.sendError( 'User saved data has been deleted', 204 );
137
- // }
138
- // const file = {
139
- // auditId: userDetails[0]._id,
140
- // store_id: userDetails[0].storeId,
141
- // file_date: userDetails[0].fileDate,
142
- // type: userDetails[0].auditType,
143
- // queueName: log.queueName,
144
- // userId: log.userId,
145
- // moduleType: userDetails[0].moduleType,
146
- // zoneName: userDetails[0].zoneName,
147
- // };
148
- // const result = {
149
- // junk: log.junk,
150
- // junk_count: log.junkCount,
151
- // employee: log.employee,
152
- // employee_count: log.employeeCount,
153
- // customer: log.customer,
154
- // customer_count: log.customerCount,
155
- // retag_image: log.retagImage,
156
- // retag_count: log.retagCount,
157
- // total_count: log.totalCount,
158
- // };
159
-
160
- // const userdata = await findOneUser( { _id: log.userId } );
161
- // if (
162
- // !inputData.nextId ||
163
- // inputData.nextId === '' ||
164
- // inputData.nextId == null
165
- // ) {
166
- // const logData = {
167
- // userId: log.userId,
168
- // userName: userdata.name,
169
- // logType: 'audit',
170
- // logSubType: 'auditStart',
171
- // logData: {
172
- // fileDate: userDetails[0].fileDate,
173
- // auditType: userDetails[0].auditType,
174
- // storeId: userDetails[0].storeId,
175
- // clientName: log.queueName,
176
- // auditId: userDetails[0]._id,
177
- // moduleType: userDetails[0].moduleType,
178
- // zoneName: userDetails[0].zoneName,
179
- // },
180
- // createdAt: new Date(),
181
- // };
182
- // logger.info( { logData: logData } );
183
- // await insertOpenSearchData( openSearch.auditLog, logData );
184
- // }
185
- // const storeQuery = {
186
- // storeId: userDetails[0].storeId,
187
- // };
188
- // const storeFields = {
189
- // storeId: 1,
190
- // storeName: 1,
191
- // address: '$storeProfile.address',
192
- // };
193
- // const storeDetails = await findOneStore( storeQuery, storeFields );
194
- // res.sendSuccess( {
195
- // result: result,
196
- // storeId: storeDetails?.storeId,
197
- // storeName: storeDetails?.storeName,
198
- // address: storeDetails?.address || '',
199
- // count: log.totalCount,
200
- // file: file,
201
- // isDraft: userDetails[0].isDraft,
202
- // } );
203
- // break;
204
-
205
- // default:
206
- // msg = {
207
- // store_id: userDetails[0].storeId,
208
- // curr_date: userDetails[0].fileDate,
209
- // audit_type: userDetails[0].auditType,
210
- // total_count: userDetails[0].beforeCount,
211
- // zone_id: userDetails[0].zoneName,
212
- // };
213
- // break;
214
- // }
215
- // if ( msg.audit_type === 'ReAudit' ) {
216
- // logger.info( 'Hit in user ReAudit', { inputData } );
217
- // let reauditInsert = {};
218
- // const [ filterData, auditImage ] = await Promise.all( [
219
- // getFilterData( msg ),
220
- // getAuditImage( msg ),
221
- // ] );
222
- // if ( filterData.statusCode == 404 || auditImage.statusCode == 404 ) {
223
- // return res.sendError( 'No Data found', 204 );
224
- // }
225
- // const reauditImg = await getReauditImg( filterData, auditImage );
226
- // if ( userDetails.length === 0 ) {
227
- // const [ day, month, year ] = msg.curr_date.split( '-' );
228
- // const temp = `${year}-${month}-${day}`;
229
- // let start = new Date( temp );
230
- // const userTimezoneOffset = start.getTimezoneOffset() * 60000;
231
- // start = new Date( start.getTime() - userTimezoneOffset );
232
- // start.setUTCHours( 0, 0, 0, 0 );
233
- // const record = {
234
- // userId: req.user._id,
235
- // storeId: msg.store_id,
236
- // clientId: msg.store_id.split( '-' )[0],
237
- // auditType: msg.audit_type || 'ReAudit',
238
- // fileDate: msg.curr_date,
239
- // queueName: inputData.queueName,
240
- // beforeCount: reauditImg.length,
241
- // auditStatus: 'inprogress',
242
- // fileDateISO: start,
243
- // timeSpent: 0,
244
- // startTime: new Date(),
245
- // zoneName: msg.zone_id,
246
- // moduleType: inputData.moduleType,
247
- // };
248
- // const query ={
249
- // storeId: msg.store_id,
250
- // zoneName: msg.zone_id,
251
- // fileDate: msg.curr_date,
252
- // moduleType: inputData.moduleType,
253
- // };
254
- // let storeRecord = {
255
- // userId: req.user._id,
256
- // auditType: msg.audit_type || 'ReAudit',
257
- // status: 'inprogress',
258
- // timeSpent: 0,
259
- // };
260
- // reauditInsert = await createUserAudit( record );
261
-
262
- // await updateOneStoreAudit( query, storeRecord );
263
- // } else {
264
- // reauditInsert = userDetails[0];
265
- // }
266
- // const userdata = await findOneUser( { _id: req.user._id } );
267
- // if ( inputData.nextId ) {
268
- // const logData = {
269
- // userId: req.user._id,
270
- // userName: userdata.name,
271
- // logType: 'audit',
272
- // logSubType: 'auditStart',
273
- // logData: {
274
- // fileDate: msg.curr_date,
275
- // auditType: msg.audit_type,
276
- // storeId: msg.store_id,
277
- // clientName: inputData.queueName,
278
- // auditId: reauditInsert._id,
279
- // zoneName: msg.zone_id,
280
- // moduleType: inputData.moduleType,
281
- // },
282
- // createdAt: new Date(),
283
- // };
284
- // await insertOpenSearchData( openSearch.auditLog, logData );
285
- // }
286
-
287
- // const storeQuery = {
288
- // storeId: msg.store_id,
289
- // };
290
- // const storeFields = {
291
- // storeId: 1,
292
- // storeName: 1,
293
- // address: '$storeProfile.address',
294
- // };
295
- // const storeInfo = await findOneStore( storeQuery, storeFields );
296
- // return res.sendSuccess( {
297
- // result: reauditImg,
298
- // count: reauditImg.length,
299
- // storeId: storeInfo?.storeId,
300
- // storeName: storeInfo?.storeName,
301
- // address: storeInfo?.address || '',
302
- // file: {
303
- // store_id: msg.store_id,
304
- // file_date: msg.curr_date,
305
- // type: msg.audit_type || 'ReAudit',
306
- // queueName: inputData.queueName,
307
- // auditId: reauditInsert._id,
308
- // userId: reauditInsert.userId,
309
- // zoneName: msg.zone_id,
310
- // moduleType: inputData.moduleType,
311
- // },
312
- // isDraft: reauditInsert.isDraft,
313
- // } );
314
- // }
315
- // const storeId = msg.store_id;
316
- // const fileDate = msg.curr_date;
317
-
318
- // const files = [];
319
- // let insertData = {};
320
- // fetchData.Bucket = bucket.auditInput; // need to change
321
- // fetchData.file_path = `${fileDate}/${storeId}/${msg.zone_id}/`;
322
- // if ( inputData.limit ) {
323
- // fetchData.MaxKeys = inputData.limit;
324
- // }
325
- // if ( inputData.nextId ) {
326
- // fetchData.ContinuationToken = decodeURIComponent( inputData.nextId );
327
- // }
328
- // const list = await listFileByPath( fetchData );
329
- // const folderPath = list.data;
330
- // const nextQuery = list.pageToken;
331
- // if ( folderPath?.length > 0 ) {
332
- // for ( let i = 0; i < folderPath.length; i++ ) {
333
- // const img = folderPath[i].Key.split( '/' );
334
- // const image = img[3].split( '.' );
335
- // const indexes = image[0].split( '_' );
336
- // fetchData.file_path = folderPath[i].Key;
337
- // const data = await signedUrl( fetchData );
338
- // const mapimg = {
339
- // img_path: data,
340
- // img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
341
- // img_id: img[3],
342
- // };
343
- // files.push( {
344
- // img_path: data,
345
- // img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
346
- // img_id: img[3],
347
- // selected: false,
348
- // dropped: false,
349
- // singleDetection: false,
350
- // count: 1,
351
- // mappedid: [ mapimg ],
352
- // } );
353
- // }
354
- // if ( userDetails.length === 0 ) {
355
- // const [ day, month, year ] = msg.curr_date.split( '-' );
356
- // const temp = `${year}-${month}-${day}`;
357
- // let start = new Date( temp );
358
- // logger.info( { start: start, date: msg.curr_date } );
359
- // const userTimezoneOffset = start.getTimezoneOffset() * 60000;
360
- // start = new Date( start.getTime() - userTimezoneOffset );
361
- // start.setUTCHours( 0, 0, 0, 0 );
362
- // const record = {
363
- // userId: req.user._id,
364
- // storeId: msg.store_id,
365
- // clientId: msg.store_id.split( '-' )[0],
366
- // auditType: 'Audit',
367
- // fileDate: msg.curr_date,
368
- // queueName: inputData.queueName,
369
- // beforeCount: msg.total_count || files.length,
370
- // auditStatus: 'inprogress',
371
- // fileDateISO: start,
372
- // timeSpent: 0,
373
- // startTime: new Date(),
374
- // zoneName: msg.zone_id,
375
- // moduleType: inputData.moduleType,
376
- // };
377
- // const query ={
378
- // storeId: msg.store_id,
379
- // zoneName: msg.zone_id,
380
- // fileDate: msg.curr_date,
381
- // moduleType: inputData.moduleType,
382
- // };
383
- // const storeRecord = {
384
- // userId: req.user._id,
385
- // storeId: msg.store_id,
386
- // clientId: msg.store_id.split( '-' )[0],
387
- // auditType: 'Audit',
388
- // fileDate: msg.curr_date,
389
- // queueName: inputData.queueName,
390
- // beforeCount: msg.total_count || files.length,
391
- // status: 'inprogress',
392
- // fileDateISO: start,
393
- // timeSpent: 0,
394
- // zoneName: msg.zone_id,
395
- // moduleType: inputData.moduleType,
396
- // };
397
-
398
- // insertData = await createUserEmpDetection( record );
399
- // await updateManyStoreEmpDetection( query, storeRecord );
400
- // } else {
401
- // insertData = userDetails[0];
402
- // }
403
- // } else {
404
- // logger.error( {
405
- // error: { folderPath: folderPath, nextQuery: nextQuery },
406
- // function: 'getAuditFile',
407
- // message: 'Bucket image data not availale',
408
- // } );
409
- // return res.sendError( 'Bucket is Empty', 204 );
410
- // }
411
- // const userdata = await findOneUser( { _id: insertData.userId } );
412
- // const storeQuery = {
413
- // storeId: storeId,
414
- // };
415
- // const storeFields = {
416
- // storeName: 1,
417
- // address: '$storeProfile.address',
418
- // };
419
- // const storeInfo = await findOneStore( storeQuery, storeFields );
420
- // if ( inputData.nextId ) {
421
- // const logData = {
422
- // userId: insertData.userId,
423
- // userName: userdata.name,
424
- // logType: 'audit',
425
- // logSubType: 'auditStart',
426
- // logData: {
427
- // fileDate: insertData.fileDate,
428
- // auditType: insertData.auditType,
429
- // storeId: storeId,
430
- // clientName: inputData.queueName,
431
- // auditId: insertData._id,
432
- // zoneName: msg.zone_id,
433
- // moduleType: inputData.moduleType,
434
- // },
435
- // createdAt: new Date(),
436
- // };
437
- // await insertOpenSearchData( openSearch.auditLog, logData );
438
- // }
439
- // logger.info( { storeInfo: storeInfo } );
440
- // return res.sendSuccess( {
441
- // result: files,
442
- // count: msg.total_count,
443
- // storeId: storeId,
444
- // storeName: storeInfo?.storeName,
445
- // address: storeInfo?.address,
446
- // file: {
447
- // queueName: inputData.queueName,
448
- // store_id: storeId,
449
- // file_date: fileDate,
450
- // type: 'Audit',
451
- // auditId: insertData._id,
452
- // userId: insertData.userId,
453
- // zoneName: msg.zone_id,
454
- // moduleType: inputData.moduleType,
455
- // nextToken: nextQuery ? encodeURIComponent( nextQuery ) : null,
456
- // },
457
- // isDraft: insertData.isDraft,
458
- // } );
459
- // } catch ( error ) {
460
- // logger.error( {
461
- // error: error,
462
- // message: req.query,
463
- // function: 'getAuditFile',
464
- // } );
465
- // return res.sendError( error, 500 );
466
- // }
467
- // }
468
20
 
469
21
  export async function workSpace( req, res ) {
470
22
  try {
@@ -476,7 +28,7 @@ export async function workSpace( req, res ) {
476
28
  const dateRange = await getDate( new Date(), new Date() );
477
29
  const filter =[
478
30
  { status: { $in: [ 'active', 'hold' ] } },
479
- { 'auditConfigs.audit': { $eq: true } },
31
+ { 'auditConfigs.traxAudit': { $eq: true } },
480
32
  { clientId: { $in: inputData.clientId } },
481
33
  ];
482
34
 
@@ -501,7 +53,12 @@ export async function workSpace( req, res ) {
501
53
  { $eq: [ inputData.moduleType, 'uniform-detection' ] }, '$auditConfigs.traxQueueName.uniformDetection',
502
54
  {
503
55
  $cond: [
504
- { $eq: [ inputData.moduleType, 'mobile-detection' ] }, '$auditConfigs.traxQueueName.mobileDetection', '$auditConfigs.traxQueueName.cameraAngleChange',
56
+ { $eq: [ inputData.moduleType, 'mobile-detection' ] }, '$auditConfigs.traxQueueName.mobileDetection',
57
+ {
58
+ $cond: [
59
+ { $eq: [ inputData.moduleType, 'hygiene' ] }, '$auditConfigs.traxQueueName.hygiene', '$auditConfigs.traxQueueName.cameraAngleChange',
60
+ ],
61
+ },
505
62
  ],
506
63
  },
507
64
  ],
@@ -546,8 +103,10 @@ export async function workSpace( req, res ) {
546
103
  const clientDetails = await aggregateClient( clientQuery );
547
104
  const clientList = clientDetails.map( ( i ) => i.clientId );
548
105
  const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
106
+ const traxDataQuery = inputData?.moduleType == 'hygine'? { moduleType: inputData.moduleType } : {};
107
+
549
108
  const getStoreData = await findOneTraxAuditData(
550
- {},
109
+ traxDataQuery,
551
110
  { fileDate: 1 },
552
111
  { createdAt: -1 },
553
112
  );
@@ -566,7 +125,6 @@ export async function workSpace( req, res ) {
566
125
  clientId: { $last: '$clientId' },
567
126
  clientName: { $last: '$clientName' },
568
127
  installedStore: { $last: '$installedStore' },
569
- // queueName: { $last: '$queueName' },
570
128
  totalCount: { $sum: 1 },
571
129
  },
572
130
  },
@@ -600,18 +158,10 @@ export async function workSpace( req, res ) {
600
158
  },
601
159
  },
602
160
  },
603
- // {
604
- // $group: {
605
- // _id: { clientId: '$clientId', storeId: '$storeId' },
606
- // clientId: { $first: '$clientId' },
607
- // completedStoresCount: { $sum: '$completed' },
608
- // },
609
- // },
610
161
  {
611
162
  $group: {
612
163
  _id: '$clientId',
613
164
  clientId: { $first: '$clientId' },
614
- // completedStoresCount: { $first: '$completedStoresCount' },
615
165
  completedStoresCount: { $sum: '$completed' },
616
166
  },
617
167
  },
@@ -799,11 +349,11 @@ export async function workSpace( req, res ) {
799
349
  },
800
350
  ];
801
351
 
802
- const auditUserCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
803
- const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
352
+ const auditUserCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
353
+ const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
804
354
  logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
805
355
  const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
806
- const completedStoresCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
356
+ const completedStoresCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
807
357
  const clientAssignedCount = await aggregateAssignAudit( clientAssign );
808
358
  const auditStoreData = await aggregateTraxAuditData(
809
359
  auditStoreDataQuery,
@@ -1063,14 +613,6 @@ export async function getAuditFile( req, res ) {
1063
613
  data,
1064
614
  );
1065
615
  }
1066
- // else {
1067
- // logger.error( {
1068
- // error: { folderPath: folderPath },
1069
- // function: `getAuditFile - ${inputData.moduleType}`,
1070
- // message: 'Bucket image data not availale',
1071
- // } );
1072
- // return res.sendError( 'Bucket is Empty', 204 );
1073
- // }
1074
616
  result.push( {
1075
617
  type: 'image',
1076
618
  file: files,
@@ -1743,6 +1285,7 @@ export async function userAuditHistory( req, res ) {
1743
1285
  tempId: 1,
1744
1286
  streamName: 1,
1745
1287
  question: 1,
1288
+ zoneName: 1,
1746
1289
  questionType: 1,
1747
1290
  answer: 1,
1748
1291
  userComments: 1,
@@ -1826,6 +1369,7 @@ export async function userAuditHistory( req, res ) {
1826
1369
  { auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
1827
1370
  { tempId: { $regex: inputData.searchValue, $options: 'i' } },
1828
1371
  { question: { $regex: inputData.searchValue, $options: 'i' } },
1372
+ { zoneName: { $regex: inputData.searchValue, $options: 'i' } },
1829
1373
  { userComments: { $regex: inputData.searchValue, $options: 'i' } },
1830
1374
  ],
1831
1375
 
@@ -1841,7 +1385,7 @@ export async function userAuditHistory( req, res ) {
1841
1385
  },
1842
1386
  );
1843
1387
  }
1844
- const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1388
+ const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1845
1389
  if ( count.length == 0 ) {
1846
1390
  return res.sendError( 'No Data Found', 204 );
1847
1391
  }
@@ -1886,10 +1430,6 @@ export async function userAuditHistory( req, res ) {
1886
1430
  temp['User Comments'] = element.userComments;
1887
1431
  break;
1888
1432
  case 'uniform-detection':
1889
- // temp['Customer ID'] = element.tempId;
1890
- // temp['Question'] = element.question;
1891
- // temp['Result'] = element.answer;
1892
- // temp['User Comments'] = element.userComments;
1893
1433
  temp['Before Count'] = element.beforeCount;
1894
1434
  temp['After Count'] = element.afterCount;
1895
1435
  temp['Accuracy'] = element.accuracy || '';
@@ -1899,6 +1439,12 @@ export async function userAuditHistory( req, res ) {
1899
1439
  temp['After Count'] = element.afterCount;
1900
1440
  temp['Accuracy'] = element.accuracy || '';
1901
1441
  break;
1442
+ case 'hygiene':
1443
+ temp['Zone Name'] = element.zoneName;
1444
+ temp['Before Count'] = element.beforeCount;
1445
+ temp['After Count'] = element.afterCount;
1446
+ temp['Accuracy'] = element.accuracy || '';
1447
+ break;
1902
1448
  }
1903
1449
  exportData.push( temp );
1904
1450
  } );
@@ -1918,7 +1464,7 @@ export async function userAuditHistory( req, res ) {
1918
1464
  }
1919
1465
 
1920
1466
 
1921
- const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1467
+ const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
1922
1468
 
1923
1469
  return res.sendSuccess( { result: result, count: count.length } );
1924
1470
  } catch ( error ) {
@@ -3951,6 +3497,7 @@ export async function overviewTable( req, res ) {
3951
3497
  export async function getDetectionAuditFile( req, res ) {
3952
3498
  try {
3953
3499
  const openSearch = JSON.parse( process.env.OPENSEARCH );
3500
+ const url = JSON.parse( process.env.URL );
3954
3501
  const inputData = req.query;
3955
3502
  const previousDate = dayjs( new Date() ).subtract( 1, 'days' );
3956
3503
  const data = await getDate( new Date( dayjs( previousDate ).format( 'YYYY-MM-DD' ) ), new Date() );
@@ -3960,6 +3507,7 @@ export async function getDetectionAuditFile( req, res ) {
3960
3507
  const end = data.end;
3961
3508
  const fetchData = {};
3962
3509
  let msg = {};
3510
+ // get user's inprogress files
3963
3511
  const userQuery = [
3964
3512
  {
3965
3513
  $match: {
@@ -3983,62 +3531,61 @@ export async function getDetectionAuditFile( req, res ) {
3983
3531
 
3984
3532
  const userDetails = await aggregateUserEmpDetection( userQuery );
3985
3533
  logger.info( { userDetails: userDetails, function: 'userDetails' } );
3986
- const auditStatus =
3987
- userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
3534
+ const auditStatus = userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
3988
3535
  switch ( auditStatus ) {
3989
3536
  case null:
3990
- const query = [
3991
- {
3992
- $match: {
3993
- $and: [
3994
- { userId: { $eq: req.user._id } },
3995
- { isCompleted: { $eq: false } },
3996
- { queueName: inputData.queueName },
3997
- { moduleType: inputData.moduleType },
3998
- ],
3999
- },
4000
- },
4001
- ];
4002
- const userAssign = await aggregateAssignAudit( query );
4003
- if ( userAssign.length > 0 ) {
4004
- logger.info( 'Hit in user assign', { inputData } );
4005
- userAssign[0].auditType == 'Audit' ?
4006
- ( msg = {
4007
- storeId: userAssign[0].storeId,
4008
- fileDate: userAssign[0].fileDate,
4009
- fileCount: userAssign[0].fileCount,
4010
- inputBucketName: userAssign[0].inputBucketName,
4011
- folderPath: userAssign[0].folderPath,
4012
- } ) :
4013
- ( msg = {
4014
- storeId: userAssign[0].storeId,
4015
- fileDate: userAssign[0].fileDate,
4016
- auditType: userAssign[0].auditType,
4017
- fileCount: userAssign[0].fileCount,
4018
- inputBucketName: userAssign[0].inputBucketName,
4019
- folderPath: userAssign[0].folderPath,
4020
- } );
4021
- await updateOneAssignAudit(
4022
- { _id: userAssign[0]._id },
4023
- { isCompleted: true },
4024
- );
4025
- logger.info( 'Hit in auditUserAssignModel updateOne', {
4026
- _id: userAssign[0]._id,
4027
- isCompleted: true,
3537
+ // const query = [
3538
+ // {
3539
+ // $match: {
3540
+ // $and: [
3541
+ // { userId: { $eq: req.user._id } },
3542
+ // { isCompleted: { $eq: false } },
3543
+ // { queueName: inputData.queueName },
3544
+ // { moduleType: inputData.moduleType },
3545
+ // ],
3546
+ // },
3547
+ // },
3548
+ // ];
3549
+ // const userAssign = await aggregateAssignAudit( query );
3550
+ // if ( userAssign.length > 0 ) {
3551
+ // logger.info( 'Hit in user assign', { inputData } );
3552
+ // userAssign[0].auditType == 'Audit' ?
3553
+ // ( msg = {
3554
+ // storeId: userAssign[0].storeId,
3555
+ // fileDate: userAssign[0].fileDate,
3556
+ // fileCount: userAssign[0].fileCount,
3557
+ // inputBucketName: userAssign[0].inputBucketName,
3558
+ // folderPath: userAssign[0].folderPath,
3559
+ // } ) :
3560
+ // ( msg = {
3561
+ // storeId: userAssign[0].storeId,
3562
+ // fileDate: userAssign[0].fileDate,
3563
+ // auditType: userAssign[0].auditType,
3564
+ // fileCount: userAssign[0].fileCount,
3565
+ // inputBucketName: userAssign[0].inputBucketName,
3566
+ // folderPath: userAssign[0].folderPath,
3567
+ // } );
3568
+ // await updateOneAssignAudit(
3569
+ // { _id: userAssign[0]._id },
3570
+ // { isCompleted: true },
3571
+ // );
3572
+ // logger.info( 'Hit in auditUserAssignModel updateOne', {
3573
+ // _id: userAssign[0]._id,
3574
+ // isCompleted: true,
3575
+ // } );
3576
+ // } else {
3577
+ logger.info( 'Hit in new file', { inputData } );
3578
+ const consumer = await sqsReceive( inputData.queueName );
3579
+ if ( !consumer ) {
3580
+ logger.error( {
3581
+ error: consumer,
3582
+ function: `getAuditFile - ${inputData.moduleType}`,
3583
+ message: 'SQS Receive queue is empty',
4028
3584
  } );
4029
- } else {
4030
- logger.info( 'Hit in new file', { inputData } );
4031
- const consumer = await sqsReceive( inputData.queueName );
4032
- if ( !consumer ) {
4033
- logger.error( {
4034
- error: consumer,
4035
- function: 'getAuditFile',
4036
- message: 'SQS Receive queue is empty',
4037
- } );
4038
- return res.sendError( `${inputData.queueName} is Empty`, 204 );
4039
- }
4040
- msg = JSON.parse( consumer );
3585
+ return res.sendError( `${inputData.queueName} is Empty`, 204 );
4041
3586
  }
3587
+ msg = JSON.parse( consumer );
3588
+ // }
4042
3589
  break;
4043
3590
 
4044
3591
  case 'drafted':
@@ -4069,6 +3616,7 @@ export async function getDetectionAuditFile( req, res ) {
4069
3616
  const file = {
4070
3617
  auditId: userDetails[0]._id,
4071
3618
  storeId: userDetails[0].storeId,
3619
+ zoneName: userDetails[0].zoneName,
4072
3620
  fileDate: userDetails[0].fileDate,
4073
3621
  auditType: userDetails[0].auditType,
4074
3622
  queueName: log.queueName,
@@ -4133,6 +3681,7 @@ export async function getDetectionAuditFile( req, res ) {
4133
3681
  default:
4134
3682
  msg = {
4135
3683
  storeId: userDetails[0].storeId,
3684
+ zoneName: userDetails[0].zoneName,
4136
3685
  fileDate: userDetails[0].fileDate,
4137
3686
  auditType: userDetails[0].auditType,
4138
3687
  fileCount: userDetails[0].beforeCount,
@@ -4141,112 +3690,12 @@ export async function getDetectionAuditFile( req, res ) {
4141
3690
  };
4142
3691
  break;
4143
3692
  }
4144
- // if ( msg.auditType === 'ReAudit' ) {
4145
- // logger.info( 'Hit in user ReAudit', { inputData } );
4146
- // let reauditInsert = {};
4147
- // const [ filterData, auditImage ] = await Promise.all( [
4148
- // getFilterData( msg ),
4149
- // getAuditImage( msg ),
4150
- // ] );
4151
- // if ( filterData.statusCode == 404 || auditImage.statusCode == 404 ) {
4152
- // return res.sendError( 'No Data found', 204 );
4153
- // }
4154
- // const reauditImg = await getReauditImg( filterData, auditImage );
4155
- // if ( userDetails.length === 0 ) {
4156
- // const [ day, month, year ] = msg.curr_date.split( '-' );
4157
- // const temp = `${year}-${month}-${day}`;
4158
- // let start = new Date( temp );
4159
- // const userTimezoneOffset = start.getTimezoneOffset() * 60000;
4160
- // start = new Date( start.getTime() - userTimezoneOffset );
4161
- // start.setUTCHours( 0, 0, 0, 0 );
4162
- // const record = {
4163
- // userId: req.user._id,
4164
- // storeId: msg.store_id,
4165
- // clientId: msg.store_id.split( '-' )[0],
4166
- // auditType: msg.audit_type || 'ReAudit',
4167
- // fileDate: msg.curr_date,
4168
- // queueName: inputData.queueName,
4169
- // beforeCount: reauditImg.length,
4170
- // auditStatus: 'inprogress',
4171
- // fileDateISO: start,
4172
- // timeSpent: 0,
4173
- // startTime: new Date(),
4174
- // zoneName: msg.zone_id,
4175
- // moduleType: inputData.moduleType,
4176
- // };
4177
- // const query = {
4178
- // storeId: msg.store_id,
4179
- // zoneName: msg.zone_id,
4180
- // fileDate: msg.curr_date,
4181
- // moduleType: inputData.moduleType,
4182
- // };
4183
- // let storeRecord = {
4184
- // userId: req.user._id,
4185
- // auditType: msg.audit_type || 'ReAudit',
4186
- // status: 'inprogress',
4187
- // timeSpent: 0,
4188
- // };
4189
- // reauditInsert = await createUserAudit( record );
4190
-
4191
- // await updateOneStoreAudit( query, storeRecord );
4192
- // } else {
4193
- // reauditInsert = userDetails[0];
4194
- // }
4195
- // const userdata = await findOneUser( { _id: req.user._id } );
4196
- // if ( inputData.nextId ) {
4197
- // const logData = {
4198
- // userId: req.user._id,
4199
- // userName: userdata.name,
4200
- // logType: 'audit',
4201
- // logSubType: 'auditStart',
4202
- // logData: {
4203
- // fileDate: msg.curr_date,
4204
- // auditType: msg.audit_type,
4205
- // storeId: msg.store_id,
4206
- // clientName: inputData.queueName,
4207
- // auditId: reauditInsert._id,
4208
- // zoneName: msg.zone_id,
4209
- // moduleType: inputData.moduleType,
4210
- // },
4211
- // createdAt: new Date(),
4212
- // };
4213
- // await insertOpenSearchData( openSearch.auditLog, logData );
4214
- // }
4215
-
4216
- // const storeQuery = {
4217
- // storeId: msg.store_id,
4218
- // };
4219
- // const storeFields = {
4220
- // storeId: 1,
4221
- // storeName: 1,
4222
- // address: '$storeProfile.address',
4223
- // };
4224
- // const storeInfo = await findOneStore( storeQuery, storeFields );
4225
- // return res.sendSuccess( {
4226
- // result: reauditImg,
4227
- // count: reauditImg.length,
4228
- // storeId: storeInfo?.storeId,
4229
- // storeName: storeInfo?.storeName,
4230
- // address: storeInfo?.address || '',
4231
- // file: {
4232
- // store_id: msg.store_id,
4233
- // file_date: msg.curr_date,
4234
- // type: msg.audit_type || 'ReAudit',
4235
- // queueName: inputData.queueName,
4236
- // auditId: reauditInsert._id,
4237
- // userId: reauditInsert.userId,
4238
- // zoneName: msg.zone_id,
4239
- // moduleType: inputData.moduleType,
4240
- // },
4241
- // isDraft: reauditInsert.isDraft,
4242
- // } );
4243
- // } to wor for reAudit concept
4244
3693
  const storeId = msg.storeId;
4245
3694
  const fileDate = msg.fileDate;
4246
3695
 
4247
3696
  const files = [];
4248
3697
  let insertData = {};
4249
- fetchData.Bucket = msg.inputBucketName; // need to change
3698
+ fetchData.Bucket = msg.inputBucketName;
4250
3699
  fetchData.file_path = msg.folderPath;
4251
3700
  if ( inputData.limit ) {
4252
3701
  fetchData.MaxKeys = inputData.limit;
@@ -4257,22 +3706,22 @@ export async function getDetectionAuditFile( req, res ) {
4257
3706
  const list = await listFileByPath( fetchData );
4258
3707
  const folderPath = list.data;
4259
3708
  const nextQuery = list.pageToken;
4260
-
3709
+ const bucketCDN = inputData.moduleType=='hygiene' ? url.hygieneInput : url.traxAuditInput;
4261
3710
  if ( folderPath?.length > 0 ) {
4262
3711
  for ( let i = 0; i < folderPath.length; i++ ) {
4263
3712
  const img = folderPath[i].Key.split( '/' );
4264
3713
  const image = img[3].split( '.' );
4265
3714
  const indexes = image[0].split( '_' );
4266
- fetchData.file_path = folderPath[i].Key;
4267
- const data = await signedUrl( fetchData );
3715
+ const Key = folderPath[i].Key;
3716
+ const data = `${bucketCDN}${Key}`;// await signedUrl( fetchData );
4268
3717
  const mapimg = {
4269
3718
  img_path: data,
4270
- img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
3719
+ img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` : inputData.moduleType=='hygiene'?`${indexes[2]}-${indexes[3]}`:image[0],
4271
3720
  img_id: img[3],
4272
3721
  };
4273
3722
  files.push( {
4274
3723
  img_path: data,
4275
- img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
3724
+ img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}`: inputData.moduleType=='hygiene'?`${indexes[2]}-${indexes[3]}`:image[0],
4276
3725
  img_id: img[3],
4277
3726
  selected: false,
4278
3727
  dropped: false,
@@ -4292,6 +3741,7 @@ export async function getDetectionAuditFile( req, res ) {
4292
3741
  const record = {
4293
3742
  userId: req.user._id,
4294
3743
  storeId: msg.storeId,
3744
+ zoneName: msg.zoneName,
4295
3745
  clientId: msg.storeId.split( '-' )[0],
4296
3746
  auditType: msg.auditType || 'Audit',
4297
3747
  fileDate: msg.fileDate,
@@ -4307,12 +3757,14 @@ export async function getDetectionAuditFile( req, res ) {
4307
3757
  };
4308
3758
  const query = {
4309
3759
  storeId: msg.storeId,
3760
+ zoneName: msg.zoneName,
4310
3761
  fileDate: msg.fileDate,
4311
3762
  moduleType: inputData.moduleType,
4312
3763
  };
4313
3764
  const storeRecord = {
4314
3765
  userId: req.user._id,
4315
3766
  storeId: msg.storeId,
3767
+ zoneName: msg.zoneName,
4316
3768
  clientId: msg.storeId.split( '-' )[0],
4317
3769
  auditType: msg.auditType || 'Audit',
4318
3770
  fileDate: msg.fileDate,
@@ -4334,7 +3786,7 @@ export async function getDetectionAuditFile( req, res ) {
4334
3786
  } else {
4335
3787
  logger.error( {
4336
3788
  error: { folderPath: folderPath, nextQuery: nextQuery },
4337
- function: 'getAuditFile',
3789
+ function: `getAuditFile - ${inputData.moduleType }`,
4338
3790
  message: 'Bucket image data not availale',
4339
3791
  } );
4340
3792
  return res.sendError( 'Bucket is Empty', 204 );
@@ -4358,6 +3810,7 @@ export async function getDetectionAuditFile( req, res ) {
4358
3810
  fileDate: insertData.fileDate,
4359
3811
  auditType: insertData.auditType,
4360
3812
  storeId: storeId,
3813
+ zoneName: insertData.zoneName,
4361
3814
  clientName: inputData.queueName,
4362
3815
  auditId: insertData._id,
4363
3816
  moduleType: inputData.moduleType,
@@ -4376,6 +3829,7 @@ export async function getDetectionAuditFile( req, res ) {
4376
3829
  file: {
4377
3830
  queueName: inputData.queueName,
4378
3831
  storeId: storeId,
3832
+ zoneName: insertData.zoneName,
4379
3833
  fileDate: fileDate,
4380
3834
  auditType: msg.auditType || 'Audit',
4381
3835
  auditId: insertData._id,
@@ -4416,11 +3870,13 @@ export async function saveDraft( req, res ) {
4416
3870
  isDraft: true,
4417
3871
  auditStatus: 'drafted',
4418
3872
  };
4419
- const storeQuery = {
3873
+ let storeQuery = {
4420
3874
  storeId: inputData.storeId,
4421
3875
  fileDate: inputData.fileDate,
4422
3876
  };
4423
3877
 
3878
+ inputData?.zoneName ? storeQuery['zoneName'] = inputData?.zoneName : null;
3879
+
4424
3880
  let storeRecord = {
4425
3881
  status: 'drafted',
4426
3882
  };
@@ -4447,6 +3903,7 @@ export async function saveDraft( req, res ) {
4447
3903
  fileDate: inputData.fileDate,
4448
3904
  auditType: inputData.auditType,
4449
3905
  storeId: inputData.storeId,
3906
+ zoneName: inputData?.zoneName,
4450
3907
  clientName: inputData.queueName,
4451
3908
  beforeCount: inputData.totalCount,
4452
3909
  afterCount: inputData.employeeCount,
@@ -4512,7 +3969,8 @@ export async function save( req, res ) {
4512
3969
  const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
4513
3970
  const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
4514
3971
  inputData.clientId = getUserAuditData.clientId;
4515
- const query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
3972
+ let query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
3973
+ inputData?.zoneName? query['zoneName'] = inputData.zoneName : null;
4516
3974
  const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
4517
3975
  if ( data ) {
4518
3976
  const userUpdated ={
@@ -4535,11 +3993,12 @@ export async function save( req, res ) {
4535
3993
  {
4536
3994
  fileDate: inputData.fileDate,
4537
3995
  storeId: inputData.storeId,
3996
+ zoneName: inputData.zoneName,
4538
3997
  moduleType: inputData.moduleType,
4539
3998
  },
4540
3999
  );
4541
4000
  if ( !getFilePath ) {
4542
- return res.sendError( ' SQS is not sent due to Inserted Data is not there', 400 );
4001
+ return res.sendError( 'SQS is not sent due to Inserted Data is not there', 400 );
4543
4002
  }
4544
4003
  const [ getStore, getClient ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: inputData.clientId }, { clientName: 1 } ) ] );
4545
4004
 
@@ -4548,31 +4007,33 @@ export async function save( req, res ) {
4548
4007
  for ( let i =0; i<inputData?.employee.length; i++ ) {
4549
4008
  tempId.push( inputData?.employee[i].img_id );
4550
4009
  }
4010
+ if ( inputData.moduleType !== 'hygiene' ) {
4011
+ const sqsProduceQueue = {
4012
+ QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
4013
+ MessageBody: JSON.stringify( {
4014
+ storeId: inputData.storeId,
4015
+ storeName: getStore?.storeName,
4016
+ zoneName: inputData?.zoneName,
4017
+ fileDate: inputData?.fileDate,
4018
+ moduleType: inputData?.moduleType,
4019
+ inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
4020
+ tempId: tempId,
4021
+ count: inputData?.employeeCount,
4022
+ folderPath: getFilePath?.sqs?.Body?.folderPath,
4023
+ } ),
4024
+ };
4025
+ const sqsQueue = await sendMessageToQueue(
4026
+ sqsProduceQueue.QueueUrl,
4027
+ sqsProduceQueue.MessageBody,
4028
+ );
4551
4029
 
4552
- const sqsProduceQueue = {
4553
- QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
4554
- MessageBody: JSON.stringify( {
4555
- storeId: inputData.storeId,
4556
- storeName: getStore?.storeName,
4557
- fileDate: inputData.fileDate,
4558
- moduleType: inputData.moduleType,
4559
- inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
4560
- tempId: tempId,
4561
- count: inputData.employeeCount,
4562
- folderPath: getFilePath?.sqs?.Body?.folderPath,
4563
- } ),
4564
- };
4565
- const sqsQueue = await sendMessageToQueue(
4566
- sqsProduceQueue.QueueUrl,
4567
- sqsProduceQueue.MessageBody,
4568
- );
4569
-
4570
- if ( sqsQueue.statusCode ) {
4571
- logger.error( {
4572
- error: `${sqsQueue}`,
4573
- type: 'UPLOAD_ERROR',
4574
- } );
4575
- return res.sendError( 'SQS not sent', 500 );
4030
+ if ( sqsQueue.statusCode ) {
4031
+ logger.error( {
4032
+ error: `${sqsQueue}`,
4033
+ type: 'UPLOAD_ERROR',
4034
+ } );
4035
+ return res.sendError( 'SQS not sent', 500 );
4036
+ }
4576
4037
  }
4577
4038
  }
4578
4039
 
@@ -4583,6 +4044,7 @@ export async function save( req, res ) {
4583
4044
  clientName: getClient?.clientName,
4584
4045
  storeId: inputData.storeId,
4585
4046
  storeName: getStore?.storeName,
4047
+ zoneName: inputData?.zoneName,
4586
4048
  spocName: getStore?.spocDetails? getStore?.spocDetails[0]?.name : '',
4587
4049
  spocEmail: getStore?.spocDetails? getStore?.spocDetails[0]?.email:'',
4588
4050
  spocContact: getStore?.spocDetails? getStore?.spocDetails[0].contact:'',
@@ -4605,6 +4067,7 @@ export async function save( req, res ) {
4605
4067
  fileDate: getUserAuditData?.fileDate,
4606
4068
  auditType: getUserAuditData?.auditType,
4607
4069
  storeId: getUserAuditData?.storeId,
4070
+ zoneName: inputData?.zoneName,
4608
4071
  moduleType: getUserAuditData?.moduleType,
4609
4072
  queueName: req.userAudit?.queueName,
4610
4073
  clientId: req.userAudit?.clientId,
@@ -43,6 +43,7 @@ export const saveDraftSchema = joi.object(
43
43
  {
44
44
  userCommands: joi.string().optional().allow( '' ),
45
45
  storeId: joi.string().required(),
46
+ zoneName: joi.string().optional(),
46
47
  auditId: joi.string().required(),
47
48
  moduleType: joi.string().required(),
48
49
  auditType: joi.string().required(),
@@ -269,6 +270,7 @@ export const overviewTableValid= {
269
270
  export const saveSchema = joi.object( {
270
271
  auditId: joi.string().required(),
271
272
  storeId: joi.string().required(),
273
+ zoneName: joi.string().optional(),
272
274
  fileDate: joi.string().required(),
273
275
  auditType: joi.string().required(),
274
276
  moduleType: joi.string().required(),
@@ -1,6 +1,6 @@
1
1
  import express from 'express';
2
2
  import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
3
- import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
+ import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
4
  import { auditImages, auditStoreList, auditUserList, clientMetrics, clients, getAuditFile, getDraftedData, overAllAuditSummary, overViewCard, overviewTable, pendingSummaryTable, reTrigger, save, saveDraft, storeMetrics, summarySplit, totalNotAssignedCount, userAuditHistory, userMetrics, workSpace, getUserAuditCount, getUserAuditCountMTD, auditViewLogs, getUserCredit } from '../controllers/audit.controllers.js';
5
5
  import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid, auditViewLogValid } from '../dtos/audit.dtos.js';
6
6
 
@@ -8,33 +8,35 @@ export const auditRouter = express.Router();
8
8
 
9
9
  // Configuration
10
10
 
11
- auditRouter.get( '/clients', isAllowedSessionHandler, validate( clientValid ), clients );
12
- auditRouter.post( '/audit-stores', isAllowedSessionHandler, validate( auditStoreValid ), auditStoreList );
13
- auditRouter.get( '/tango-users', isAllowedSessionHandler, auditUserList );
11
+ auditRouter.get( '/clients', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( clientValid ), clients );
12
+ auditRouter.post( '/audit-stores', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditStoreValid ), auditStoreList );
13
+ auditRouter.get( '/tango-users', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), auditUserList );
14
14
 
15
15
  // Audit Mapping
16
- auditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
17
- auditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
18
- auditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
19
- auditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserAudit, save );
20
- auditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
16
+ auditRouter.get( '/get-file', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getFileValid ), isExistsQueue, getAuditFile );
17
+ auditRouter.post( '/save-draft', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( saveDraftValid ), saveDraft );
18
+ auditRouter.get( '/get-drafted-data', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getDraftedDataValid ), getDraftedData );
19
+ auditRouter.post( '/save', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( saveValid ), validateUserAudit, save );
20
+ auditRouter.post( '/work-space', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( workSpaceValid ), workSpace );
21
21
 
22
22
  // Audit Metrics
23
- auditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
24
- auditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
25
- auditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
26
- auditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
27
- auditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
28
- auditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
29
- auditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
30
- auditRouter.get( '/audit-images', isAllowedSessionHandler, validate( auditImageValid ), isAuditInputFolderExist, auditImages );
23
+ auditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( userAuditHistoryValid ), userAuditHistory );
24
+ auditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( clientMetricsValid ), clientMetrics );
25
+ auditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( storeMetricsValid ), storeMetrics );
26
+ auditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( userMetricsValid ), userMetrics );
27
+ auditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( pendingSummaryTableValid ), pendingSummaryTable );
28
+ auditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overAllAuditSummaryValid ), overAllAuditSummary );
29
+ auditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler,
30
+ accessVerification( { userType: [ 'tango' ], access: [ { featureName: 'TangoAdmin', name: 'TicketConfiguration', permissions: [ 'isEdit' ] } ] } ),
31
+ validate( reTriggerValid ), isAuditDocumentExist, isAuditInputFolderExist, reTrigger );
32
+ auditRouter.get( '/audit-images', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditImageValid ), isAuditInputFolderExist, auditImages );
31
33
  // summary
32
- auditRouter.post( '/metrics/overview-card', isAllowedSessionHandler, validate( overViewCardValid ), overViewCard );
33
- auditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
34
- auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
34
+ auditRouter.post( '/metrics/overview-card', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overViewCardValid ), overViewCard );
35
+ auditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( summarySplitValid ), summarySplit );
36
+ auditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overviewTableValid ), overviewTable );
35
37
 
36
38
  // ticket
37
- auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, totalNotAssignedCount );
39
+ auditRouter.get( '/total-not-assigned-count', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), totalNotAssignedCount );
38
40
 
39
41
  // audit user wallet
40
42
  auditRouter.get( '/get-user-credit', isAllowedSessionHandler, isAuditUser, getUserCredit );
@@ -42,5 +44,5 @@ auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditC
42
44
  auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
43
45
 
44
46
  // audit log
45
- auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, validate( auditViewLogValid ), auditViewLogs );
47
+ auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( auditViewLogValid ), auditViewLogs );
46
48
  export default auditRouter;
@@ -1,5 +1,5 @@
1
1
  import { Router } from 'express';
2
- import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
2
+ import { accessVerification, isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
3
3
  import { getDetectionFileValid, getFileValid, userAuditHistoryValid, workSpaceValid, saveValid, clientMetricsValid, storeMetricsValid, userMetricsValid, pendingSummaryTableValid, overAllAuditSummaryValid, summarySplitValid, overviewTableValid, getUpdatedFileValid, saveBinaryValid, getDraftedDataValid, saveDraftValid, reTriggerValidSchema } from '../dtos/traxAudit.dtos.js';
4
4
  import { isExistsQueue } from '../validation/audit.validation.js';
5
5
  import { clientMetrics, getAuditFile, getDetectionAuditFile, getUpdatedFile, overAllAuditSummary, overviewTable, pendingSummaryTable, saveBinary, storeMetrics, summarySplit, userAuditHistory, userMetrics, workSpace, saveDraft, getDraftedData, save, reTrigger } from '../controllers/traxAudit.controllers.js';
@@ -9,30 +9,32 @@ export const traxAuditRouter = Router();
9
9
 
10
10
  // Audit Mapping
11
11
 
12
- traxAuditRouter.get( '/get-file-detection', isAllowedSessionHandler, validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
13
- traxAuditRouter.post( '/save', validate( saveValid ), isAllowedSessionHandler, validateUserEmpDetection, save );
14
- traxAuditRouter.post( '/save-draft', validate( saveDraftValid ), isAllowedSessionHandler, saveDraft );
15
- traxAuditRouter.get( '/get-drafted-data', validate( getDraftedDataValid ), isAllowedSessionHandler, getDraftedData );
12
+ traxAuditRouter.get( '/get-file-detection', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getDetectionFileValid ), isExistsQueue, getDetectionAuditFile );
13
+ traxAuditRouter.post( '/save', validate( saveValid ), isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validateUserEmpDetection, save );
14
+ traxAuditRouter.post( '/save-draft', validate( saveDraftValid ), isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), saveDraft );
15
+ traxAuditRouter.get( '/get-drafted-data', validate( getDraftedDataValid ), isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), getDraftedData );
16
16
 
17
17
 
18
18
  // Y/n
19
- traxAuditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
20
- traxAuditRouter.post( '/get-updated-file', isAllowedSessionHandler, validate( getUpdatedFileValid ), isTraxAuditDocumentExist, getUpdatedFile );
19
+ traxAuditRouter.get( '/get-file', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getFileValid ), isExistsQueue, getAuditFile );
20
+ traxAuditRouter.post( '/get-updated-file', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( getUpdatedFileValid ), isTraxAuditDocumentExist, getUpdatedFile );
21
21
  traxAuditRouter.post( '/save-binary-audit', isAllowedSessionHandler, validate( saveBinaryValid ), validateBinaryAudit, saveBinary );
22
22
 
23
23
  // metrcis
24
- traxAuditRouter.post( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
25
- traxAuditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
26
- traxAuditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
27
- traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
28
- traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
29
- traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, validate( pendingSummaryTableValid ), pendingSummaryTable );
30
- traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, validate( overAllAuditSummaryValid ), overAllAuditSummary );
31
- traxAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler, validate( reTriggerValidSchema ), isuserEmpDocumentExist, isMappingAuditInputFolderExist, reTrigger );
24
+ traxAuditRouter.post( '/work-space', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( workSpaceValid ), workSpace );
25
+ traxAuditRouter.post( '/metrics/user-audit-history', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( userAuditHistoryValid ), userAuditHistory );
26
+ traxAuditRouter.post( '/metrics/client-metrics', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( clientMetricsValid ), clientMetrics );
27
+ traxAuditRouter.post( '/metrics/store-metrics', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( storeMetricsValid ), storeMetrics );
28
+ traxAuditRouter.post( '/metrics/user-metrics', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( userMetricsValid ), userMetrics );
29
+ traxAuditRouter.post( '/metrics/pending-summary-table', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( pendingSummaryTableValid ), pendingSummaryTable );
30
+ traxAuditRouter.post( '/metrics/overall-audit-summary', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overAllAuditSummaryValid ), overAllAuditSummary );
31
+ traxAuditRouter.post( '/metrics/re-trigger', isAllowedSessionHandler,
32
+ accessVerification( { userType: [ 'tango' ], access: [ { featureName: 'TangoAdmin', name: 'TicketConfiguration', permissions: [ 'isEdit' ] } ] } ),
33
+ validate( reTriggerValidSchema ), isuserEmpDocumentExist, isMappingAuditInputFolderExist, reTrigger );
32
34
 
33
35
  // summary
34
36
 
35
- traxAuditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, validate( summarySplitValid ), summarySplit );
36
- traxAuditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, validate( overviewTableValid ), overviewTable );
37
+ traxAuditRouter.post( '/metrics/summary-split-up', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( summarySplitValid ), summarySplit );
38
+ traxAuditRouter.post( '/metrics/overview-table', isAllowedSessionHandler, accessVerification( { userType: [ 'tango' ] } ), validate( overviewTableValid ), overviewTable );
37
39
 
38
40
  export default traxAuditRouter;
@@ -7,3 +7,11 @@ export function aggregateAuditUsers( query ) {
7
7
  export function findOneAuditUsers( query, fields ) {
8
8
  return auditUsersModel.findOne( query, fields );
9
9
  };
10
+
11
+ export function updateOneAuditUsers( query, fields ) {
12
+ return auditUsersModel.updateOne( query, fields );
13
+ };
14
+
15
+ export function updateManyAuditUsers( query, fields ) {
16
+ return auditUsersModel.updateMany( query, fields );
17
+ };