tango-app-api-audit 1.0.19 → 1.0.21
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
|
@@ -3,20 +3,9 @@ import { aggregateAuditClientData } from '../service/auditClientData.service.js'
|
|
|
3
3
|
import { aggregateUserAudit } from '../service/userAudit.service.js';
|
|
4
4
|
import mongoose from 'mongoose';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
|
+
import { aggregateStoreAudit } from '../service/storeAudit.service.js';
|
|
6
7
|
// import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
export async function getAuditImageList( req, res ) {
|
|
10
|
-
// try {
|
|
11
|
-
// logger.info( { env: env } );
|
|
12
|
-
// const inputData = req.body;
|
|
13
|
-
// return res.sendSuccess( { result: inputData, config: env.cloud.aws.region } );
|
|
14
|
-
// } catch ( error ) {
|
|
15
|
-
// logger.info( { error: error, message: req.body, function: 'getAuditImageList' } );
|
|
16
|
-
// return res.sendError( error );
|
|
17
|
-
// }
|
|
18
|
-
}
|
|
19
|
-
|
|
20
9
|
export async function userAuditHistory( req, res ) {
|
|
21
10
|
try {
|
|
22
11
|
const inputData = req.body;
|
|
@@ -504,7 +493,7 @@ export async function userMetrics( req, res ) {
|
|
|
504
493
|
let filter = [];
|
|
505
494
|
if ( inputData.fileType == 'auditedDate' ) {
|
|
506
495
|
filter.push(
|
|
507
|
-
{
|
|
496
|
+
{ updatedAt: { $gte: dateRange.start } },
|
|
508
497
|
{ updatedAt: { $lte: dateRange.end } },
|
|
509
498
|
|
|
510
499
|
);
|
|
@@ -520,9 +509,11 @@ export async function userMetrics( req, res ) {
|
|
|
520
509
|
{ auditStatus: { $in: inputData.filterByStatus } },
|
|
521
510
|
);
|
|
522
511
|
}
|
|
523
|
-
if ( inputData?.
|
|
512
|
+
if ( inputData?.filterByUser?.length> 0 ) {
|
|
513
|
+
const temp = inputData.filterByUser.map( ( item ) => new mongoose.Types.ObjectId( item ) );
|
|
514
|
+
logger.info( { temp: temp } );
|
|
524
515
|
filter.push(
|
|
525
|
-
{ userId: { $in:
|
|
516
|
+
{ userId: { $in: temp } },
|
|
526
517
|
);
|
|
527
518
|
}
|
|
528
519
|
|
|
@@ -532,23 +523,33 @@ export async function userMetrics( req, res ) {
|
|
|
532
523
|
$and: filter,
|
|
533
524
|
},
|
|
534
525
|
},
|
|
526
|
+
{
|
|
527
|
+
$project: {
|
|
528
|
+
userId: 1,
|
|
529
|
+
fileDate: 1,
|
|
530
|
+
startTime: 1,
|
|
531
|
+
endTime: 1,
|
|
532
|
+
totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
533
|
+
beforeCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$beforeCount', 0 ] },
|
|
534
|
+
afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
|
|
535
|
+
},
|
|
536
|
+
},
|
|
535
537
|
{
|
|
536
538
|
$group: {
|
|
537
539
|
_id: { userId: '$userId', fileDate: '$fileDate' },
|
|
538
540
|
userId: { $first: '$userId' },
|
|
539
541
|
fileDate: { $first: '$fileDate' },
|
|
540
|
-
totalCompletedFiles: { $
|
|
541
|
-
beforeCount: { $
|
|
542
|
-
afterCount: { $
|
|
543
|
-
checkIntime: { $first: '$
|
|
544
|
-
checkOutTime: { $last: '$
|
|
542
|
+
totalCompletedFiles: { $sum: '$totalCompletedFiles' },
|
|
543
|
+
beforeCount: { $sum: '$beforeCount' },
|
|
544
|
+
afterCount: { $sum: '$afterCount' },
|
|
545
|
+
checkIntime: { $first: '$startTime' },
|
|
546
|
+
checkOutTime: { $last: '$endTime' },
|
|
545
547
|
|
|
546
548
|
},
|
|
547
549
|
},
|
|
548
550
|
{
|
|
549
551
|
$project: {
|
|
550
552
|
_id: 0,
|
|
551
|
-
userName: '$userId',
|
|
552
553
|
userId: 1,
|
|
553
554
|
fileDate: 1,
|
|
554
555
|
totalCompletedFiles: 1,
|
|
@@ -556,19 +557,18 @@ export async function userMetrics( req, res ) {
|
|
|
556
557
|
afterCount: 1,
|
|
557
558
|
mappingPerc: { $round: [
|
|
558
559
|
{ $multiply: [
|
|
559
|
-
{ $divide: [ '$afterCount', 'beforeCount' ] }, 100,
|
|
560
|
+
{ $divide: [ '$afterCount', '$beforeCount' ] }, 100,
|
|
560
561
|
] }, 2,
|
|
561
562
|
] },
|
|
562
563
|
checkIntime: 1,
|
|
563
564
|
checkOutTime: 1,
|
|
564
565
|
differenceInSeconds: {
|
|
565
|
-
$divide: [ { $subtract: [ '$
|
|
566
|
+
$divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
|
|
566
567
|
},
|
|
567
568
|
},
|
|
568
569
|
},
|
|
569
570
|
{
|
|
570
571
|
$project: {
|
|
571
|
-
userName: 1,
|
|
572
572
|
userId: 1,
|
|
573
573
|
fileDate: 1,
|
|
574
574
|
totalCompletedFiles: 1,
|
|
@@ -585,7 +585,40 @@ export async function userMetrics( req, res ) {
|
|
|
585
585
|
{
|
|
586
586
|
$project: {
|
|
587
587
|
event: 1,
|
|
588
|
-
|
|
588
|
+
userId: 1,
|
|
589
|
+
fileDate: 1,
|
|
590
|
+
totalCompletedFiles: 1,
|
|
591
|
+
beforeCount: 1,
|
|
592
|
+
afterCount: 1,
|
|
593
|
+
checkIntime: 1,
|
|
594
|
+
checkOutTime: 1,
|
|
595
|
+
hours: {
|
|
596
|
+
$cond: {
|
|
597
|
+
if: { $lt: [ '$hours', 10 ] },
|
|
598
|
+
then: { $concat: [ '0', { $toString: { $round: [ '$hours', 0 ] } } ] },
|
|
599
|
+
else: { $toString: { $round: [ '$hours', 0 ] } },
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
minutes: {
|
|
603
|
+
$cond: {
|
|
604
|
+
if: { $lt: [ '$minutes', 10 ] },
|
|
605
|
+
then: { $concat: [ '0', { $toString: { $round: [ '$minutes', 0 ] } } ] },
|
|
606
|
+
else: { $toString: { $round: [ '$minutes', 0 ] } },
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
seconds: {
|
|
610
|
+
$cond: {
|
|
611
|
+
if: { $lt: [ '$seconds', 10 ] },
|
|
612
|
+
then: { $concat: [ '0', { $toString: { $round: [ '$seconds', 0 ] } } ] },
|
|
613
|
+
else: { $toString: { $round: [ '$seconds', 0 ] } },
|
|
614
|
+
},
|
|
615
|
+
},
|
|
616
|
+
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
$project: {
|
|
621
|
+
event: 1,
|
|
589
622
|
userId: 1,
|
|
590
623
|
fileDate: 1,
|
|
591
624
|
totalCompletedFiles: 1,
|
|
@@ -594,14 +627,50 @@ export async function userMetrics( req, res ) {
|
|
|
594
627
|
checkIntime: 1,
|
|
595
628
|
checkOutTime: 1,
|
|
596
629
|
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
|
-
],
|
|
630
|
+
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
602
631
|
},
|
|
603
632
|
},
|
|
604
633
|
},
|
|
634
|
+
{
|
|
635
|
+
$lookup: {
|
|
636
|
+
from: 'users',
|
|
637
|
+
let: { userId: '$userId' },
|
|
638
|
+
pipeline: [
|
|
639
|
+
{
|
|
640
|
+
$match: {
|
|
641
|
+
$expr: {
|
|
642
|
+
$eq: [ '$_id', '$$userId' ],
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
$project: {
|
|
648
|
+
_id: 0,
|
|
649
|
+
userName: 1,
|
|
650
|
+
},
|
|
651
|
+
},
|
|
652
|
+
], as: 'userInfo',
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
$unwind: {
|
|
657
|
+
path: '$userInfo', preserveNullAndEmptyArrays: true,
|
|
658
|
+
},
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
$project: {
|
|
662
|
+
event: 1,
|
|
663
|
+
userName: '$userInfo.userName',
|
|
664
|
+
userId: 1,
|
|
665
|
+
fileDate: 1,
|
|
666
|
+
totalCompletedFiles: 1,
|
|
667
|
+
beforeCount: 1,
|
|
668
|
+
afterCount: 1,
|
|
669
|
+
checkIntime: 1,
|
|
670
|
+
checkOutTime: 1,
|
|
671
|
+
workingHours: 1,
|
|
672
|
+
},
|
|
673
|
+
},
|
|
605
674
|
];
|
|
606
675
|
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
607
676
|
query.push( {
|
|
@@ -663,3 +732,85 @@ export async function userMetrics( req, res ) {
|
|
|
663
732
|
return res.sendError( err, 500 );
|
|
664
733
|
}
|
|
665
734
|
}
|
|
735
|
+
|
|
736
|
+
export async function overViewCard( req, res ) {
|
|
737
|
+
try {
|
|
738
|
+
const inputData = req.body;
|
|
739
|
+
const temp = {
|
|
740
|
+
totalCount: 0,
|
|
741
|
+
auditFileCount: 0,
|
|
742
|
+
ReAuditFileCount: 0,
|
|
743
|
+
inprogressCount: 0,
|
|
744
|
+
completedCount: 0,
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
748
|
+
let filters =[
|
|
749
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
750
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
751
|
+
];
|
|
752
|
+
if ( inputData.clientId.length > 0 ) {
|
|
753
|
+
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
754
|
+
}
|
|
755
|
+
const query =[
|
|
756
|
+
{
|
|
757
|
+
$match: {
|
|
758
|
+
$and: filters,
|
|
759
|
+
},
|
|
760
|
+
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
$project: {
|
|
764
|
+
auditFileCount: {
|
|
765
|
+
$cond: [
|
|
766
|
+
{ $eq: [ '$auditType', 'Audit' ] }, 1, 0,
|
|
767
|
+
],
|
|
768
|
+
},
|
|
769
|
+
ReAuditFileCount: {
|
|
770
|
+
$cond: [
|
|
771
|
+
{ $eq: [ '$auditType', 'ReAudit' ] }, 1, 0,
|
|
772
|
+
],
|
|
773
|
+
},
|
|
774
|
+
inprogressCount: {
|
|
775
|
+
$cond: [
|
|
776
|
+
{ $ne: [ '$status', 'completed' ] }, 1, 0,
|
|
777
|
+
],
|
|
778
|
+
},
|
|
779
|
+
completedCount: {
|
|
780
|
+
$cond: [
|
|
781
|
+
{ $eq: [ '$status', 'completed' ] }, 1, 0,
|
|
782
|
+
],
|
|
783
|
+
},
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
$group: {
|
|
788
|
+
_id: { fileDate: '$fileDate', clientId: '$clientId' },
|
|
789
|
+
totalCount: { $sum: 1 },
|
|
790
|
+
auditFileCount: { $sum: '$auditFileCount' },
|
|
791
|
+
ReAuditFileCount: { $sum: '$ReAuditFileCount' },
|
|
792
|
+
inprogressCount: { $sum: '$inprogressCount' },
|
|
793
|
+
completedCount: { $sum: '$completedCount' },
|
|
794
|
+
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
$project: {
|
|
799
|
+
_id: 0,
|
|
800
|
+
totalCount: 1,
|
|
801
|
+
auditFileCount: 1,
|
|
802
|
+
ReAuditFileCount: 1,
|
|
803
|
+
inprogressCount: 1,
|
|
804
|
+
completedCount: 1,
|
|
805
|
+
},
|
|
806
|
+
},
|
|
807
|
+
];
|
|
808
|
+
const result = await aggregateStoreAudit( query );
|
|
809
|
+
logger.info( { result: result } );
|
|
810
|
+
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
811
|
+
} catch ( error ) {
|
|
812
|
+
const err = error.message || 'Internal Server Error';
|
|
813
|
+
logger.error( { error: error, message: req.body, function: 'overViewCard' } );
|
|
814
|
+
return res.sendError( err, 500 );
|
|
815
|
+
}
|
|
816
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { clientMetricsSchema, getAuditImagesSchema, storeMetricsSchema, userAuditHistorySchema, userMetricsSchema } from '../dtos/auditMetrics.dtos.js';
|
|
2
|
+
import { clientMetricsSchema, getAuditImagesSchema, overViewCardSchema, storeMetricsSchema, userAuditHistorySchema, userMetricsSchema } from '../dtos/auditMetrics.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const auditMetricsDocs = {
|
|
5
5
|
|
|
@@ -95,7 +95,7 @@ export const auditMetricsDocs = {
|
|
|
95
95
|
post: {
|
|
96
96
|
tags: [ 'Audit Metrics' ],
|
|
97
97
|
description: `Get list of file wise details with date range and users`,
|
|
98
|
-
operationId: '
|
|
98
|
+
operationId: 'user-metrics',
|
|
99
99
|
parameters: {},
|
|
100
100
|
requestBody: {
|
|
101
101
|
content: {
|
|
@@ -113,4 +113,26 @@ export const auditMetricsDocs = {
|
|
|
113
113
|
},
|
|
114
114
|
},
|
|
115
115
|
},
|
|
116
|
+
'/v3/audit-metrics/overview-card': {
|
|
117
|
+
post: {
|
|
118
|
+
tags: [ 'Audit Metrics' ],
|
|
119
|
+
description: `Get overall high level audited files count splitup`,
|
|
120
|
+
operationId: 'overview-card',
|
|
121
|
+
parameters: {},
|
|
122
|
+
requestBody: {
|
|
123
|
+
content: {
|
|
124
|
+
'application/json': {
|
|
125
|
+
schema: j2s( overViewCardSchema ).swagger,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
responses: {
|
|
130
|
+
200: { description: 'Successful' },
|
|
131
|
+
401: { description: 'Unauthorized User' },
|
|
132
|
+
422: { description: 'Field Error' },
|
|
133
|
+
500: { description: 'Server Error' },
|
|
134
|
+
204: { description: 'Not Found' },
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
116
138
|
};
|
|
@@ -94,3 +94,15 @@ export const userMetricsSchema = joi.object(
|
|
|
94
94
|
export const userMetricsValid = {
|
|
95
95
|
body: userMetricsSchema,
|
|
96
96
|
};
|
|
97
|
+
|
|
98
|
+
export const overViewCardSchema = joi.object(
|
|
99
|
+
{
|
|
100
|
+
fromDate: joi.string().required(),
|
|
101
|
+
toDate: joi.string().required(),
|
|
102
|
+
clientId: joi.array().optional(),
|
|
103
|
+
},
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
export const overViewCardValid = {
|
|
107
|
+
body: overViewCardSchema,
|
|
108
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { clientMetrics,
|
|
5
|
-
import { clientMetricsValid,
|
|
4
|
+
import { clientMetrics, overViewCard, storeMetrics, userAuditHistory, userMetrics } from '../controllers/auditMetrics.controllers.js';
|
|
5
|
+
import { clientMetricsValid, overViewCardValid, storeMetricsValid, userAuditHistoryValid, userMetricsValid } from '../dtos/auditMetrics.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditMetricsRouter = express.Router();
|
|
8
8
|
|
|
9
|
-
auditMetricsRouter.post( '/
|
|
10
|
-
auditMetricsRouter.post( '/
|
|
11
|
-
auditMetricsRouter.post( '/
|
|
12
|
-
auditMetricsRouter.post( '/
|
|
13
|
-
auditMetricsRouter.post( '/
|
|
9
|
+
auditMetricsRouter.post( '/user-audit-history', isAllowedSessionHandler, validate( userAuditHistoryValid ), userAuditHistory );
|
|
10
|
+
auditMetricsRouter.post( '/store-metrics', isAllowedSessionHandler, validate( storeMetricsValid ), storeMetrics );
|
|
11
|
+
auditMetricsRouter.post( '/client-metrics', isAllowedSessionHandler, validate( clientMetricsValid ), clientMetrics );
|
|
12
|
+
auditMetricsRouter.post( '/user-metrics', isAllowedSessionHandler, validate( userMetricsValid ), userMetrics );
|
|
13
|
+
auditMetricsRouter.post( '/overview-card', isAllowedSessionHandler, validate( overViewCardValid ), overViewCard );
|
|
14
14
|
|
|
15
15
|
export default auditMetricsRouter;
|