tango-app-api-audit 1.0.20 → 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
|
|
|
@@ -536,8 +527,8 @@ export async function userMetrics( req, res ) {
|
|
|
536
527
|
$project: {
|
|
537
528
|
userId: 1,
|
|
538
529
|
fileDate: 1,
|
|
539
|
-
|
|
540
|
-
|
|
530
|
+
startTime: 1,
|
|
531
|
+
endTime: 1,
|
|
541
532
|
totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
542
533
|
beforeCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$beforeCount', 0 ] },
|
|
543
534
|
afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
|
|
@@ -551,15 +542,14 @@ export async function userMetrics( req, res ) {
|
|
|
551
542
|
totalCompletedFiles: { $sum: '$totalCompletedFiles' },
|
|
552
543
|
beforeCount: { $sum: '$beforeCount' },
|
|
553
544
|
afterCount: { $sum: '$afterCount' },
|
|
554
|
-
checkIntime: { $first: '$
|
|
555
|
-
checkOutTime: { $last: '$
|
|
545
|
+
checkIntime: { $first: '$startTime' },
|
|
546
|
+
checkOutTime: { $last: '$endTime' },
|
|
556
547
|
|
|
557
548
|
},
|
|
558
549
|
},
|
|
559
550
|
{
|
|
560
551
|
$project: {
|
|
561
552
|
_id: 0,
|
|
562
|
-
userName: '$userId',
|
|
563
553
|
userId: 1,
|
|
564
554
|
fileDate: 1,
|
|
565
555
|
totalCompletedFiles: 1,
|
|
@@ -573,13 +563,12 @@ export async function userMetrics( req, res ) {
|
|
|
573
563
|
checkIntime: 1,
|
|
574
564
|
checkOutTime: 1,
|
|
575
565
|
differenceInSeconds: {
|
|
576
|
-
$divide: [ { $subtract: [ '$
|
|
566
|
+
$divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
|
|
577
567
|
},
|
|
578
568
|
},
|
|
579
569
|
},
|
|
580
570
|
{
|
|
581
571
|
$project: {
|
|
582
|
-
userName: 1,
|
|
583
572
|
userId: 1,
|
|
584
573
|
fileDate: 1,
|
|
585
574
|
totalCompletedFiles: 1,
|
|
@@ -596,7 +585,40 @@ export async function userMetrics( req, res ) {
|
|
|
596
585
|
{
|
|
597
586
|
$project: {
|
|
598
587
|
event: 1,
|
|
599
|
-
|
|
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,
|
|
600
622
|
userId: 1,
|
|
601
623
|
fileDate: 1,
|
|
602
624
|
totalCompletedFiles: 1,
|
|
@@ -605,14 +627,50 @@ export async function userMetrics( req, res ) {
|
|
|
605
627
|
checkIntime: 1,
|
|
606
628
|
checkOutTime: 1,
|
|
607
629
|
workingHours: {
|
|
608
|
-
$concat: [
|
|
609
|
-
{ $toString: '$hours' }, ':',
|
|
610
|
-
{ $substr: [ { $toString: { $add: [ { $cond: [ { $lt: [ '$minutes', 10 ] }, '0', '' ] }, '$minutes' ] } }, 0, 2 ] }, ':',
|
|
611
|
-
{ $substr: [ { $toString: { $add: [ { $cond: [ { $lt: [ '$seconds', 10 ] }, '0', '' ] }, '$seconds' ] } }, 0, 2 ] },
|
|
612
|
-
],
|
|
630
|
+
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
613
631
|
},
|
|
614
632
|
},
|
|
615
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
|
+
},
|
|
616
674
|
];
|
|
617
675
|
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
618
676
|
query.push( {
|
|
@@ -674,3 +732,85 @@ export async function userMetrics( req, res ) {
|
|
|
674
732
|
return res.sendError( err, 500 );
|
|
675
733
|
}
|
|
676
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;
|