tango-app-api-audit 3.4.11-alpha.20 → 3.4.11-alpha.23

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.11-alpha.20",
3
+ "version": "3.4.11-alpha.23",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2320,11 +2320,17 @@ export async function userMetrics( req, res ) {
2320
2320
  userId: 1,
2321
2321
  fileDate: 1,
2322
2322
  startTime: 1,
2323
- endTime: 1,
2323
+ endTime: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$endTime', '$$REMOVE' ] },
2324
2324
  totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
2325
2325
  beforeCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$beforeCount', 0 ] },
2326
2326
  afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
2327
2327
  createdAt: 1,
2328
+ // to: '$createdAt',
2329
+ },
2330
+ },
2331
+ {
2332
+ $sort: {
2333
+ endTime: -1,
2328
2334
  },
2329
2335
  },
2330
2336
  {
@@ -2336,8 +2342,9 @@ export async function userMetrics( req, res ) {
2336
2342
  beforeCount: { $sum: '$beforeCount' },
2337
2343
  afterCount: { $sum: '$afterCount' },
2338
2344
  checkIntime: { $first: '$startTime' },
2339
- checkOutTime: { $last: '$endTime' },
2345
+ checkOutTime: { $first: '$endTime' },
2340
2346
  createdAt: { $first: '$createdAt' },
2347
+ to: { $last: '$createdAt' },
2341
2348
 
2342
2349
  },
2343
2350
  },
@@ -2373,6 +2380,7 @@ export async function userMetrics( req, res ) {
2373
2380
  $divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
2374
2381
  },
2375
2382
  createdAt: 1,
2383
+ to: 1,
2376
2384
  },
2377
2385
  },
2378
2386
  {
@@ -2389,6 +2397,7 @@ export async function userMetrics( req, res ) {
2389
2397
  minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
2390
2398
  seconds: { $mod: [ '$differenceInSeconds', 60 ] },
2391
2399
  createdAt: 1,
2400
+ to: 1,
2392
2401
  },
2393
2402
  },
2394
2403
  {
@@ -2424,6 +2433,7 @@ export async function userMetrics( req, res ) {
2424
2433
  },
2425
2434
  },
2426
2435
  createdAt: 1,
2436
+ to: 1,
2427
2437
  },
2428
2438
  },
2429
2439
  {
@@ -2442,6 +2452,7 @@ export async function userMetrics( req, res ) {
2442
2452
  $concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
2443
2453
  },
2444
2454
  createdAt: 1,
2455
+ to: 1,
2445
2456
  },
2446
2457
  },
2447
2458
  {
@@ -2496,6 +2507,7 @@ export async function userMetrics( req, res ) {
2496
2507
  },
2497
2508
  workingHours: 1,
2498
2509
  createdAt: 1,
2510
+ to: 1,
2499
2511
  },
2500
2512
  },
2501
2513
  ];
@@ -4734,6 +4746,7 @@ export async function auditViewLogs( req, res ) {
4734
4746
  },
4735
4747
  };
4736
4748
  break;
4749
+ case 'uniform-detection':
4737
4750
  case 'mobile-detection':
4738
4751
  logsQuery = {
4739
4752
  'size': 100,
@@ -1613,7 +1613,7 @@ export async function saveBinary( req, res ) {
1613
1613
  question: req.userAudit?.question,
1614
1614
  result: req.userAudit?.answer,
1615
1615
  endTime: Date.now(),
1616
- timeSpent:timeDifferenceInMinutes,
1616
+ timeSpent: timeDifferenceInMinutes,
1617
1617
  auditId: new mongoose.Types.ObjectId( inputData.auditId ),
1618
1618
  },
1619
1619
  createdAt: Date.now(),
@@ -4519,7 +4519,7 @@ export async function save( req, res ) {
4519
4519
  const storeUpdated ={
4520
4520
  status: 'completed',
4521
4521
  afterCount: inputData.employeeCount,
4522
- timeSpent:timeDifferenceInMinutes,
4522
+ timeSpent: timeDifferenceInMinutes,
4523
4523
  };
4524
4524
  logger.info( { query: query, function: 'saveQuery' } );
4525
4525
  const [ userUpdate, storeUpdate ] = await Promise.all( [ updateOneUserEmpDetection( { _id: inputData.auditId }, userUpdated ), updateOneStoreEmpDetection( query, storeUpdated ) ] );
@@ -4541,7 +4541,7 @@ export async function save( req, res ) {
4541
4541
  tempId.push( inputData?.employee[i].img_id );
4542
4542
  }
4543
4543
  }
4544
- const getStore = await findOneStore( { storeId: inputData.storeId }, { storeName: 1 } );
4544
+ const [ getStore, getClient ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: inputData.clientId }, { clientName: 1 } ) ] );
4545
4545
  const sqsProduceQueue = {
4546
4546
  QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
4547
4547
  MessageBody: JSON.stringify( {
@@ -4568,6 +4568,25 @@ export async function save( req, res ) {
4568
4568
  return res.sendError( 'SQS not sent', 500 );
4569
4569
  }
4570
4570
 
4571
+ // trax output in open serach
4572
+ const output = {
4573
+ clientId: inputData.clientId,
4574
+ clientName: getClient?.clientName,
4575
+ storeId: inputData.storeId,
4576
+ storeName: getStore?.storeName,
4577
+ spocName: getStore?.spocDetails[0]?.name,
4578
+ spocEmail: getStore?.spocDetails[0]?.email,
4579
+ spocContact: getStore?.spocDetails[0].contact,
4580
+ address: getStore?.storeProfile?.address,
4581
+ fileDate: inputData.fileDate,
4582
+ moduleType: inputData.moduleType,
4583
+ inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
4584
+ tempId: tempId,
4585
+ count: inputData.employeeCount,
4586
+ folderPath: getFilePath?.sqs?.Body?.folderPath,
4587
+ createdAt: new Date(),
4588
+ };
4589
+ await insertOpenSearchData( openSearch.traxDetectionOutput, output );
4571
4590
  const logData = {
4572
4591
  userId: req.user._id,
4573
4592
  userName: req.user.userName,
@@ -4584,7 +4603,7 @@ export async function save( req, res ) {
4584
4603
  afterCount: inputData.employeeCount,
4585
4604
  startTime: req.userAudit?.startTime,
4586
4605
  endTime: Date.now(),
4587
- timeSpent:timeDifferenceInMinutes,
4606
+ timeSpent: timeDifferenceInMinutes,
4588
4607
  auditId: new mongoose.Types.ObjectId( inputData.auditId ),
4589
4608
  },
4590
4609
  createdAt: Date.now(),
@@ -1,4 +1,4 @@
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';
1
+ import { auditStoreSchema, clientMetricsSchema, clientSchema, getDraftedDataSchema, getFileSchema, overAllAuditSummarySchema, overViewCardSchema, reTriggerValidSchema, saveDraftSchema, saveSchema, storeMetricsSchema, summarySplitSchema, userAuditHistorySchema, userMetricsSchema, userSchema, workSpaceSchema, auditImageValidSchema, pendingSummaryTableSchema, overviewTableSchema, auditViewlogSchema } from '../dtos/audit.dtos.js';
2
2
  import j2s from 'joi-to-swagger';
3
3
 
4
4
  export const auditDocs = {
@@ -544,6 +544,47 @@ export const auditDocs = {
544
544
  },
545
545
  },
546
546
  },
547
+ '/v3/audit/audit-view-logs': {
548
+ get: {
549
+ tags: [ 'Audit Mapping' ],
550
+ description: `Get log for a store audit details`,
551
+ operationId: 'audit-view-logs',
552
+ parameters: [
553
+ {
554
+ in: 'query',
555
+ name: 'fileDate',
556
+ scema: j2s( auditViewlogSchema ).swagger,
557
+ require: true,
558
+ },
559
+ {
560
+ in: 'query',
561
+ name: 'storeId',
562
+ scema: j2s( auditViewlogSchema ).swagger,
563
+ require: true,
564
+ },
565
+ {
566
+ in: 'query',
567
+ name: 'moduleType',
568
+ scema: j2s( auditViewlogSchema ).swagger,
569
+ require: true,
570
+ },
571
+ {
572
+ in: 'query',
573
+ name: 'zoneName',
574
+ scema: j2s( auditViewlogSchema ).swagger,
575
+ require: false,
576
+ },
577
+ ],
578
+ responses: {
579
+ 200: { description: 'Successful' },
580
+ 401: { description: 'Unauthorized User' },
581
+ 422: { description: 'Field Error' },
582
+ 500: { description: 'Server Error' },
583
+ 204: { description: 'Not Found' },
584
+ },
585
+
586
+ },
587
+ },
547
588
  '/v3/audit/get-user-credit': {
548
589
  get: {
549
590
  tags: [ 'Audit User Wallet' ],
@@ -239,6 +239,17 @@ export const overviewTableValid = {
239
239
  body: overviewTableSchema,
240
240
  };
241
241
 
242
+ export const auditViewlogSchema = joi.object( {
243
+ fileDate: joi.string().required(),
244
+ storeId: joi.string().required(),
245
+ moduleType: joi.string().required(),
246
+ zoneName: joi.string().optional(),
247
+ } );
248
+
249
+ export const auditViewLogValid = {
250
+ query: auditViewlogSchema,
251
+ };
252
+
242
253
  export const overAllAuditSummarySchema = joi.object( {
243
254
  fromDate: joi.string().required(),
244
255
  toDate: joi.string().required(),
@@ -2,7 +2,7 @@ import express from 'express';
2
2
  import { isAuditDocumentExist, isAuditInputFolderExist, isAuditUser, isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
3
3
  import { 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
- import { auditStoreValid, clientMetricsValid, clientValid, getDraftedDataValid, getFileValid, overAllAuditSummaryValid, overViewCardValid, pendingSummaryTableValid, reTriggerValid, saveDraftValid, saveValid, storeMetricsValid, summarySplitValid, userAuditHistoryValid, userMetricsValid, workSpaceValid, auditImageValid, overviewTableValid } from '../dtos/audit.dtos.js';
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
 
7
7
  export const auditRouter = express.Router();
8
8
 
@@ -42,5 +42,5 @@ auditRouter.get( '/get-user-audit-count', isAllowedSessionHandler, getUserAuditC
42
42
  auditRouter.get( '/get-user-audit-count-mtd', isAllowedSessionHandler, getUserAuditCountMTD );
43
43
 
44
44
  // audit log
45
- auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, auditViewLogs );
45
+ auditRouter.get( '/audit-view-logs', isAllowedSessionHandler, validate( auditViewLogValid ), auditViewLogs );
46
46
  export default auditRouter;