tango-app-api-audit 1.0.15 → 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 +1 -1
- package/src/controllers/audit.controllers.js +334 -99
- package/src/controllers/auditMetrics.controllers.js +169 -1
- package/src/docs/auditMetrics.docs.js +23 -1
- package/src/dtos/audit.dtos.js +0 -2
- package/src/dtos/auditMetrics.dtos.js +20 -0
- package/src/routes/auditMetrics.routes.js +3 -2
- package/src/routes/user.routes.js +8 -0
- package/src/service/storeAudit.service.js +4 -0
- package/src/validation/audit.validation.js +1 -1
package/package.json
CHANGED
|
@@ -1,18 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
chunkArray,
|
|
3
|
+
download,
|
|
4
|
+
fileUpload,
|
|
5
|
+
getJsonFileData,
|
|
6
|
+
getUTC,
|
|
7
|
+
insertOpenSearchData,
|
|
8
|
+
listFileByPath,
|
|
9
|
+
listFileWithoutLimit,
|
|
10
|
+
signedUrl,
|
|
11
|
+
} from 'tango-app-api-middleware';
|
|
12
|
+
import {
|
|
13
|
+
aggregateUserAudit,
|
|
14
|
+
createUserAudit,
|
|
15
|
+
findOneUserAudit,
|
|
16
|
+
updateOneUserAudit,
|
|
17
|
+
} from '../service/userAudit.service.js';
|
|
18
|
+
import {
|
|
19
|
+
aggregateAssignAudit,
|
|
20
|
+
updateOneAssignAudit,
|
|
21
|
+
} from '../service/assignAudit.service.js';
|
|
4
22
|
import { findOneUser } from '../service/user.service.js';
|
|
5
23
|
import dayjs from 'dayjs';
|
|
6
|
-
import { aggregateClient } from '../service/client.service.js';
|
|
24
|
+
import { aggregateClient, findClient } from '../service/client.service.js';
|
|
7
25
|
import { logger } from 'tango-app-api-middleware';
|
|
8
|
-
import {
|
|
9
|
-
|
|
26
|
+
import {
|
|
27
|
+
listQueue,
|
|
28
|
+
sqsReceive,
|
|
29
|
+
sendMessageToQueue,
|
|
30
|
+
} from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
31
|
+
import {
|
|
32
|
+
aggregateStoreAudit,
|
|
33
|
+
createStoreAudit,
|
|
34
|
+
findOneStoreAudit,
|
|
35
|
+
updateOneStoreAudit,
|
|
36
|
+
} from '../service/storeAudit.service.js';
|
|
10
37
|
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
11
38
|
import _ from 'lodash';
|
|
12
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
createAuditLog,
|
|
41
|
+
findOneAuditLog,
|
|
42
|
+
} from '../service/auditLog.service.js';
|
|
13
43
|
import { findOneStore } from '../service/store.service.js';
|
|
14
|
-
import {
|
|
15
|
-
|
|
44
|
+
import {
|
|
45
|
+
mapCustomer,
|
|
46
|
+
mapEmployee,
|
|
47
|
+
mapJunk,
|
|
48
|
+
splitB20000,
|
|
49
|
+
splitE0,
|
|
50
|
+
splitG20000,
|
|
51
|
+
} from '../validation/audit.validation.js';
|
|
52
|
+
import mongoose from 'mongoose';
|
|
16
53
|
export async function getAuditFile( req, res ) {
|
|
17
54
|
try {
|
|
18
55
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
@@ -33,9 +70,7 @@ export async function getAuditFile( req, res ) {
|
|
|
33
70
|
{ createdAt: { $gte: start } },
|
|
34
71
|
{ createdAt: { $lte: end } },
|
|
35
72
|
],
|
|
36
|
-
|
|
37
73
|
},
|
|
38
|
-
|
|
39
74
|
},
|
|
40
75
|
{
|
|
41
76
|
$sort: { createdAt: -1 },
|
|
@@ -46,7 +81,8 @@ export async function getAuditFile( req, res ) {
|
|
|
46
81
|
];
|
|
47
82
|
|
|
48
83
|
const userDetails = await aggregateUserAudit( userQuery );
|
|
49
|
-
const auditStatus =
|
|
84
|
+
const auditStatus =
|
|
85
|
+
userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
50
86
|
|
|
51
87
|
switch ( auditStatus ) {
|
|
52
88
|
case null:
|
|
@@ -64,24 +100,35 @@ export async function getAuditFile( req, res ) {
|
|
|
64
100
|
const userAssign = await aggregateAssignAudit( query );
|
|
65
101
|
if ( userAssign.length > 0 ) {
|
|
66
102
|
logger.info( 'Hit in user assign', { inputData } );
|
|
67
|
-
|
|
68
|
-
msg = {
|
|
103
|
+
userAssign[0].fileType == 'Audit' ?
|
|
104
|
+
( msg = {
|
|
69
105
|
store_id: userAssign[0].storeId,
|
|
70
106
|
curr_date: userAssign[0].fileDate,
|
|
71
107
|
total_count: userAssign[0].fileCount,
|
|
72
|
-
} :
|
|
108
|
+
} ) :
|
|
109
|
+
( msg = {
|
|
73
110
|
store_id: userAssign[0].storeId,
|
|
74
111
|
curr_date: userAssign[0].fileDate,
|
|
75
112
|
audit_type: userAssign[0].fileType,
|
|
76
113
|
total_count: userAssign[0].fileCount,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
|
|
114
|
+
} );
|
|
115
|
+
await updateOneAssignAudit(
|
|
116
|
+
{ _id: userAssign[0]._id },
|
|
117
|
+
{ isCompleted: true },
|
|
118
|
+
);
|
|
119
|
+
logger.info( 'Hit in auditUserAssignModel updateOne', {
|
|
120
|
+
_id: userAssign[0]._id,
|
|
121
|
+
isCompleted: true,
|
|
122
|
+
} );
|
|
80
123
|
} else {
|
|
81
124
|
logger.info( 'Hit in new file', { inputData } );
|
|
82
125
|
const consumer = await sqsReceive( inputData.queueName );
|
|
83
126
|
if ( !consumer ) {
|
|
84
|
-
logger.error( {
|
|
127
|
+
logger.error( {
|
|
128
|
+
error: consumer,
|
|
129
|
+
function: 'getAuditFile',
|
|
130
|
+
message: 'SQS Receive queue is empty',
|
|
131
|
+
} );
|
|
85
132
|
return res.sendError( `${inputData.queueName} is Empty`, 204 );
|
|
86
133
|
}
|
|
87
134
|
msg = JSON.parse( consumer );
|
|
@@ -90,15 +137,26 @@ export async function getAuditFile( req, res ) {
|
|
|
90
137
|
|
|
91
138
|
case 'drafted':
|
|
92
139
|
logger.info( 'userDetails drafted', { inputData } );
|
|
93
|
-
const log = await findOneAuditLog(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
140
|
+
const log = await findOneAuditLog(
|
|
141
|
+
{
|
|
142
|
+
userId: userDetails[0].userId,
|
|
143
|
+
fileDate: userDetails[0].fileDate,
|
|
144
|
+
storeId: userDetails[0].storeId,
|
|
145
|
+
totalCount: userDetails[0].beforeCount,
|
|
146
|
+
},
|
|
147
|
+
{},
|
|
148
|
+
{ createdAt: -1 },
|
|
149
|
+
);
|
|
99
150
|
if ( !log ) {
|
|
100
|
-
await updateOneUserAudit(
|
|
101
|
-
|
|
151
|
+
await updateOneUserAudit(
|
|
152
|
+
{ _id: userDetails[0]._id },
|
|
153
|
+
{ $set: { isDraft: false, auditStatus: 'skipped' } },
|
|
154
|
+
);
|
|
155
|
+
logger.info( 'audit update in drafted', {
|
|
156
|
+
_id: userDetails[0]._id,
|
|
157
|
+
isDraft: false,
|
|
158
|
+
auditStatus: 'skipped',
|
|
159
|
+
} );
|
|
102
160
|
return res.sendError( 'User saved data has been deleted', 204 );
|
|
103
161
|
}
|
|
104
162
|
const file = {
|
|
@@ -122,7 +180,11 @@ export async function getAuditFile( req, res ) {
|
|
|
122
180
|
};
|
|
123
181
|
|
|
124
182
|
const userdata = await findOneUser( { _id: log.userId } );
|
|
125
|
-
if (
|
|
183
|
+
if (
|
|
184
|
+
!inputData.nextId ||
|
|
185
|
+
inputData.nextId === '' ||
|
|
186
|
+
inputData.nextId == null
|
|
187
|
+
) {
|
|
126
188
|
const logData = {
|
|
127
189
|
userId: log.userId,
|
|
128
190
|
userName: userdata.name,
|
|
@@ -169,10 +231,7 @@ export async function getAuditFile( req, res ) {
|
|
|
169
231
|
break;
|
|
170
232
|
}
|
|
171
233
|
if ( msg.audit_type === 'ReAudit' ) {
|
|
172
|
-
logger.info(
|
|
173
|
-
'Hit in user ReAudit'
|
|
174
|
-
, { inputData },
|
|
175
|
-
);
|
|
234
|
+
logger.info( 'Hit in user ReAudit', { inputData } );
|
|
176
235
|
let reauditInsert = {};
|
|
177
236
|
const [ filterData, auditImage ] = await Promise.all( [
|
|
178
237
|
getFilterData( msg ),
|
|
@@ -246,24 +305,22 @@ export async function getAuditFile( req, res ) {
|
|
|
246
305
|
address: '$storeProfile.address',
|
|
247
306
|
};
|
|
248
307
|
const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
249
|
-
return res.sendSuccess(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
);
|
|
308
|
+
return res.sendSuccess( {
|
|
309
|
+
result: reauditImg,
|
|
310
|
+
count: reauditImg.length,
|
|
311
|
+
storeId: storeInfo?.storeId,
|
|
312
|
+
storeName: storeInfo?.storeName,
|
|
313
|
+
address: storeInfo?.address || '',
|
|
314
|
+
file: {
|
|
315
|
+
store_id: msg.store_id,
|
|
316
|
+
file_date: msg.curr_date,
|
|
317
|
+
type: msg.audit_type || 'ReAudit',
|
|
318
|
+
queueName: inputData.queueName,
|
|
319
|
+
auditId: reauditInsert._id,
|
|
320
|
+
userId: reauditInsert.userId,
|
|
321
|
+
},
|
|
322
|
+
isDraft: reauditInsert.isDraft,
|
|
323
|
+
} );
|
|
267
324
|
}
|
|
268
325
|
const storeId = msg.store_id;
|
|
269
326
|
const fileDate = msg.curr_date;
|
|
@@ -343,7 +400,11 @@ export async function getAuditFile( req, res ) {
|
|
|
343
400
|
insertData = userDetails[0];
|
|
344
401
|
}
|
|
345
402
|
} else {
|
|
346
|
-
logger.error( {
|
|
403
|
+
logger.error( {
|
|
404
|
+
error: { folderPath: folderPath, nextQuery: nextQuery },
|
|
405
|
+
function: 'getAuditFile',
|
|
406
|
+
message: 'Bucket image data not availale',
|
|
407
|
+
} );
|
|
347
408
|
return res.sendError( 'Bucket is Empty', 204 );
|
|
348
409
|
}
|
|
349
410
|
const userdata = await findOneUser( { _id: insertData.userId } );
|
|
@@ -390,7 +451,11 @@ export async function getAuditFile( req, res ) {
|
|
|
390
451
|
isDraft: insertData.isDraft,
|
|
391
452
|
} );
|
|
392
453
|
} catch ( error ) {
|
|
393
|
-
logger.error( {
|
|
454
|
+
logger.error( {
|
|
455
|
+
error: error,
|
|
456
|
+
message: req.query,
|
|
457
|
+
function: 'getAuditFile',
|
|
458
|
+
} );
|
|
394
459
|
return res.sendError( error, 500 );
|
|
395
460
|
}
|
|
396
461
|
}
|
|
@@ -407,17 +472,26 @@ export async function getFilterData( msg ) {
|
|
|
407
472
|
return mappingFile;
|
|
408
473
|
} else {
|
|
409
474
|
const mappingData = await JSON.parse( mappingFile.toString( 'utf-8' ) );
|
|
410
|
-
const filterData = await mappingData.person_data.filter(
|
|
475
|
+
const filterData = await mappingData.person_data.filter(
|
|
476
|
+
( item ) =>
|
|
477
|
+
item.temp_ids < 20000 &&
|
|
478
|
+
item.temp_ids > 0 &&
|
|
479
|
+
item.person_status === '',
|
|
480
|
+
);
|
|
411
481
|
const finalResult = await filterData.map( ( i ) => {
|
|
412
482
|
return { ...i, img: i.index.concat( '_', i.temp_ids ) };
|
|
413
483
|
} );
|
|
414
484
|
return finalResult;
|
|
415
485
|
}
|
|
416
486
|
} catch ( error ) {
|
|
417
|
-
logger.error( {
|
|
487
|
+
logger.error( {
|
|
488
|
+
error: error,
|
|
489
|
+
type: 'MAPPING JSON getFilterData',
|
|
490
|
+
function: 'getFilterData',
|
|
491
|
+
} );
|
|
418
492
|
return error;
|
|
419
493
|
}
|
|
420
|
-
}
|
|
494
|
+
}
|
|
421
495
|
|
|
422
496
|
export async function getAuditImage( msg ) {
|
|
423
497
|
try {
|
|
@@ -464,7 +538,7 @@ export async function getAuditImage( msg ) {
|
|
|
464
538
|
logger.error( { error: error, type: 'GCP BUCKET --getAuditImage' } );
|
|
465
539
|
return error;
|
|
466
540
|
}
|
|
467
|
-
}
|
|
541
|
+
}
|
|
468
542
|
|
|
469
543
|
export const getReauditImg = async ( filter, image ) => {
|
|
470
544
|
const chunkedMappingData = await chunkArray( image, 10 );
|
|
@@ -491,7 +565,9 @@ export async function workSpace( req, res ) {
|
|
|
491
565
|
try {
|
|
492
566
|
const inputData = req.query;
|
|
493
567
|
const limit = inputData.limit || 10;
|
|
494
|
-
const offset =
|
|
568
|
+
const offset = inputData.offset ?
|
|
569
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
570
|
+
0;
|
|
495
571
|
const dateRange = await getUTC( new Date(), new Date() );
|
|
496
572
|
|
|
497
573
|
const temp = [];
|
|
@@ -512,7 +588,7 @@ export async function workSpace( req, res ) {
|
|
|
512
588
|
},
|
|
513
589
|
];
|
|
514
590
|
|
|
515
|
-
if ( inputData.searchValue&& inputData.searchValue!== '' ) {
|
|
591
|
+
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
516
592
|
clientQuery.push( {
|
|
517
593
|
$match: {
|
|
518
594
|
$or: [
|
|
@@ -547,7 +623,6 @@ export async function workSpace( req, res ) {
|
|
|
547
623
|
totalFilesCount: { $last: '$totalFilesCount' },
|
|
548
624
|
clientName: { $last: '$clientName' },
|
|
549
625
|
queueName: { $last: '$queueName' },
|
|
550
|
-
|
|
551
626
|
},
|
|
552
627
|
},
|
|
553
628
|
{
|
|
@@ -584,7 +659,6 @@ export async function workSpace( req, res ) {
|
|
|
584
659
|
_id: { clientId: '$clientId', storeId: '$storeId' },
|
|
585
660
|
clientId: { $first: '$clientId' },
|
|
586
661
|
completedCount: { $sum: '$completed' },
|
|
587
|
-
|
|
588
662
|
},
|
|
589
663
|
},
|
|
590
664
|
{
|
|
@@ -610,7 +684,11 @@ export async function workSpace( req, res ) {
|
|
|
610
684
|
$project: {
|
|
611
685
|
clientId: 1,
|
|
612
686
|
pending: {
|
|
613
|
-
$cond: [
|
|
687
|
+
$cond: [
|
|
688
|
+
{ $or: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted' ] ] } ] },
|
|
689
|
+
1,
|
|
690
|
+
0,
|
|
691
|
+
],
|
|
614
692
|
},
|
|
615
693
|
},
|
|
616
694
|
},
|
|
@@ -620,7 +698,6 @@ export async function workSpace( req, res ) {
|
|
|
620
698
|
clientId: { $first: '$clientId' },
|
|
621
699
|
pendingCount: { $sum: '$pending' },
|
|
622
700
|
totalCount: { $sum: 1 },
|
|
623
|
-
|
|
624
701
|
},
|
|
625
702
|
},
|
|
626
703
|
{
|
|
@@ -631,7 +708,6 @@ export async function workSpace( req, res ) {
|
|
|
631
708
|
totalCount: { $first: '$totalCount' },
|
|
632
709
|
},
|
|
633
710
|
},
|
|
634
|
-
|
|
635
711
|
];
|
|
636
712
|
|
|
637
713
|
const draftedFiles = [
|
|
@@ -682,7 +758,6 @@ export async function workSpace( req, res ) {
|
|
|
682
758
|
{ clientId: { $in: clientList } },
|
|
683
759
|
],
|
|
684
760
|
},
|
|
685
|
-
|
|
686
761
|
},
|
|
687
762
|
{
|
|
688
763
|
$group: {
|
|
@@ -703,13 +778,8 @@ export async function workSpace( req, res ) {
|
|
|
703
778
|
const clientAssign = [
|
|
704
779
|
{
|
|
705
780
|
$match: {
|
|
706
|
-
$and: [
|
|
707
|
-
|
|
708
|
-
{ isCompleted: false },
|
|
709
|
-
{ clientId: { $in: clientList } },
|
|
710
|
-
],
|
|
781
|
+
$and: [ { isCompleted: false }, { clientId: { $in: clientList } } ],
|
|
711
782
|
},
|
|
712
|
-
|
|
713
783
|
},
|
|
714
784
|
{
|
|
715
785
|
$group: {
|
|
@@ -734,9 +804,21 @@ export async function workSpace( req, res ) {
|
|
|
734
804
|
|
|
735
805
|
const clientAssignresult = await aggregateAssignAudit( clientAssign );
|
|
736
806
|
const userAsignCount = await aggregateAssignAudit( userAsign );
|
|
737
|
-
const mergeAll = _.merge(
|
|
807
|
+
const mergeAll = _.merge(
|
|
808
|
+
_.keyBy( clientDetails, 'clientId' ),
|
|
809
|
+
_.keyBy( auditCount, 'clientId' ),
|
|
810
|
+
_.keyBy( draftedCount, 'clientId' ),
|
|
811
|
+
_.keyBy( clientAssignresult, 'clientId' ),
|
|
812
|
+
);
|
|
738
813
|
const finalResult = _.values( mergeAll );
|
|
739
|
-
const merge = _.values(
|
|
814
|
+
const merge = _.values(
|
|
815
|
+
_.merge(
|
|
816
|
+
_.keyBy( finalResult, 'clientId' ),
|
|
817
|
+
_.keyBy( auditDetails, 'clientId' ),
|
|
818
|
+
_.keyBy( userAsignCount, 'clientId' ),
|
|
819
|
+
_.keyBy( CompletedCount, 'clientId' ),
|
|
820
|
+
),
|
|
821
|
+
);
|
|
740
822
|
logger.info( { merge: merge } );
|
|
741
823
|
let totalStores = 0;
|
|
742
824
|
for ( let i = 0; i < merge.length; i++ ) {
|
|
@@ -748,16 +830,42 @@ export async function workSpace( req, res ) {
|
|
|
748
830
|
temp.push( {
|
|
749
831
|
clientId: merge[i].clientId,
|
|
750
832
|
clientName: merge[i].clientName,
|
|
751
|
-
completedCount: merge[i].completedCount ?
|
|
833
|
+
completedCount: merge[i].completedCount ?
|
|
834
|
+
Number( merge[i].completedCount ) :
|
|
835
|
+
0,
|
|
752
836
|
pendingByQueue: Number( pending ),
|
|
753
|
-
pendingByUser:
|
|
837
|
+
pendingByUser:
|
|
838
|
+
merge[i].pendingCount >= 0 ?
|
|
839
|
+
Number( merge[i].pendingCount ) +
|
|
840
|
+
( merge[i].ClientAsignedCount ?
|
|
841
|
+
Number( merge[i].ClientAsignedCount ) :
|
|
842
|
+
0 ) :
|
|
843
|
+
0,
|
|
754
844
|
totalCount: merge[i].totalFilesCount,
|
|
755
845
|
queueName: merge[i].queueName,
|
|
756
846
|
isDraft: merge[i].isDrafted ? merge[i].isDrafted : false,
|
|
757
|
-
isEnable:
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
847
|
+
isEnable:
|
|
848
|
+
Number( pending ) > 0 ||
|
|
849
|
+
merge[i].isDrafted ||
|
|
850
|
+
( merge[i].asignedCount && merge[i].asignedCount > 0 ) ||
|
|
851
|
+
( merge[i].inprogressCount && merge[i].inprogressCount > 0 ) ?
|
|
852
|
+
true :
|
|
853
|
+
false,
|
|
854
|
+
completedRatio: merge[i].totalFilesCount ?
|
|
855
|
+
merge[i].completedCount ?
|
|
856
|
+
Math.round(
|
|
857
|
+
( Number( merge[i].completedCount ) /
|
|
858
|
+
Number( merge[i].totalFilesCount ) ) *
|
|
859
|
+
100,
|
|
860
|
+
) :
|
|
861
|
+
0 :
|
|
862
|
+
0,
|
|
863
|
+
isAssigned:
|
|
864
|
+
merge[i].asignedCount && merge[i].asignedCount > 0 ? true : false,
|
|
865
|
+
Assignedcount:
|
|
866
|
+
merge[i].asignedCount && merge[i].asignedCount > 0 ?
|
|
867
|
+
merge[i].asignedCount :
|
|
868
|
+
0,
|
|
761
869
|
} );
|
|
762
870
|
}
|
|
763
871
|
}
|
|
@@ -779,7 +887,11 @@ export async function workSpace( req, res ) {
|
|
|
779
887
|
await download( exportdata, res );
|
|
780
888
|
return;
|
|
781
889
|
} else {
|
|
782
|
-
return res.sendSuccess( {
|
|
890
|
+
return res.sendSuccess( {
|
|
891
|
+
result: temp,
|
|
892
|
+
count: count.length,
|
|
893
|
+
totalStores: totalStores,
|
|
894
|
+
} );
|
|
783
895
|
}
|
|
784
896
|
} catch ( error ) {
|
|
785
897
|
const err = error.message || 'Internal Server Error';
|
|
@@ -804,16 +916,16 @@ export async function saveDraft( req, res ) {
|
|
|
804
916
|
const userQuery = {
|
|
805
917
|
_id: inputData.auditId,
|
|
806
918
|
};
|
|
807
|
-
let userRecord ={
|
|
919
|
+
let userRecord = {
|
|
808
920
|
isDraft: true,
|
|
809
921
|
auditStatus: 'drafted',
|
|
810
922
|
};
|
|
811
|
-
const storeQuery ={
|
|
923
|
+
const storeQuery = {
|
|
812
924
|
storeId: inputData.storeId,
|
|
813
925
|
fileDate: inputData.fileDate,
|
|
814
926
|
};
|
|
815
927
|
|
|
816
|
-
let storeRecord ={
|
|
928
|
+
let storeRecord = {
|
|
817
929
|
status: 'drafted',
|
|
818
930
|
};
|
|
819
931
|
|
|
@@ -823,7 +935,7 @@ export async function saveDraft( req, res ) {
|
|
|
823
935
|
const isoDateTime = dayjs( isoDate );
|
|
824
936
|
const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
|
|
825
937
|
|
|
826
|
-
userRecord.timeSpent=timeDifferenceInMinutes;
|
|
938
|
+
userRecord.timeSpent = timeDifferenceInMinutes;
|
|
827
939
|
|
|
828
940
|
storeRecord.timeSpent = timeDifferenceInMinutes;
|
|
829
941
|
}
|
|
@@ -849,7 +961,9 @@ export async function saveDraft( req, res ) {
|
|
|
849
961
|
await createAuditLog( inputData );
|
|
850
962
|
await updateOneUserAudit( userQuery, userRecord );
|
|
851
963
|
await updateOneStoreAudit( storeQuery, storeRecord );
|
|
852
|
-
return res.sendSuccess( {
|
|
964
|
+
return res.sendSuccess( {
|
|
965
|
+
result: 'The file has been drafted successfully',
|
|
966
|
+
} );
|
|
853
967
|
} catch ( error ) {
|
|
854
968
|
const err = error.message || 'Internal Server Error';
|
|
855
969
|
logger.error( { error: error, message: req.body, function: 'saveDraft' } );
|
|
@@ -861,21 +975,24 @@ export async function getDraftedData( req, res ) {
|
|
|
861
975
|
try {
|
|
862
976
|
const inputData = req.query;
|
|
863
977
|
const userId = inputData.userId || req.user._id;
|
|
864
|
-
const query={
|
|
978
|
+
const query = {
|
|
865
979
|
fileDate: inputData.fileDate,
|
|
866
980
|
storeId: inputData.storeId,
|
|
867
981
|
userId: userId,
|
|
868
|
-
|
|
869
982
|
};
|
|
870
983
|
const result = await findOneAuditLog( query, {}, { createdAt: -1 }, 1 );
|
|
871
984
|
|
|
872
|
-
if ( result.length ==0 ) {
|
|
985
|
+
if ( result.length == 0 ) {
|
|
873
986
|
return res.sendError( 'No Data Found', 500 );
|
|
874
987
|
}
|
|
875
988
|
return res.sendSuccess( { result: result } );
|
|
876
989
|
} catch ( error ) {
|
|
877
990
|
const err = error.message || 'Internal Server Error';
|
|
878
|
-
logger.error( {
|
|
991
|
+
logger.error( {
|
|
992
|
+
error: error,
|
|
993
|
+
message: req.query,
|
|
994
|
+
function: 'getDraftedData',
|
|
995
|
+
} );
|
|
879
996
|
return res.sendError( err, 500 );
|
|
880
997
|
}
|
|
881
998
|
}
|
|
@@ -883,9 +1000,11 @@ export async function getDraftedData( req, res ) {
|
|
|
883
1000
|
export async function save( req, res ) {
|
|
884
1001
|
try {
|
|
885
1002
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
1003
|
+
const sqs = JSON.parse( process.env.SQS );
|
|
1004
|
+
|
|
886
1005
|
const inputData = req.body;
|
|
887
1006
|
const params = {
|
|
888
|
-
Key: `${inputData.storeId}/${inputData.fileDate}/${
|
|
1007
|
+
Key: `${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
889
1008
|
};
|
|
890
1009
|
|
|
891
1010
|
if ( inputData.auditType === 'ReAudit' ) {
|
|
@@ -893,10 +1012,17 @@ export async function save( req, res ) {
|
|
|
893
1012
|
} else {
|
|
894
1013
|
params.Bucket = bucket.masterJson;
|
|
895
1014
|
}
|
|
896
|
-
logger.info( { params: params } );
|
|
897
1015
|
const fileData = await getJsonFileData( params );
|
|
1016
|
+
|
|
1017
|
+
if ( fileData?.statusCode ) {
|
|
1018
|
+
logger.error( {
|
|
1019
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1020
|
+
type: 'UPLOAD_ERROR',
|
|
1021
|
+
} );
|
|
1022
|
+
return res.sendError( fileData, 500 );
|
|
1023
|
+
}
|
|
1024
|
+
|
|
898
1025
|
const masterJsonData = JSON.parse( fileData.toString( 'utf-8' ) );
|
|
899
|
-
logger.info( { masterJsonData: masterJsonData, length: masterJsonData.person_data.length } );
|
|
900
1026
|
|
|
901
1027
|
const [ G20000, B20000, E0 ] = await Promise.all( [
|
|
902
1028
|
splitG20000( masterJsonData.person_data ),
|
|
@@ -916,19 +1042,128 @@ export async function save( req, res ) {
|
|
|
916
1042
|
|
|
917
1043
|
const uploadDataParams = {
|
|
918
1044
|
Bucket: bucket.auditUploadBucket,
|
|
919
|
-
Key: `${inputData.storeId}/${inputData.fileDate}
|
|
1045
|
+
Key: `${inputData.storeId}/${inputData.fileDate}/`,
|
|
920
1046
|
ContentType: 'application/json',
|
|
921
|
-
|
|
1047
|
+
fileName: `${bucket.masterJsonFile}`,
|
|
1048
|
+
body: JSON.stringify( tempObject ),
|
|
922
1049
|
};
|
|
923
|
-
logger.info( { uploadDataParams: uploadDataParams } );
|
|
924
1050
|
const mappingUpload = await fileUpload( uploadDataParams );
|
|
925
|
-
|
|
926
|
-
|
|
1051
|
+
|
|
1052
|
+
if ( mappingUpload?.statusCode ) {
|
|
1053
|
+
logger.error( {
|
|
1054
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1055
|
+
type: 'UPLOAD_ERROR',
|
|
1056
|
+
} );
|
|
1057
|
+
return res.sendError( mappingUpload, 500 );
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
let getUserAuditData = await findOneUserAudit( {
|
|
1061
|
+
_id: new mongoose.Types.ObjectId( inputData.auditId ),
|
|
1062
|
+
} );
|
|
1063
|
+
const isoDate = getUserAuditData.startTime;
|
|
1064
|
+
const currentTime = dayjs();
|
|
1065
|
+
const isoDateTime = dayjs( isoDate );
|
|
1066
|
+
const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
|
|
1067
|
+
|
|
1068
|
+
await updateOneUserAudit(
|
|
1069
|
+
{ _id: new mongoose.Types.ObjectId( inputData.auditId ) },
|
|
1070
|
+
{
|
|
1071
|
+
auditStatus: 'completed',
|
|
1072
|
+
endTime: Date.now(),
|
|
1073
|
+
isDraft: false,
|
|
1074
|
+
afterCount: inputData.customerCount,
|
|
1075
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1076
|
+
},
|
|
1077
|
+
);
|
|
1078
|
+
|
|
1079
|
+
/** *
|
|
1080
|
+
*
|
|
1081
|
+
* logs need to be added
|
|
1082
|
+
*
|
|
1083
|
+
*
|
|
1084
|
+
*/
|
|
1085
|
+
|
|
1086
|
+
let storeConfig = await findOneStore(
|
|
1087
|
+
{
|
|
1088
|
+
storeId: getUserAuditData.storeId,
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
auditConfigs: 1,
|
|
1092
|
+
clientId: 1,
|
|
1093
|
+
},
|
|
1094
|
+
);
|
|
1095
|
+
let storeAuditData = await findOneStoreAudit( {
|
|
1096
|
+
storeId: inputData.storeId,
|
|
1097
|
+
fileDate: inputData.fileDate,
|
|
1098
|
+
} );
|
|
1099
|
+
|
|
1100
|
+
let clientData = await findClient( { clientId: storeConfig.clientId } );
|
|
1101
|
+
|
|
1102
|
+
if ( (
|
|
1103
|
+
( storeAuditData.beforeCount - inputData.customerCount ) /
|
|
1104
|
+
storeAuditData.beforeCount <
|
|
1105
|
+
storeConfig.auditConfigs.ratio
|
|
1106
|
+
) && inputData.auditType == 'Audit' ) {
|
|
1107
|
+
logger.info(
|
|
1108
|
+
`Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|
|
1109
|
+
'Reaudit',
|
|
1110
|
+
);
|
|
1111
|
+
|
|
1112
|
+
const sqsProduceQueue = {
|
|
1113
|
+
QueueUrl: `${sqs.url}${clientData[0].auditConfigs.queueName}`,
|
|
1114
|
+
MessageBody: JSON.stringify( {
|
|
1115
|
+
store_id: inputData.storeId,
|
|
1116
|
+
audit_type: 'ReAudit',
|
|
1117
|
+
curr_date: inputData.fileDate,
|
|
1118
|
+
total_count: inputData.customerCount,
|
|
1119
|
+
before_count: storeAuditData.beforeCount,
|
|
1120
|
+
} ),
|
|
1121
|
+
};
|
|
1122
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
1123
|
+
logger.info( { sqsQueue: sqsQueue } );
|
|
1124
|
+
|
|
1125
|
+
if ( sqsQueue.statusCode ) {
|
|
1126
|
+
logger.error( {
|
|
1127
|
+
error: `ERROR IN UPLOAD PATH: ${inputData.storeId}/${inputData.fileDate}/${bucket.masterJsonFile}`,
|
|
1128
|
+
type: 'UPLOAD_ERROR',
|
|
1129
|
+
} );
|
|
1130
|
+
return res.sendError( mappingUpload, 500 );
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
await updateOneStoreAudit( { storeId: inputData.storeId },
|
|
1134
|
+
{
|
|
1135
|
+
status: 'not_assign',
|
|
1136
|
+
afterCount: inputData.customerCount,
|
|
1137
|
+
auditType: 'ReAudit',
|
|
1138
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1139
|
+
} );
|
|
1140
|
+
} else {
|
|
1141
|
+
logger.info( 'Hit in Features', { data: ( _.omit( inputData, [ 'junk', 'employee', 'customer' ] ) ) } );
|
|
1142
|
+
await updateOneStoreAudit( { storeId: inputData.storeId },
|
|
1143
|
+
{
|
|
1144
|
+
status: 'completed',
|
|
1145
|
+
afterCount: inputData.customerCount,
|
|
1146
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1147
|
+
} );
|
|
1148
|
+
|
|
1149
|
+
const sqsProduceQueue = {
|
|
1150
|
+
QueueUrl: `${sqs.url}${sqs.feature}`,
|
|
1151
|
+
|
|
1152
|
+
MessageBody: JSON.stringify( {
|
|
1153
|
+
store_id: inputData.storeId,
|
|
1154
|
+
store_date: inputData.fileDate,
|
|
1155
|
+
bucket_name: `${bucket.auditUploadBucket}`,
|
|
1156
|
+
} ),
|
|
1157
|
+
};
|
|
1158
|
+
logger.info( { sqsProduceQueue: sqsProduceQueue } );
|
|
1159
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
1160
|
+
logger.info( { sqsQueue: sqsQueue } );
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
return res.sendSuccess( { result: 'Updated Successfully' } );
|
|
927
1164
|
} catch ( error ) {
|
|
928
|
-
const err= error.message || 'Internal Server Error';
|
|
1165
|
+
const err = error.message || 'Internal Server Error';
|
|
929
1166
|
logger.error( { error: error, message: req.body, function: 'save' } );
|
|
930
1167
|
return res.sendError( err );
|
|
931
1168
|
}
|
|
932
1169
|
}
|
|
933
|
-
|
|
934
|
-
|
|
@@ -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
|
};
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -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(),
|
|
@@ -63,7 +62,6 @@ export const saveSchema = joi.object(
|
|
|
63
62
|
employee: joi.array().required(),
|
|
64
63
|
customerCount: joi.number().required(),
|
|
65
64
|
customer: joi.array().required(),
|
|
66
|
-
queueName: joi.string().required(),
|
|
67
65
|
},
|
|
68
66
|
);
|
|
69
67
|
|
|
@@ -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;
|
|
@@ -11,3 +11,7 @@ export function createStoreAudit( record ) {
|
|
|
11
11
|
export function aggregateStoreAudit( query ) {
|
|
12
12
|
return storeAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
export function findOneStoreAudit( query, fields ) {
|
|
16
|
+
return storeAuditModel.findOne( query, fields );
|
|
17
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkFileExist, getQueueUrl, logger } from 'tango-app-api-middleware';
|
|
1
|
+
import { checkFileExist, chunkArray, getQueueUrl, logger } from 'tango-app-api-middleware';
|
|
2
2
|
import { findOneUserAudit } from '../service/userAudit.service.js';
|
|
3
3
|
|
|
4
4
|
export async function isExistsQueue( req, res, next ) {
|