tango-app-api-audit 1.0.6 → 1.0.8
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.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
"express": "^4.19.2",
|
|
20
20
|
"handlebars": "^4.7.8",
|
|
21
21
|
"joi-to-swagger": "^6.2.0",
|
|
22
|
+
"lodash": "^4.17.21",
|
|
22
23
|
"mongodb": "^6.7.0",
|
|
23
24
|
"nodemon": "^3.1.3",
|
|
24
25
|
"swagger-ui-express": "^5.0.1",
|
|
25
26
|
"tango-api-schema": "^2.0.117",
|
|
26
|
-
"tango-app-api-middleware": "^3.1.
|
|
27
|
+
"tango-app-api-middleware": "^3.1.23",
|
|
27
28
|
"winston": "^3.13.0",
|
|
28
29
|
"winston-daily-rotate-file": "^5.0.0"
|
|
29
30
|
},
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { chunkArray, getJsonFileData, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, listFileWithoutLimit, signedUrl } from 'tango-app-api-middleware';
|
|
1
|
+
import { chunkArray, download, getJsonFileData, getOpenSearchData, getUTC, insertOpenSearchData, listFileByPath, listFileWithoutLimit, signedUrl } from 'tango-app-api-middleware';
|
|
2
2
|
import { aggregateUserAudit, createUserAudit, findOneUserAudit, updateOneUserAudit } from '../service/userAudit.service.js';
|
|
3
3
|
import { aggregateAssignAudit, updateOneAssignAudit } from '../service/assignAudit.service.js';
|
|
4
4
|
import { findOneUser } from '../service/user.service.js';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import { aggregateClient } from '../service/client.service.js';
|
|
7
7
|
import { logger } from 'tango-app-api-middleware';
|
|
8
|
-
import { sqsReceive } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
9
|
-
import { createStoreAudit, updateOneStoreAudit } from '../service/storeAudit.service.js';
|
|
8
|
+
import { listQueue, sqsReceive } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
9
|
+
import { aggregateStoreAudit, createStoreAudit, updateOneStoreAudit } from '../service/storeAudit.service.js';
|
|
10
|
+
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
11
|
+
import _ from 'lodash';
|
|
10
12
|
|
|
11
13
|
export async function getAuditFile( req, res ) {
|
|
12
14
|
try {
|
|
@@ -248,8 +250,10 @@ export async function getAuditFile( req, res ) {
|
|
|
248
250
|
if ( inputData.nextId ) {
|
|
249
251
|
fetchData.ContinuationToken = decodeURIComponent( inputData.nextId );
|
|
250
252
|
}
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
+
const list = await listFileByPath( fetchData );
|
|
254
|
+
const folderPath = list.data;
|
|
255
|
+
const nextQuery = list.pageToken;
|
|
256
|
+
logger.info( { nextQuery: folderPath } );
|
|
253
257
|
if ( folderPath?.length > 0 ) {
|
|
254
258
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
255
259
|
const img = folderPath[i].Key.split( '/' );
|
|
@@ -446,17 +450,19 @@ export const mapFunction = async ( chunk, filter ) => {
|
|
|
446
450
|
return temp;
|
|
447
451
|
};
|
|
448
452
|
|
|
449
|
-
export async function
|
|
453
|
+
export async function workSpace( req, res ) {
|
|
450
454
|
try {
|
|
451
455
|
const inputData = req.query;
|
|
452
|
-
const
|
|
456
|
+
const limit = inputData.limit || 10;
|
|
457
|
+
const offset =inputData.offset? ( inputData.offset - 1 ) * inputData.limit : 0;
|
|
458
|
+
const dateRange = await getUTC( new Date(), new Date() );
|
|
453
459
|
|
|
454
460
|
const temp = [];
|
|
455
461
|
const clientQuery = [
|
|
456
462
|
{
|
|
457
463
|
$match: {
|
|
458
464
|
$and: [
|
|
459
|
-
{
|
|
465
|
+
{ status: { $in: [ 'active', 'hold' ] } },
|
|
460
466
|
{ 'auditConfigs.audit': { $eq: true } },
|
|
461
467
|
],
|
|
462
468
|
},
|
|
@@ -480,16 +486,16 @@ export async function getQueueDetailList( req, res ) {
|
|
|
480
486
|
} );
|
|
481
487
|
}
|
|
482
488
|
const count = await aggregateClient( clientQuery );
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
489
|
+
logger.info( { count: count } );
|
|
490
|
+
if ( count?.length == 0 ) {
|
|
491
|
+
return res.sendError( 'No Data Found', 204 );
|
|
486
492
|
}
|
|
487
493
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
return res.sendError( 'No Data Found', 204 );
|
|
494
|
+
if ( inputData.limit && !inputData.isExport ) {
|
|
495
|
+
clientQuery.push( { $skip: offset }, { $limit: limit } );
|
|
491
496
|
}
|
|
492
497
|
|
|
498
|
+
const clientDetails = await aggregateClient( clientQuery );
|
|
493
499
|
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
494
500
|
const query = [
|
|
495
501
|
{
|
|
@@ -517,7 +523,7 @@ export async function getQueueDetailList( req, res ) {
|
|
|
517
523
|
},
|
|
518
524
|
];
|
|
519
525
|
|
|
520
|
-
const fileDate = dayjs(
|
|
526
|
+
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
521
527
|
|
|
522
528
|
const completedFiles = [
|
|
523
529
|
{
|
|
@@ -532,7 +538,7 @@ export async function getQueueDetailList( req, res ) {
|
|
|
532
538
|
$project: {
|
|
533
539
|
clientId: 1,
|
|
534
540
|
completed: {
|
|
535
|
-
$cond: [ { $eq: [ '$
|
|
541
|
+
$cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ],
|
|
536
542
|
},
|
|
537
543
|
},
|
|
538
544
|
},
|
|
@@ -558,8 +564,8 @@ export async function getQueueDetailList( req, res ) {
|
|
|
558
564
|
$match: {
|
|
559
565
|
$and: [
|
|
560
566
|
{ clientId: { $in: clientList } },
|
|
561
|
-
{ createdAt: { $gte:
|
|
562
|
-
{ createdAt: { $lte:
|
|
567
|
+
{ createdAt: { $gte: dateRange.start } },
|
|
568
|
+
{ createdAt: { $lte: dateRange.end } },
|
|
563
569
|
],
|
|
564
570
|
},
|
|
565
571
|
},
|
|
@@ -567,7 +573,7 @@ export async function getQueueDetailList( req, res ) {
|
|
|
567
573
|
$project: {
|
|
568
574
|
clientId: 1,
|
|
569
575
|
pending: {
|
|
570
|
-
$cond: [ { $or: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted' ] ] }
|
|
576
|
+
$cond: [ { $or: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted' ] ] } ] }, 1, 0 ],
|
|
571
577
|
},
|
|
572
578
|
},
|
|
573
579
|
},
|
|
@@ -597,8 +603,8 @@ export async function getQueueDetailList( req, res ) {
|
|
|
597
603
|
$and: [
|
|
598
604
|
{ clientId: { $in: clientList } },
|
|
599
605
|
{ userId: { $eq: inputData.userId } },
|
|
600
|
-
{ createdAt: { $gte:
|
|
601
|
-
{ createdAt: { $lte:
|
|
606
|
+
{ createdAt: { $gte: dateRange.start } },
|
|
607
|
+
{ createdAt: { $lte: dateRange.end } },
|
|
602
608
|
],
|
|
603
609
|
},
|
|
604
610
|
},
|
|
@@ -684,14 +690,14 @@ export async function getQueueDetailList( req, res ) {
|
|
|
684
690
|
},
|
|
685
691
|
];
|
|
686
692
|
|
|
687
|
-
const auditDetails = await
|
|
688
|
-
const auditCount = await
|
|
689
|
-
const draftedCount = await
|
|
690
|
-
const CompletedCount = await
|
|
693
|
+
const auditDetails = await aggregateAuditClientData( query );
|
|
694
|
+
const auditCount = await aggregateUserAudit( auditFiles );
|
|
695
|
+
const draftedCount = await aggregateUserAudit( draftedFiles );
|
|
696
|
+
const CompletedCount = await aggregateStoreAudit( completedFiles );
|
|
691
697
|
|
|
692
|
-
const clientAssignresult = await
|
|
698
|
+
const clientAssignresult = await aggregateAssignAudit( clientAssign );
|
|
693
699
|
|
|
694
|
-
const userAsignCount = await
|
|
700
|
+
const userAsignCount = await aggregateAssignAudit( userAsign );
|
|
695
701
|
const mergeAll = _.merge( _.keyBy( clientDetails, 'clientId' ), _.keyBy( auditCount, 'clientId' ), _.keyBy( draftedCount, 'clientId' ), _.keyBy( clientAssignresult, 'clientId' ) );
|
|
696
702
|
const finalResult = _.values( mergeAll );
|
|
697
703
|
const merge = _.values( _.merge( _.keyBy( finalResult, 'clientId' ), _.keyBy( auditDetails, 'clientId' ), _.keyBy( userAsignCount, 'clientId' ), _.keyBy( CompletedCount, 'clientId' ) ) );
|
|
@@ -703,13 +709,13 @@ export async function getQueueDetailList( req, res ) {
|
|
|
703
709
|
const pending = await listQueue( merge[i].queueName );
|
|
704
710
|
if ( !pending.statusCode ) {
|
|
705
711
|
temp.push( {
|
|
706
|
-
|
|
707
|
-
|
|
712
|
+
clientId: merge[i].clientId,
|
|
713
|
+
clientName: merge[i].clientName,
|
|
708
714
|
completedCount: merge[i].completedCount ? Number( merge[i].completedCount ) : 0,
|
|
709
715
|
pendingByQueue: Number( pending ),
|
|
710
716
|
pendingByUser: ( merge[i].pendingCount >= 0 ) ? Number( merge[i].pendingCount )+( merge[i].ClientAsignedCount ? Number( merge[i].ClientAsignedCount ) : 0 ) : 0,
|
|
711
717
|
totalCount: merge[i].totalFilesCount,
|
|
712
|
-
|
|
718
|
+
queueName: merge[i].queueName,
|
|
713
719
|
isDraft: merge[i].isDrafted ? merge[i].isDrafted : false,
|
|
714
720
|
isEnable: Number( pending ) > 0 || merge[i].isDrafted || ( merge[i].asignedCount && merge[i].asignedCount > 0 ) || ( merge[i].inprogressCount && merge[i].inprogressCount > 0 ) ? true : false,
|
|
715
721
|
completedRatio: merge[i].totalFilesCount ? merge[i].completedCount ? Math.round( ( Number( merge[i].completedCount ) / Number( merge[i].totalFilesCount ) ) * 100 ) : 0 : 0,
|
|
@@ -719,7 +725,7 @@ export async function getQueueDetailList( req, res ) {
|
|
|
719
725
|
}
|
|
720
726
|
}
|
|
721
727
|
|
|
722
|
-
if ( inputData.
|
|
728
|
+
if ( inputData.isExport ) {
|
|
723
729
|
const exportdata = [];
|
|
724
730
|
temp.forEach( ( element ) => {
|
|
725
731
|
exportdata.push( {
|
|
@@ -739,7 +745,9 @@ export async function getQueueDetailList( req, res ) {
|
|
|
739
745
|
return res.sendSuccess( { result: temp, count: count.length, totalStores: totalStores } );
|
|
740
746
|
}
|
|
741
747
|
} catch ( error ) {
|
|
742
|
-
|
|
748
|
+
const err = error.message || 'Internal Server Error';
|
|
749
|
+
logger.info( { error: error, message: req.query, function: 'workSpace' } );
|
|
750
|
+
return res.sendError( err, 500 );
|
|
743
751
|
}
|
|
744
752
|
}
|
|
745
753
|
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getDraftedDataSchema, getFileSchema, saveDraftSchema, saveSchema } from '../dtos/audit.dtos.js';
|
|
1
|
+
import { getDraftedDataSchema, getFileSchema, saveDraftSchema, saveSchema, workSpaceSchema } from '../dtos/audit.dtos.js';
|
|
2
2
|
import j2s from 'joi-to-swagger';
|
|
3
3
|
|
|
4
4
|
export const auditDocs = {
|
|
@@ -108,4 +108,45 @@ export const auditDocs = {
|
|
|
108
108
|
},
|
|
109
109
|
},
|
|
110
110
|
},
|
|
111
|
+
'/v3/audit/work-space': {
|
|
112
|
+
get: {
|
|
113
|
+
tags: [ 'Audit' ],
|
|
114
|
+
description: 'queue wise info of audit files ',
|
|
115
|
+
operationId: 'work-space',
|
|
116
|
+
parameters: [
|
|
117
|
+
{
|
|
118
|
+
in: 'query',
|
|
119
|
+
name: 'searchValue',
|
|
120
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
121
|
+
require: false,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
in: 'query',
|
|
125
|
+
name: 'offset',
|
|
126
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
127
|
+
require: false,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
in: 'query',
|
|
131
|
+
name: 'limit',
|
|
132
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
133
|
+
require: false,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
in: 'query',
|
|
137
|
+
name: 'isExport',
|
|
138
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
139
|
+
require: false,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
responses: {
|
|
143
|
+
200: { description: 'Successful' },
|
|
144
|
+
401: { description: 'Unauthorized User' },
|
|
145
|
+
422: { description: 'Field Error' },
|
|
146
|
+
500: { description: 'Server Error' },
|
|
147
|
+
204: { description: 'Not Found' },
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
|
|
111
152
|
};
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -4,7 +4,7 @@ import joi from 'joi';
|
|
|
4
4
|
export const getFileSchema = joi.object(
|
|
5
5
|
{
|
|
6
6
|
queueName: joi.string().required(),
|
|
7
|
-
nextId: joi.string().optional(),
|
|
7
|
+
nextId: joi.string().optional().allow( '' ),
|
|
8
8
|
limit: joi.number().optional(),
|
|
9
9
|
},
|
|
10
10
|
);
|
|
@@ -15,7 +15,7 @@ export const getFileValid = {
|
|
|
15
15
|
|
|
16
16
|
export const saveDraftSchema = joi.object(
|
|
17
17
|
{
|
|
18
|
-
userCommands: joi.string().optional(),
|
|
18
|
+
userCommands: joi.string().optional().allow( '' ),
|
|
19
19
|
storeId: joi.string().required(),
|
|
20
20
|
auditId: joi.string().required(),
|
|
21
21
|
auditType: joi.string().required(),
|
|
@@ -60,15 +60,15 @@ export const saveValid = {
|
|
|
60
60
|
body: saveSchema,
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
-
export const
|
|
63
|
+
export const workSpaceSchema = joi.object(
|
|
64
64
|
{
|
|
65
65
|
searchValue: joi.string().optional(),
|
|
66
66
|
offset: joi.string().optional(),
|
|
67
67
|
limit: joi.number().optional(),
|
|
68
|
-
|
|
68
|
+
isExport: joi.boolean().optional(),
|
|
69
69
|
},
|
|
70
70
|
);
|
|
71
71
|
|
|
72
|
-
export const
|
|
73
|
-
query:
|
|
72
|
+
export const workSpaceValid = {
|
|
73
|
+
query: workSpaceSchema,
|
|
74
74
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { isExistsQueue, validateUserAudit } from '../validation/audit.validation.js';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { getAuditFile, getDraftedData,
|
|
5
|
-
import { getDraftedDataValid, getFileValid,
|
|
4
|
+
import { getAuditFile, getDraftedData, save, saveDraft, workSpace } from '../controllers/audit.controllers.js';
|
|
5
|
+
import { getDraftedDataValid, getFileValid, saveDraftValid, saveValid, workSpaceValid } from '../dtos/audit.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditRouter = express.Router();
|
|
8
8
|
|
|
@@ -10,6 +10,6 @@ auditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ),
|
|
|
10
10
|
auditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
|
|
11
11
|
auditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
|
|
12
12
|
auditRouter.post( '/save', isAllowedSessionHandler, validate( saveValid ), validateUserAudit, save );
|
|
13
|
-
auditRouter.get( '/
|
|
13
|
+
auditRouter.get( '/work-space', isAllowedSessionHandler, validate( workSpaceValid ), workSpace );
|
|
14
14
|
|
|
15
15
|
export default auditRouter;
|
|
@@ -7,3 +7,7 @@ export function updateOneStoreAudit( query, record ) {
|
|
|
7
7
|
export function createStoreAudit( record ) {
|
|
8
8
|
return storeAuditModel.create( record );
|
|
9
9
|
}
|
|
10
|
+
|
|
11
|
+
export function aggregateStoreAudit( query ) {
|
|
12
|
+
return storeAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
13
|
+
}
|