tango-app-api-audit 1.0.16 → 1.0.17

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": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "audit & audit metrics apis",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -324,7 +324,6 @@ export async function storeMetrics( req, res ) {
324
324
 
325
325
  export async function clientMetrics( req, res ) {
326
326
  try {
327
- // const sqs = JSON.parse( process.env.SQS );
328
327
  const inputData = req.body;
329
328
  const limit = inputData.limit || 10;
330
329
  const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
@@ -495,3 +494,172 @@ export async function clientMetrics( req, res ) {
495
494
  return res.sendError( err, 500 );
496
495
  }
497
496
  }
497
+
498
+ export async function userMetrics( req, res ) {
499
+ try {
500
+ const inputData = req.body;
501
+ const limit = inputData.limit || 10;
502
+ const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
503
+ const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
504
+ let filter = [];
505
+ if ( inputData.fileType == 'auditedDate' ) {
506
+ filter.push(
507
+ { createdAt: { $gte: dateRange.start } },
508
+ { updatedAt: { $lte: dateRange.end } },
509
+
510
+ );
511
+ } else {
512
+ filter.push(
513
+ { fileDateISO: { $gte: dateRange.start } },
514
+ { fileDateISO: { $lte: dateRange.end } },
515
+
516
+ );
517
+ }
518
+ if ( inputData?.filterByStatus?.length> 0 ) {
519
+ filter.push(
520
+ { auditStatus: { $in: inputData.filterByStatus } },
521
+ );
522
+ }
523
+ if ( inputData?.filterByuser?.length> 0 ) {
524
+ filter.push(
525
+ { userId: { $in: inputData.filterByuser } },
526
+ );
527
+ }
528
+
529
+ const query = [
530
+ {
531
+ $match: {
532
+ $and: filter,
533
+ },
534
+ },
535
+ {
536
+ $group: {
537
+ _id: { userId: '$userId', fileDate: '$fileDate' },
538
+ userId: { $first: '$userId' },
539
+ fileDate: { $first: '$fileDate' },
540
+ totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, { $sum: 1 } ] },
541
+ beforeCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, { $sum: { $ifNull: [ '$beforeCount', 0 ] } } ] },
542
+ afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, { $sum: { $ifNull: [ '$afterCount', 0 ] } } ] },
543
+ checkIntime: { $first: '$createdAt' },
544
+ checkOutTime: { $last: '$createdAt' },
545
+
546
+ },
547
+ },
548
+ {
549
+ $project: {
550
+ _id: 0,
551
+ userName: '$userId',
552
+ userId: 1,
553
+ fileDate: 1,
554
+ totalCompletedFiles: 1,
555
+ beforeCount: 1,
556
+ afterCount: 1,
557
+ mappingPerc: { $round: [
558
+ { $multiply: [
559
+ { $divide: [ '$afterCount', 'beforeCount' ] }, 100,
560
+ ] }, 2,
561
+ ] },
562
+ checkIntime: 1,
563
+ checkOutTime: 1,
564
+ differenceInSeconds: {
565
+ $divide: [ { $subtract: [ '$checkIntime', '$checkoutTime' ] }, 1000 ],
566
+ },
567
+ },
568
+ },
569
+ {
570
+ $project: {
571
+ userName: 1,
572
+ userId: 1,
573
+ fileDate: 1,
574
+ totalCompletedFiles: 1,
575
+ beforeCount: 1,
576
+ afterCount: 1,
577
+ checkIntime: 1,
578
+ checkOutTime: 1,
579
+ mappingPerc: 1,
580
+ hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
581
+ minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
582
+ seconds: { $mod: [ '$differenceInSeconds', 60 ] },
583
+ },
584
+ },
585
+ {
586
+ $project: {
587
+ event: 1,
588
+ userName: 1,
589
+ userId: 1,
590
+ fileDate: 1,
591
+ totalCompletedFiles: 1,
592
+ beforeCount: 1,
593
+ afterCount: 1,
594
+ checkIntime: 1,
595
+ checkOutTime: 1,
596
+ workingHours: {
597
+ $concat: [
598
+ { $toString: '$hours' }, ':',
599
+ { $substr: [ { $toString: { $add: [ { $cond: [ { $lt: [ '$minutes', 10 ] }, '0', '' ] }, '$minutes' ] } }, 0, 2 ] }, ':',
600
+ { $substr: [ { $toString: { $add: [ { $cond: [ { $lt: [ '$seconds', 10 ] }, '0', '' ] }, '$seconds' ] } }, 0, 2 ] },
601
+ ],
602
+ },
603
+ },
604
+ },
605
+ ];
606
+ if ( inputData.searchValue && inputData.searchValue!== '' ) {
607
+ query.push( {
608
+ $match: {
609
+ $or: [
610
+ { clientId: { $regex: inputData.searchValue, $options: 'i' } },
611
+ { clientName: { $regex: inputData.searchValue, $options: 'i' } },
612
+ ],
613
+
614
+ },
615
+ } );
616
+ }
617
+ if ( inputData.sortColumnName ) {
618
+ const sortBy = inputData.sortBy || -1;
619
+ query.push( {
620
+ $sort: { [inputData.sortColumName]: sortBy },
621
+ },
622
+ );
623
+ }
624
+
625
+ const count = await aggregateUserAudit( query );
626
+ if ( count.length == 0 ) {
627
+ return res.sendError( 'No Data Found', 204 );
628
+ }
629
+
630
+ query.push(
631
+ { $skip: offset },
632
+ { $limit: limit },
633
+ );
634
+ if ( inputData.isExport ) {
635
+ query.push(
636
+ {
637
+ $project: {
638
+ '_id': 0,
639
+ 'File Date': '$fileDate',
640
+ 'zuser Name': '$userName',
641
+ 'User Id': '$userId',
642
+ 'Total Completed Files Count': '$totalCompletedFiles',
643
+ 'Total efore Count': '$beforeCount',
644
+ 'Total After Count': '$afterCount',
645
+ 'check Intime': '$checkIntime',
646
+ 'check OutTime': '$checkOutTime',
647
+ 'working Hours': '$workingHours',
648
+ },
649
+ },
650
+ );
651
+ }
652
+
653
+
654
+ const result = await aggregateUserAudit( query );
655
+ if ( inputData.isExport ) {
656
+ await download( result, res );
657
+ return;
658
+ }
659
+ return res.sendSuccess( { result: result, count: count.length } );
660
+ } catch ( error ) {
661
+ const err = error.error || 'Internal Server Error';
662
+ logger.info( { error: error, message: req.body, function: 'clientMetrics' } );
663
+ return res.sendError( err, 500 );
664
+ }
665
+ }
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { clientMetricsSchema, getAuditImagesSchema, storeMetricsSchema, userAuditHistorySchema } from '../dtos/auditMetrics.dtos.js';
2
+ import { clientMetricsSchema, getAuditImagesSchema, storeMetricsSchema, userAuditHistorySchema, userMetricsSchema } from '../dtos/auditMetrics.dtos.js';
3
3
 
4
4
  export const auditMetricsDocs = {
5
5
 
@@ -91,4 +91,26 @@ export const auditMetricsDocs = {
91
91
  },
92
92
  },
93
93
  },
94
+ '/v3/audit-metrics/user-metrics': {
95
+ post: {
96
+ tags: [ 'Audit Metrics' ],
97
+ description: `Get list of file wise details with date range and users`,
98
+ operationId: 'client-metrics',
99
+ parameters: {},
100
+ requestBody: {
101
+ content: {
102
+ 'application/json': {
103
+ schema: j2s( userMetricsSchema ).swagger,
104
+ },
105
+ },
106
+ },
107
+ responses: {
108
+ 200: { description: 'Successful' },
109
+ 401: { description: 'Unauthorized User' },
110
+ 422: { description: 'Field Error' },
111
+ 500: { description: 'Server Error' },
112
+ 204: { description: 'Not Found' },
113
+ },
114
+ },
115
+ },
94
116
  };
@@ -55,7 +55,6 @@ export const saveSchema = joi.object(
55
55
  storeId: joi.string().required(),
56
56
  fileDate: joi.string().required(),
57
57
  auditType: joi.string().required(),
58
- fileDate: joi.string().required(),
59
58
  beforeCount: joi.number().required(),
60
59
  junkCount: joi.number().required(),
61
60
  junk: joi.array().required(),
@@ -74,3 +74,23 @@ export const clientMetricsSchema = joi.object(
74
74
  export const clientMetricsValid = {
75
75
  body: clientMetricsSchema,
76
76
  };
77
+
78
+ export const userMetricsSchema = joi.object(
79
+ {
80
+ fromDate: joi.string().required(),
81
+ toDate: joi.string().required(),
82
+ fileType: joi.string().required(),
83
+ searchValue: joi.string().optional().allow( '' ),
84
+ filterByUser: joi.array().optional(),
85
+ filterByStatus: joi.array().optional(),
86
+ sortColumnName: joi.string().optional(),
87
+ sortBy: joi.number().optional(),
88
+ limit: joi.number().optional(),
89
+ offset: joi.number().optional(),
90
+ isExport: joi.boolean().optional(),
91
+ },
92
+ );
93
+
94
+ export const userMetricsValid = {
95
+ body: userMetricsSchema,
96
+ };
@@ -1,8 +1,8 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
4
- import { clientMetrics, getAuditImageList, storeMetrics, userAuditHistory } from '../controllers/auditMetrics.controllers.js';
5
- import { clientMetricsValid, getAuditImagesValid, storeMetricsValid, userAuditHistoryValid } from '../dtos/auditMetrics.dtos.js';
4
+ import { clientMetrics, getAuditImageList, storeMetrics, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
5
+ import { clientMetricsValid, getAuditImagesValid, storeMetricsValid, userAuditHistoryValid, userMetricsValid } from '../dtos/auditMetrics.dtos.js';
6
6
 
7
7
  export const auditMetricsRouter = express.Router();
8
8
 
@@ -10,5 +10,6 @@ auditMetricsRouter.post( '/get-audit-images', validate( getAuditImagesValid ), g
10
10
  auditMetricsRouter.post( '/user-audit-history', validate( userAuditHistoryValid ), isAllowedSessionHandler, userAuditHistory );
11
11
  auditMetricsRouter.post( '/store-metrics', validate( storeMetricsValid ), isAllowedSessionHandler, storeMetrics );
12
12
  auditMetricsRouter.post( '/client-metrics', validate( clientMetricsValid ), isAllowedSessionHandler, clientMetrics );
13
+ auditMetricsRouter.post( '/user-metrics', validate( userMetricsValid ), isAllowedSessionHandler, userMetrics );
13
14
 
14
15
  export default auditMetricsRouter;
@@ -0,0 +1,8 @@
1
+ import { Router } from 'express';
2
+ import { isAllowedSessionHandler } from 'tango-app-api-middleware';
3
+
4
+ export const userRouter = Router();
5
+
6
+ userRouter.get( '/audit-users', isAllowedSessionHandler, auditUserList );
7
+
8
+ export default userRouter;