tango-app-api-audit 1.0.48 → 1.0.49
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/index.js +1 -7
- package/package.json +2 -2
- package/src/controllers/audit.controllers.js +283 -111
- package/src/docs/audit.docs.js +101 -6
- package/src/dtos/audit.dtos.js +44 -0
- package/src/routes/audit.routes.js +9 -2
- package/src/service/auditStoreData.service.js +10 -0
- package/src/controllers/client.controllers.js +0 -42
- package/src/controllers/store.controllers.js +0 -42
- package/src/controllers/user.controllers.js +0 -41
- package/src/docs/client.docs.js +0 -33
- package/src/docs/store.docs.js +0 -27
- package/src/docs/user.docs.js +0 -33
- package/src/dtos/client.dtos.js +0 -13
- package/src/dtos/store.dtos.js +0 -14
- package/src/dtos/user.dtos.js +0 -14
- package/src/routes/client.routes.js +0 -10
- package/src/routes/store.routes.js +0 -10
- package/src/routes/user.routes.js +0 -9
package/index.js
CHANGED
|
@@ -4,15 +4,9 @@ import { auditRouter } from './src/routes/audit.routes.js';
|
|
|
4
4
|
import { auditMetricsRouter } from './src/routes/auditMetrics.routes.js';
|
|
5
5
|
import { auditMetricsDocs } from './src/docs/auditMetrics.docs.js';
|
|
6
6
|
import { auditDocs } from './src/docs/audit.docs.js';
|
|
7
|
-
import clientRouter from './src/routes/client.routes.js';
|
|
8
|
-
import { clientDocs } from './src/docs/client.docs.js';
|
|
9
|
-
import { storeRouter } from './src/routes/store.routes.js';
|
|
10
|
-
import { storeDocs } from './src/docs/store.docs.js';
|
|
11
|
-
import { userDocs } from './src/docs/user.docs.js';
|
|
12
|
-
import { userRouter } from './src/routes/user.routes.js';
|
|
13
7
|
import { zoneAuditRouter } from './src/routes/zone.routes.js';
|
|
14
8
|
import { zoneAuditDocs } from './src/docs/zoneAudit.docs.js';
|
|
15
9
|
|
|
16
|
-
export { auditRouter, auditMetricsRouter, auditMetricsDocs, auditDocs,
|
|
10
|
+
export { auditRouter, auditMetricsRouter, auditMetricsDocs, auditDocs, zoneAuditRouter, zoneAuditDocs };
|
|
17
11
|
|
|
18
12
|
|
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.49",
|
|
4
4
|
"description": "audit & audit metrics apis",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"mongodb": "^6.7.0",
|
|
25
25
|
"nodemon": "^3.1.3",
|
|
26
26
|
"swagger-ui-express": "^5.0.1",
|
|
27
|
-
"tango-api-schema": "^2.0.
|
|
27
|
+
"tango-api-schema": "^2.0.152",
|
|
28
28
|
"tango-app-api-middleware": "^3.1.28",
|
|
29
29
|
"winston": "^3.13.0",
|
|
30
30
|
"winston-daily-rotate-file": "^5.0.0"
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
aggregateAssignAudit,
|
|
20
20
|
updateOneAssignAudit,
|
|
21
21
|
} from '../service/assignAudit.service.js';
|
|
22
|
-
import { findOneUser } from '../service/user.service.js';
|
|
22
|
+
import { aggregateUser, findOneUser } from '../service/user.service.js';
|
|
23
23
|
import dayjs from 'dayjs';
|
|
24
24
|
import { aggregateClient, findClient } from '../service/client.service.js';
|
|
25
25
|
import { logger } from 'tango-app-api-middleware';
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
createAuditLog,
|
|
40
40
|
findOneAuditLog,
|
|
41
41
|
} from '../service/auditLog.service.js';
|
|
42
|
-
import { findOneStore } from '../service/store.service.js';
|
|
42
|
+
import { aggregateStore, findOneStore } from '../service/store.service.js';
|
|
43
43
|
import {
|
|
44
44
|
mapCustomer,
|
|
45
45
|
mapEmployee,
|
|
@@ -49,6 +49,140 @@ import {
|
|
|
49
49
|
splitG20000,
|
|
50
50
|
} from '../validation/audit.validation.js';
|
|
51
51
|
import mongoose from 'mongoose';
|
|
52
|
+
import {
|
|
53
|
+
aggregateAuditStoreDataSchema,
|
|
54
|
+
findOneStoreData,
|
|
55
|
+
} from '../service/auditStoreData.service.js';
|
|
56
|
+
|
|
57
|
+
/* < -- *** Configuration *** --> */
|
|
58
|
+
|
|
59
|
+
// client
|
|
60
|
+
export async function clients( req, res ) {
|
|
61
|
+
try {
|
|
62
|
+
const inputData = req.query;
|
|
63
|
+
const query = [
|
|
64
|
+
{
|
|
65
|
+
$match: {
|
|
66
|
+
'status': { $in: [ 'active', 'hold' ] },
|
|
67
|
+
'auditConfigs.audit': true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
$project: {
|
|
72
|
+
_id: 0,
|
|
73
|
+
clientName: 1,
|
|
74
|
+
clientId: 1,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
const count = await aggregateClient( query );
|
|
80
|
+
if ( count.length == 0 ) {
|
|
81
|
+
return res.sendSuccess( { result: [], count: 0 } );
|
|
82
|
+
}
|
|
83
|
+
if ( inputData.limit ) {
|
|
84
|
+
const offset = inputData.offset ?
|
|
85
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
86
|
+
0;
|
|
87
|
+
query.push( { $skip: offset }, { $limit: limit } );
|
|
88
|
+
}
|
|
89
|
+
const getAuditClients = await aggregateClient( query );
|
|
90
|
+
|
|
91
|
+
return res.sendSuccess( { result: getAuditClients, count: count.length } );
|
|
92
|
+
} catch ( error ) {
|
|
93
|
+
const err = error.message || 'Internal Server Error';
|
|
94
|
+
logger.info( { error: error, messgae: req.query, function: 'clients' } );
|
|
95
|
+
return res.sendError( err, 500 );
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function auditStoreList( req, res ) {
|
|
100
|
+
try {
|
|
101
|
+
const inputData = req.body;
|
|
102
|
+
const query = [
|
|
103
|
+
{
|
|
104
|
+
$match: {
|
|
105
|
+
clientId: { $in: inputData.clientId },
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
$project: {
|
|
110
|
+
_id: 0,
|
|
111
|
+
clientId: 1,
|
|
112
|
+
storeId: 1,
|
|
113
|
+
storeName: 1,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const count = await aggregateStore( query );
|
|
119
|
+
if ( count.length == 0 ) {
|
|
120
|
+
return res.sendSuccess( { result: [], count: 0 } );
|
|
121
|
+
}
|
|
122
|
+
if ( inputData.limit ) {
|
|
123
|
+
const offset = inputData.offset ?
|
|
124
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
125
|
+
0;
|
|
126
|
+
query.push( { $skip: offset }, { $limit: limit } );
|
|
127
|
+
}
|
|
128
|
+
const result = await aggregateStore( query );
|
|
129
|
+
|
|
130
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
131
|
+
} catch ( error ) {
|
|
132
|
+
const err = error.message || 'Internal Server Error';
|
|
133
|
+
logger.info( {
|
|
134
|
+
error: error,
|
|
135
|
+
messgae: req.body,
|
|
136
|
+
function: 'auditStoreList',
|
|
137
|
+
} );
|
|
138
|
+
return res.sendError( err, 500 );
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function auditUserList( req, res ) {
|
|
143
|
+
try {
|
|
144
|
+
const inputData = req.query;
|
|
145
|
+
const query = [
|
|
146
|
+
{
|
|
147
|
+
$match: {
|
|
148
|
+
userType: { $eq: 'tango' },
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
$project: {
|
|
153
|
+
userName: 1,
|
|
154
|
+
userId: '$_id',
|
|
155
|
+
_id: 0,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
const count = await aggregateUser( query );
|
|
161
|
+
if ( count.length == 0 ) {
|
|
162
|
+
return res.sendSuccess( { result: [], count: 0 } );
|
|
163
|
+
}
|
|
164
|
+
if ( inputData.limit ) {
|
|
165
|
+
const offset = inputData.offset ?
|
|
166
|
+
( inputData.offset - 1 ) * inputData.limit :
|
|
167
|
+
0;
|
|
168
|
+
query.push( { $skip: offset }, { $limit: limit } );
|
|
169
|
+
}
|
|
170
|
+
const result = await aggregateUser( query );
|
|
171
|
+
|
|
172
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
173
|
+
} catch ( error ) {
|
|
174
|
+
const err = error.message || 'Internal Server Error';
|
|
175
|
+
logger.info( {
|
|
176
|
+
error: error,
|
|
177
|
+
messgae: req.query,
|
|
178
|
+
function: 'auditUserList',
|
|
179
|
+
} );
|
|
180
|
+
return res.sendError( err, 500 );
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* < -- *** Audit Mapping *** --> */
|
|
185
|
+
|
|
52
186
|
export async function getAuditFile( req, res ) {
|
|
53
187
|
try {
|
|
54
188
|
const bucket = JSON.parse( process.env.BUCKET );
|
|
@@ -627,50 +761,59 @@ export async function workSpace( req, res ) {
|
|
|
627
761
|
} );
|
|
628
762
|
}
|
|
629
763
|
const count = await aggregateClient( clientQuery );
|
|
630
|
-
logger.info( { count: count } );
|
|
631
764
|
if ( count?.length == 0 ) {
|
|
632
765
|
return res.sendError( 'No Data Found', 204 );
|
|
633
766
|
}
|
|
634
767
|
|
|
635
|
-
if (
|
|
768
|
+
if ( !inputData.isExport ) {
|
|
636
769
|
clientQuery.push( { $skip: offset }, { $limit: limit } );
|
|
637
770
|
}
|
|
638
771
|
|
|
639
772
|
const clientDetails = await aggregateClient( clientQuery );
|
|
640
773
|
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
641
|
-
// const query = [
|
|
642
|
-
// {
|
|
643
|
-
// $match: {
|
|
644
|
-
// clientId: { $in: clientList },
|
|
645
|
-
// },
|
|
646
|
-
// },
|
|
647
|
-
// {
|
|
648
|
-
// $group: {
|
|
649
|
-
// _id: '$clientId',
|
|
650
|
-
// clientId: { $last: '$clientId' },
|
|
651
|
-
// totalFilesCount: { $last: '$totalFilesCount' },
|
|
652
|
-
// clientName: { $last: '$clientName' },
|
|
653
|
-
// queueName: { $last: '$queueName' },
|
|
654
|
-
// },
|
|
655
|
-
// },
|
|
656
|
-
// {
|
|
657
|
-
// $project: {
|
|
658
|
-
// clientId: 1,
|
|
659
|
-
// totalFilesCount: 1,
|
|
660
|
-
// clientName: 1,
|
|
661
|
-
// queueName: 1,
|
|
662
|
-
// },
|
|
663
|
-
// },
|
|
664
|
-
// ];
|
|
665
|
-
|
|
666
774
|
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
775
|
+
const getStoreData = await findOneStoreData(
|
|
776
|
+
{},
|
|
777
|
+
{ fileDate: 1 },
|
|
778
|
+
{ createdAt: -1 },
|
|
779
|
+
);
|
|
780
|
+
const latestDate = getStoreData?.fileDate || dayjs( fileDate ).format( 'DD-MM-YYYY' );
|
|
781
|
+
const auditStoreDataQuery = [
|
|
782
|
+
{
|
|
783
|
+
$match: {
|
|
784
|
+
clientId: { $in: clientList },
|
|
785
|
+
moduleType: { $eq: inputData.moduleType },
|
|
786
|
+
fileDate: { $eq: latestDate },
|
|
787
|
+
},
|
|
788
|
+
},
|
|
789
|
+
{
|
|
790
|
+
$group: {
|
|
791
|
+
_id: '$clientId',
|
|
792
|
+
clientId: { $last: '$clientId' },
|
|
793
|
+
clientName: { $last: '$clientName' },
|
|
794
|
+
installedStore: { $last: '$installedStore' },
|
|
795
|
+
queueName: { $last: '$queueName' },
|
|
796
|
+
totalCount: { $sum: 1 },
|
|
797
|
+
},
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
$project: {
|
|
801
|
+
_id: 0,
|
|
802
|
+
clientId: 1,
|
|
803
|
+
clientName: 1,
|
|
804
|
+
installedStore: 1,
|
|
805
|
+
queueName: 1,
|
|
806
|
+
totalCount: 1,
|
|
807
|
+
},
|
|
808
|
+
},
|
|
809
|
+
];
|
|
667
810
|
|
|
668
|
-
const
|
|
811
|
+
const completedStores = [
|
|
669
812
|
{
|
|
670
813
|
$match: {
|
|
671
814
|
$and: [
|
|
672
815
|
{ clientId: { $in: clientList } },
|
|
673
|
-
{
|
|
816
|
+
{ fileDate: { $eq: latestDate } },
|
|
674
817
|
],
|
|
675
818
|
},
|
|
676
819
|
},
|
|
@@ -682,18 +825,26 @@ export async function workSpace( req, res ) {
|
|
|
682
825
|
},
|
|
683
826
|
},
|
|
684
827
|
},
|
|
828
|
+
// {
|
|
829
|
+
// $group: {
|
|
830
|
+
// _id: { clientId: '$clientId', storeId: '$storeId' },
|
|
831
|
+
// clientId: { $first: '$clientId' },
|
|
832
|
+
// completedStoresCount: { $sum: '$completed' },
|
|
833
|
+
// },
|
|
834
|
+
// },
|
|
685
835
|
{
|
|
686
836
|
$group: {
|
|
687
|
-
_id:
|
|
837
|
+
_id: '$clientId',
|
|
688
838
|
clientId: { $first: '$clientId' },
|
|
689
|
-
|
|
839
|
+
// completedStoresCount: { $first: '$completedStoresCount' },
|
|
840
|
+
completedStoresCount: { $sum: '$completed' },
|
|
690
841
|
},
|
|
691
842
|
},
|
|
692
843
|
{
|
|
693
|
-
$
|
|
694
|
-
_id:
|
|
695
|
-
clientId:
|
|
696
|
-
|
|
844
|
+
$project: {
|
|
845
|
+
_id: 0,
|
|
846
|
+
clientId: 1,
|
|
847
|
+
completedStoresCount: 1,
|
|
697
848
|
},
|
|
698
849
|
},
|
|
699
850
|
];
|
|
@@ -725,7 +876,7 @@ export async function workSpace( req, res ) {
|
|
|
725
876
|
_id: { clientId: '$clientId', storeId: '$storeId' },
|
|
726
877
|
clientId: { $first: '$clientId' },
|
|
727
878
|
pendingCount: { $sum: '$pending' },
|
|
728
|
-
|
|
879
|
+
totalFilesCount: { $sum: 1 },
|
|
729
880
|
},
|
|
730
881
|
},
|
|
731
882
|
{
|
|
@@ -733,17 +884,16 @@ export async function workSpace( req, res ) {
|
|
|
733
884
|
_id: '$clientId',
|
|
734
885
|
clientId: { $first: '$clientId' },
|
|
735
886
|
pendingCount: { $first: { $ifNull: [ '$pendingCount', 0 ] } },
|
|
736
|
-
|
|
887
|
+
totalFilesCount: { $first: '$totalFilesCount' },
|
|
737
888
|
},
|
|
738
889
|
},
|
|
739
890
|
];
|
|
740
|
-
|
|
741
|
-
const draftedFiles = [
|
|
891
|
+
const userIncompleteFiles = [
|
|
742
892
|
{
|
|
743
893
|
$match: {
|
|
744
894
|
$and: [
|
|
745
895
|
{ clientId: { $in: clientList } },
|
|
746
|
-
{ userId: { $eq:
|
|
896
|
+
{ userId: { $eq: req.user._id } },
|
|
747
897
|
{ createdAt: { $gte: dateRange.start } },
|
|
748
898
|
{ createdAt: { $lte: dateRange.end } },
|
|
749
899
|
],
|
|
@@ -771,13 +921,13 @@ export async function workSpace( req, res ) {
|
|
|
771
921
|
_id: '$clientId',
|
|
772
922
|
clientId: { $first: '$clientId' },
|
|
773
923
|
isDrafted: { $first: '$isDraft' },
|
|
774
|
-
|
|
775
|
-
|
|
924
|
+
userDraftCount: { $sum: '$draft' },
|
|
925
|
+
userInprogressCount: { $sum: '$inprogress' },
|
|
776
926
|
},
|
|
777
927
|
},
|
|
778
928
|
];
|
|
779
929
|
|
|
780
|
-
const
|
|
930
|
+
const userAsignAudit = [
|
|
781
931
|
{
|
|
782
932
|
$match: {
|
|
783
933
|
$and: [
|
|
@@ -791,14 +941,14 @@ export async function workSpace( req, res ) {
|
|
|
791
941
|
$group: {
|
|
792
942
|
_id: '$clientId',
|
|
793
943
|
clientId: { $first: '$clientId' },
|
|
794
|
-
|
|
944
|
+
userAsignedCount: { $sum: 1 },
|
|
795
945
|
},
|
|
796
946
|
},
|
|
797
947
|
{
|
|
798
948
|
$project: {
|
|
799
949
|
_id: 0,
|
|
800
950
|
clientId: 1,
|
|
801
|
-
|
|
951
|
+
userAsignedCount: 1,
|
|
802
952
|
},
|
|
803
953
|
},
|
|
804
954
|
];
|
|
@@ -813,44 +963,47 @@ export async function workSpace( req, res ) {
|
|
|
813
963
|
$group: {
|
|
814
964
|
_id: '$clientId',
|
|
815
965
|
clientId: { $first: '$clientId' },
|
|
816
|
-
|
|
966
|
+
clientAsignedCount: { $sum: 1 },
|
|
817
967
|
},
|
|
818
968
|
},
|
|
819
969
|
{
|
|
820
970
|
$project: {
|
|
821
971
|
_id: 0,
|
|
822
972
|
clientId: 1,
|
|
823
|
-
|
|
973
|
+
clientAsignedCount: { $ifNull: [ '$clientAsignedCount', 0 ] },
|
|
824
974
|
},
|
|
825
975
|
},
|
|
826
976
|
];
|
|
827
977
|
|
|
828
|
-
const
|
|
829
|
-
const
|
|
830
|
-
|
|
831
|
-
|
|
978
|
+
const auditUserCount = await aggregateUserAudit( auditFiles );
|
|
979
|
+
const userIncompleteFilesCount = await aggregateUserAudit(
|
|
980
|
+
userIncompleteFiles,
|
|
981
|
+
);
|
|
982
|
+
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
983
|
+
const completedStoresCount = await aggregateStoreAudit( completedStores );
|
|
984
|
+
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
985
|
+
const auditStoreData = await aggregateAuditStoreDataSchema(
|
|
986
|
+
auditStoreDataQuery,
|
|
987
|
+
);
|
|
832
988
|
|
|
833
|
-
const clientAssignresult = await aggregateAssignAudit( clientAssign );
|
|
834
|
-
const userAsignCount = await aggregateAssignAudit( userAsign );
|
|
835
989
|
const mergeAll = _.merge(
|
|
836
990
|
_.keyBy( clientDetails, 'clientId' ),
|
|
837
|
-
_.keyBy(
|
|
838
|
-
_.keyBy(
|
|
839
|
-
_.keyBy(
|
|
991
|
+
_.keyBy( auditUserCount, 'clientId' ),
|
|
992
|
+
_.keyBy( userIncompleteFilesCount, 'clientId' ),
|
|
993
|
+
_.keyBy( clientAssignedCount, 'clientId' ),
|
|
840
994
|
);
|
|
841
995
|
const finalResult = _.values( mergeAll );
|
|
842
996
|
const merge = _.values(
|
|
843
997
|
_.merge(
|
|
844
998
|
_.keyBy( finalResult, 'clientId' ),
|
|
845
|
-
_.keyBy(
|
|
846
|
-
_.keyBy(
|
|
847
|
-
_.keyBy(
|
|
999
|
+
_.keyBy( auditStoreData, 'clientId' ),
|
|
1000
|
+
_.keyBy( userAsignAuditCount, 'clientId' ),
|
|
1001
|
+
_.keyBy( completedStoresCount, 'clientId' ),
|
|
848
1002
|
),
|
|
849
1003
|
);
|
|
850
|
-
logger.info( { merge: merge } );
|
|
851
1004
|
let totalStores = 0;
|
|
852
1005
|
for ( let i = 0; i < merge.length; i++ ) {
|
|
853
|
-
totalStores =
|
|
1006
|
+
totalStores = merge[i]?.totalFilesCount || 0;
|
|
854
1007
|
|
|
855
1008
|
const pending = await listQueue( merge[i].queueName );
|
|
856
1009
|
|
|
@@ -858,41 +1011,43 @@ export async function workSpace( req, res ) {
|
|
|
858
1011
|
temp.push( {
|
|
859
1012
|
clientId: merge[i].clientId,
|
|
860
1013
|
clientName: merge[i].clientName,
|
|
861
|
-
|
|
862
|
-
Number( merge[i].
|
|
1014
|
+
completedStoresCount: merge[i].completedStoresCount ?
|
|
1015
|
+
Number( merge[i].completedStoresCount ) :
|
|
863
1016
|
0,
|
|
864
1017
|
pendingByQueue: Number( pending ),
|
|
865
1018
|
pendingByUser:
|
|
866
1019
|
merge[i].pendingCount >= 0 ?
|
|
867
1020
|
Number( merge[i].pendingCount ) +
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
1021
|
+
( merge[i].clientAsignedCount ?
|
|
1022
|
+
Number( merge[i].clientAsignedCount ) :
|
|
1023
|
+
0 ) :
|
|
871
1024
|
0,
|
|
872
1025
|
totalCount: merge[i].totalFilesCount,
|
|
873
1026
|
queueName: merge[i].queueName,
|
|
874
|
-
isDraft: merge[i]
|
|
1027
|
+
isDraft: merge[i]?.isDrafted || false,
|
|
875
1028
|
isEnable:
|
|
876
1029
|
Number( pending ) > 0 ||
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
1030
|
+
merge[i].isDrafted ||
|
|
1031
|
+
( merge[i].userAsignedCount && merge[i].userAsignedCount > 0 ) ||
|
|
1032
|
+
( merge[i].userInprogressCount && merge[i].userInprogressCount > 0 ) ?
|
|
1033
|
+
1 :
|
|
1034
|
+
0,
|
|
882
1035
|
completedRatio: merge[i].totalFilesCount ?
|
|
883
|
-
merge[i].
|
|
1036
|
+
merge[i].completedStoresCount ?
|
|
884
1037
|
Math.round(
|
|
885
|
-
( Number( merge[i].
|
|
886
|
-
|
|
887
|
-
|
|
1038
|
+
( Number( merge[i].completedStoresCount ) /
|
|
1039
|
+
Number( merge[i].totalFilesCount ) ) *
|
|
1040
|
+
100,
|
|
888
1041
|
) :
|
|
889
1042
|
0 :
|
|
890
1043
|
0,
|
|
891
1044
|
isAssigned:
|
|
892
|
-
merge[i].
|
|
1045
|
+
merge[i].userAsignedCount && merge[i].userAsignedCount > 0 ?
|
|
1046
|
+
true :
|
|
1047
|
+
false,
|
|
893
1048
|
Assignedcount:
|
|
894
|
-
merge[i].
|
|
895
|
-
merge[i].
|
|
1049
|
+
merge[i].userAsignedCount && merge[i].userAsignedCount > 0 ?
|
|
1050
|
+
merge[i].userAsignedCount :
|
|
896
1051
|
0,
|
|
897
1052
|
} );
|
|
898
1053
|
}
|
|
@@ -904,10 +1059,10 @@ export async function workSpace( req, res ) {
|
|
|
904
1059
|
exportdata.push( {
|
|
905
1060
|
'Client Name': element.clientName,
|
|
906
1061
|
'Client Id': element.clientId,
|
|
1062
|
+
'Completed stores Count': element.completedStoresCount,
|
|
907
1063
|
'Completed Percentage': element.completedRatio + ' %',
|
|
908
1064
|
'Pending Queue': element.pendingByQueue,
|
|
909
1065
|
'Pending User': element.pendingByUser,
|
|
910
|
-
'Completed': element.completedCount,
|
|
911
1066
|
'Draft': element.isDraft ? 1 : 0,
|
|
912
1067
|
'Assigned': element.Assignedcount,
|
|
913
1068
|
} );
|
|
@@ -916,7 +1071,7 @@ export async function workSpace( req, res ) {
|
|
|
916
1071
|
return;
|
|
917
1072
|
} else {
|
|
918
1073
|
return res.sendSuccess( {
|
|
919
|
-
result: temp,
|
|
1074
|
+
result: temp.sort( ( a, b ) => a.isEnable-b.isEnable ),
|
|
920
1075
|
count: count.length,
|
|
921
1076
|
totalStores: totalStores,
|
|
922
1077
|
} );
|
|
@@ -1136,11 +1291,13 @@ export async function save( req, res ) {
|
|
|
1136
1291
|
|
|
1137
1292
|
let clientData = await findClient( { clientId: storeConfig.clientId } );
|
|
1138
1293
|
|
|
1139
|
-
if (
|
|
1294
|
+
if (
|
|
1140
1295
|
( storeAuditData.beforeCount - inputData.customerCount ) /
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1296
|
+
storeAuditData.beforeCount <
|
|
1297
|
+
storeConfig.auditConfigs.ratio &&
|
|
1298
|
+
inputData.auditType == 'Audit' &&
|
|
1299
|
+
inputData.moduleType == 'traffic'
|
|
1300
|
+
) {
|
|
1144
1301
|
logger.info(
|
|
1145
1302
|
`Hit in Reaudit pushing queue Store Id=${inputData.storeId},File Date=${inputData.fileDate}, /n \nQueue Name = ${clientData[0].auditConfigs.queueName}`,
|
|
1146
1303
|
'Reaudit',
|
|
@@ -1156,7 +1313,10 @@ export async function save( req, res ) {
|
|
|
1156
1313
|
before_count: storeAuditData.beforeCount,
|
|
1157
1314
|
} ),
|
|
1158
1315
|
};
|
|
1159
|
-
const sqsQueue = await sendMessageToQueue(
|
|
1316
|
+
const sqsQueue = await sendMessageToQueue(
|
|
1317
|
+
sqsProduceQueue.QueueUrl,
|
|
1318
|
+
sqsProduceQueue.MessageBody,
|
|
1319
|
+
);
|
|
1160
1320
|
|
|
1161
1321
|
if ( sqsQueue.statusCode ) {
|
|
1162
1322
|
logger.error( {
|
|
@@ -1166,30 +1326,39 @@ export async function save( req, res ) {
|
|
|
1166
1326
|
return res.sendError( mappingUpload, 500 );
|
|
1167
1327
|
}
|
|
1168
1328
|
|
|
1169
|
-
await updateOneStoreAudit(
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1329
|
+
await updateOneStoreAudit(
|
|
1330
|
+
{
|
|
1331
|
+
storeId: inputData.storeId,
|
|
1332
|
+
fileDate: inputData.fileDate,
|
|
1333
|
+
moduleType: inputData.moduleType,
|
|
1334
|
+
zoneName: inputData.zoneName,
|
|
1335
|
+
auditType: inputData.auditType,
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
status: 'not_assign',
|
|
1339
|
+
afterCount: inputData.customerCount,
|
|
1340
|
+
auditType: 'ReAudit',
|
|
1341
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1342
|
+
},
|
|
1343
|
+
);
|
|
1180
1344
|
} else {
|
|
1181
|
-
logger.info( 'Hit in Features', {
|
|
1182
|
-
|
|
1183
|
-
fileDate: inputData.fileDate,
|
|
1184
|
-
moduleType: inputData.moduleType,
|
|
1185
|
-
zoneName: inputData.zoneName,
|
|
1186
|
-
auditType: inputData.auditType,
|
|
1187
|
-
},
|
|
1188
|
-
{
|
|
1189
|
-
status: 'completed',
|
|
1190
|
-
afterCount: inputData.customerCount,
|
|
1191
|
-
timeSpent: timeDifferenceInMinutes,
|
|
1345
|
+
logger.info( 'Hit in Features', {
|
|
1346
|
+
data: _.omit( inputData, [ 'junk', 'employee', 'customer' ] ),
|
|
1192
1347
|
} );
|
|
1348
|
+
await updateOneStoreAudit(
|
|
1349
|
+
{
|
|
1350
|
+
storeId: inputData.storeId,
|
|
1351
|
+
fileDate: inputData.fileDate,
|
|
1352
|
+
moduleType: inputData.moduleType,
|
|
1353
|
+
zoneName: inputData.zoneName,
|
|
1354
|
+
auditType: inputData.auditType,
|
|
1355
|
+
},
|
|
1356
|
+
{
|
|
1357
|
+
status: 'completed',
|
|
1358
|
+
afterCount: inputData.customerCount,
|
|
1359
|
+
timeSpent: timeDifferenceInMinutes,
|
|
1360
|
+
},
|
|
1361
|
+
);
|
|
1193
1362
|
|
|
1194
1363
|
const sqsProduceQueue = {
|
|
1195
1364
|
QueueUrl: `${sqs.url}${sqs.feature}`,
|
|
@@ -1203,7 +1372,10 @@ export async function save( req, res ) {
|
|
|
1203
1372
|
} ),
|
|
1204
1373
|
};
|
|
1205
1374
|
logger.info( { sqsProduceQueue: sqsProduceQueue } );
|
|
1206
|
-
const sqsQueue = await sendMessageToQueue(
|
|
1375
|
+
const sqsQueue = await sendMessageToQueue(
|
|
1376
|
+
sqsProduceQueue.QueueUrl,
|
|
1377
|
+
sqsProduceQueue.MessageBody,
|
|
1378
|
+
);
|
|
1207
1379
|
logger.info( { sqsQueue: sqsQueue } );
|
|
1208
1380
|
}
|
|
1209
1381
|
|
package/src/docs/audit.docs.js
CHANGED
|
@@ -1,10 +1,99 @@
|
|
|
1
|
-
import { getDraftedDataSchema, getFileSchema, saveDraftSchema, saveSchema, workSpaceSchema } from '../dtos/audit.dtos.js';
|
|
1
|
+
import { auditStoreSchema, clientSchema, getDraftedDataSchema, getFileSchema, saveDraftSchema, saveSchema, userSchema, workSpaceSchema } from '../dtos/audit.dtos.js';
|
|
2
2
|
import j2s from 'joi-to-swagger';
|
|
3
3
|
|
|
4
4
|
export const auditDocs = {
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/* < -- *** Configuration *** --> */
|
|
8
|
+
|
|
9
|
+
// client
|
|
10
|
+
'/v3/audit/clients': {
|
|
11
|
+
get: {
|
|
12
|
+
tags: [ 'Client' ],
|
|
13
|
+
description: 'Get client list which is enable for audit',
|
|
14
|
+
operationId: 'clients',
|
|
15
|
+
parameters: [
|
|
16
|
+
{
|
|
17
|
+
in: 'query',
|
|
18
|
+
name: 'limit',
|
|
19
|
+
scema: j2s( clientSchema ).swagger,
|
|
20
|
+
require: false,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
in: 'query',
|
|
24
|
+
name: 'offset',
|
|
25
|
+
scema: j2s( clientSchema ).swagger,
|
|
26
|
+
require: false,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
responses: {
|
|
30
|
+
200: { description: 'Successful' },
|
|
31
|
+
401: { description: 'Unauthorized User' },
|
|
32
|
+
422: { description: 'Field Error' },
|
|
33
|
+
500: { description: 'Server Error' },
|
|
34
|
+
204: { description: 'Not Found' },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
// store
|
|
40
|
+
|
|
41
|
+
'/v3/audit/audit-stores': {
|
|
42
|
+
post: {
|
|
43
|
+
tags: [ 'Stores' ],
|
|
44
|
+
description: `sGet list of stores`,
|
|
45
|
+
operationId: 'audit-stores',
|
|
46
|
+
parameters: {},
|
|
47
|
+
requestBody: {
|
|
48
|
+
content: {
|
|
49
|
+
'application/json': {
|
|
50
|
+
schema: j2s( auditStoreSchema ).swagger,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
responses: {
|
|
55
|
+
200: { description: 'Successful' },
|
|
56
|
+
401: { description: 'Unauthorized User' },
|
|
57
|
+
422: { description: 'Field Error' },
|
|
58
|
+
500: { description: 'Server Error' },
|
|
59
|
+
204: { description: 'Not Found' },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
// user
|
|
65
|
+
'/v3/audit/tango-users': {
|
|
66
|
+
get: {
|
|
67
|
+
tags: [ 'User' ],
|
|
68
|
+
description: 'Get user list',
|
|
69
|
+
operationId: 'tango-users',
|
|
70
|
+
parameters: [
|
|
71
|
+
{
|
|
72
|
+
in: 'query',
|
|
73
|
+
name: 'limit',
|
|
74
|
+
scema: j2s( userSchema ).swagger,
|
|
75
|
+
require: false,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
in: 'query',
|
|
79
|
+
name: 'offset',
|
|
80
|
+
scema: j2s( userSchema ).swagger,
|
|
81
|
+
require: false,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
responses: {
|
|
85
|
+
200: { description: 'Successful' },
|
|
86
|
+
401: { description: 'Unauthorized User' },
|
|
87
|
+
422: { description: 'Field Error' },
|
|
88
|
+
500: { description: 'Server Error' },
|
|
89
|
+
204: { description: 'Not Found' },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
|
|
5
94
|
'/v3/audit/get-file': {
|
|
6
95
|
get: {
|
|
7
|
-
tags: [ 'Audit' ],
|
|
96
|
+
tags: [ 'Audit Mapping' ],
|
|
8
97
|
description: 'Get a file via queue message',
|
|
9
98
|
operationId: 'get-file',
|
|
10
99
|
parameters: [
|
|
@@ -44,7 +133,7 @@ export const auditDocs = {
|
|
|
44
133
|
},
|
|
45
134
|
'/v3/audit/save-draft': {
|
|
46
135
|
post: {
|
|
47
|
-
tags: [ 'Audit' ],
|
|
136
|
+
tags: [ 'Audit Mapping' ],
|
|
48
137
|
description: `save audited file. which is save in the mongo db`,
|
|
49
138
|
operationId: 'save-draft',
|
|
50
139
|
parameters: {},
|
|
@@ -66,7 +155,7 @@ export const auditDocs = {
|
|
|
66
155
|
},
|
|
67
156
|
'/v3/audit/get-drafted-data': {
|
|
68
157
|
get: {
|
|
69
|
-
tags: [ 'Audit' ],
|
|
158
|
+
tags: [ 'Audit Mapping' ],
|
|
70
159
|
description: 'Get a saved file via DB',
|
|
71
160
|
operationId: 'get-drafted-data',
|
|
72
161
|
parameters: [
|
|
@@ -94,7 +183,7 @@ export const auditDocs = {
|
|
|
94
183
|
},
|
|
95
184
|
'/v3/audit/save': {
|
|
96
185
|
post: {
|
|
97
|
-
tags: [ 'Audit' ],
|
|
186
|
+
tags: [ 'Audit Mapping' ],
|
|
98
187
|
description: `submit the audit file. which is store in the bucket in the json format`,
|
|
99
188
|
operationId: 'save',
|
|
100
189
|
parameters: {},
|
|
@@ -116,10 +205,16 @@ export const auditDocs = {
|
|
|
116
205
|
},
|
|
117
206
|
'/v3/audit/work-space': {
|
|
118
207
|
get: {
|
|
119
|
-
tags: [ 'Audit' ],
|
|
208
|
+
tags: [ 'Audit Mapping' ],
|
|
120
209
|
description: 'queue wise info of audit files ',
|
|
121
210
|
operationId: 'work-space',
|
|
122
211
|
parameters: [
|
|
212
|
+
{
|
|
213
|
+
in: 'query',
|
|
214
|
+
name: 'moduleType',
|
|
215
|
+
scema: j2s( workSpaceSchema ).swagger,
|
|
216
|
+
require: true,
|
|
217
|
+
},
|
|
123
218
|
{
|
|
124
219
|
in: 'query',
|
|
125
220
|
name: 'searchValue',
|
package/src/dtos/audit.dtos.js
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
import joi from 'joi';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
/* < -- *** Configurations *** --> */
|
|
5
|
+
|
|
6
|
+
// client
|
|
7
|
+
export const clientSchema = joi.object(
|
|
8
|
+
{
|
|
9
|
+
limit: joi.number().optional(),
|
|
10
|
+
offset: joi.number().optional(),
|
|
11
|
+
},
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const clientValid = {
|
|
15
|
+
query: clientSchema,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// store
|
|
19
|
+
export const auditStoreSchema = joi.object(
|
|
20
|
+
{
|
|
21
|
+
clientId: joi.array().required(),
|
|
22
|
+
limit: joi.number().optional(),
|
|
23
|
+
offset: joi.number().optional(),
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const auditStoreValid = {
|
|
28
|
+
body: auditStoreSchema,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// user
|
|
32
|
+
export const userSchema = joi.object(
|
|
33
|
+
{
|
|
34
|
+
|
|
35
|
+
limit: joi.number().optional(),
|
|
36
|
+
offset: joi.number().optional(),
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const userValid = {
|
|
41
|
+
query: userSchema,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/* < -- *** Audit Mapping *** --> */
|
|
45
|
+
|
|
46
|
+
|
|
4
47
|
export const getFileSchema = joi.object(
|
|
5
48
|
{
|
|
6
49
|
queueName: joi.string().required(),
|
|
@@ -81,6 +124,7 @@ export const saveValid = {
|
|
|
81
124
|
export const workSpaceSchema = joi.object(
|
|
82
125
|
{
|
|
83
126
|
searchValue: joi.string().optional().allow( '' ),
|
|
127
|
+
moduleType: joi.string().required(),
|
|
84
128
|
offset: joi.string().optional(),
|
|
85
129
|
limit: joi.number().optional(),
|
|
86
130
|
isExport: joi.boolean().optional(),
|
|
@@ -1,11 +1,18 @@
|
|
|
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, save, saveDraft, workSpace } from '../controllers/audit.controllers.js';
|
|
5
|
-
import { getDraftedDataValid, getFileValid, saveDraftValid, saveValid, workSpaceValid } from '../dtos/audit.dtos.js';
|
|
4
|
+
import { auditStoreList, auditUserList, clients, getAuditFile, getDraftedData, save, saveDraft, workSpace } from '../controllers/audit.controllers.js';
|
|
5
|
+
import { auditStoreValid, clientValid, getDraftedDataValid, getFileValid, saveDraftValid, saveValid, workSpaceValid } from '../dtos/audit.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditRouter = express.Router();
|
|
8
8
|
|
|
9
|
+
// Configuration
|
|
10
|
+
|
|
11
|
+
auditRouter.get( '/clients', isAllowedSessionHandler, validate( clientValid ), clients );
|
|
12
|
+
auditRouter.post( '/audit-stores', isAllowedSessionHandler, validate( auditStoreValid ), auditStoreList );
|
|
13
|
+
auditRouter.get( '/tango-users', isAllowedSessionHandler, auditUserList );
|
|
14
|
+
|
|
15
|
+
// Audit Mapping
|
|
9
16
|
auditRouter.get( '/get-file', isAllowedSessionHandler, validate( getFileValid ), isExistsQueue, getAuditFile );
|
|
10
17
|
auditRouter.post( '/save-draft', isAllowedSessionHandler, validate( saveDraftValid ), saveDraft );
|
|
11
18
|
auditRouter.get( '/get-drafted-data', isAllowedSessionHandler, validate( getDraftedDataValid ), getDraftedData );
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import auditStoreDataModel from 'tango-api-schema/schema/auditStoreData.model.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function aggregateAuditStoreDataSchema( query ) {
|
|
5
|
+
return auditStoreDataModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function findOneStoreData( query, fields, sort ) {
|
|
9
|
+
return auditStoreDataModel.findOne( query, fields ).sort( sort );
|
|
10
|
+
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { logger } from 'tango-app-api-middleware';
|
|
2
|
-
import { aggregateClient } from '../service/client.service.js';
|
|
3
|
-
|
|
4
|
-
export async function clients( req, res ) {
|
|
5
|
-
try {
|
|
6
|
-
const inputData = req.query;
|
|
7
|
-
const query =[
|
|
8
|
-
{
|
|
9
|
-
$match: {
|
|
10
|
-
'status': { $in: [ 'active', 'hold' ] },
|
|
11
|
-
'auditConfigs.audit': true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
$project: {
|
|
16
|
-
_id: 0,
|
|
17
|
-
clientName: 1,
|
|
18
|
-
clientId: 1,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
const count = await aggregateClient( query );
|
|
24
|
-
if ( count.length == 0 ) {
|
|
25
|
-
return res.sendSuccess( { result: [], count: 0 } );
|
|
26
|
-
}
|
|
27
|
-
if ( inputData.limit ) {
|
|
28
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * inputData.limit : 0;
|
|
29
|
-
query.push(
|
|
30
|
-
{ $skip: offset },
|
|
31
|
-
{ $limit: limit },
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
const getAuditClients = await aggregateClient( query );
|
|
35
|
-
|
|
36
|
-
return res.sendSuccess( { result: getAuditClients, count: count.length } );
|
|
37
|
-
} catch ( error ) {
|
|
38
|
-
const err = error.message || 'Internal Server Error';
|
|
39
|
-
logger.info( { error: error, messgae: req.query, function: 'clients' } );
|
|
40
|
-
return res.sendError( err, 500 );
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { logger } from 'tango-app-api-middleware';
|
|
2
|
-
import { aggregateStore } from '../service/store.service.js';
|
|
3
|
-
|
|
4
|
-
export async function auditStoreList( req, res ) {
|
|
5
|
-
try {
|
|
6
|
-
const inputData = req.body;
|
|
7
|
-
const query =[
|
|
8
|
-
{
|
|
9
|
-
$match: {
|
|
10
|
-
clientId: { $in: inputData.clientId },
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
$project: {
|
|
15
|
-
_id: 0,
|
|
16
|
-
clientId: 1,
|
|
17
|
-
storeId: 1,
|
|
18
|
-
storeName: 1,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
const count = await aggregateStore( query );
|
|
24
|
-
if ( count.length == 0 ) {
|
|
25
|
-
return res.sendSuccess( { result: [], count: 0 } );
|
|
26
|
-
}
|
|
27
|
-
if ( inputData.limit ) {
|
|
28
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * inputData.limit : 0;
|
|
29
|
-
query.push(
|
|
30
|
-
{ $skip: offset },
|
|
31
|
-
{ $limit: limit },
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
const result = await aggregateStore( query );
|
|
35
|
-
|
|
36
|
-
return res.sendSuccess( { result: result, count: count.length } );
|
|
37
|
-
} catch ( error ) {
|
|
38
|
-
const err = error.message || 'Internal Server Error';
|
|
39
|
-
logger.info( { error: error, messgae: req.body, function: 'auditStoreList' } );
|
|
40
|
-
return res.sendError( err, 500 );
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { logger } from 'tango-app-api-middleware';
|
|
2
|
-
import { aggregateUser } from '../service/user.service.js';
|
|
3
|
-
|
|
4
|
-
export async function auditUserList( req, res ) {
|
|
5
|
-
try {
|
|
6
|
-
const inputData = req.query;
|
|
7
|
-
const query =[
|
|
8
|
-
{
|
|
9
|
-
$match: {
|
|
10
|
-
userType: { $eq: 'tango' },
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
$project: {
|
|
15
|
-
userName: 1,
|
|
16
|
-
userId: '$_id',
|
|
17
|
-
_id: 0,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const count = await aggregateUser( query );
|
|
23
|
-
if ( count.length == 0 ) {
|
|
24
|
-
return res.sendSuccess( { result: [], count: 0 } );
|
|
25
|
-
}
|
|
26
|
-
if ( inputData.limit ) {
|
|
27
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * inputData.limit : 0;
|
|
28
|
-
query.push(
|
|
29
|
-
{ $skip: offset },
|
|
30
|
-
{ $limit: limit },
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
const result = await aggregateUser( query );
|
|
34
|
-
|
|
35
|
-
return res.sendSuccess( { result: result, count: count.length } );
|
|
36
|
-
} catch ( error ) {
|
|
37
|
-
const err = error.message || 'Internal Server Error';
|
|
38
|
-
logger.info( { error: error, messgae: req.query, function: 'auditUserList' } );
|
|
39
|
-
return res.sendError( err, 500 );
|
|
40
|
-
}
|
|
41
|
-
}
|
package/src/docs/client.docs.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { clientSchema } from '../dtos/client.dtos.js';
|
|
3
|
-
|
|
4
|
-
export const clientDocs = {
|
|
5
|
-
'/v3/audit/client/clients': {
|
|
6
|
-
get: {
|
|
7
|
-
tags: [ 'Audit/Client' ],
|
|
8
|
-
description: 'Get client list which is enable for audit',
|
|
9
|
-
operationId: 'clients',
|
|
10
|
-
parameters: [
|
|
11
|
-
{
|
|
12
|
-
in: 'query',
|
|
13
|
-
name: 'limit',
|
|
14
|
-
scema: j2s( clientSchema ).swagger,
|
|
15
|
-
require: false,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
in: 'query',
|
|
19
|
-
name: 'offset',
|
|
20
|
-
scema: j2s( clientSchema ).swagger,
|
|
21
|
-
require: false,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
responses: {
|
|
25
|
-
200: { description: 'Successful' },
|
|
26
|
-
401: { description: 'Unauthorized User' },
|
|
27
|
-
422: { description: 'Field Error' },
|
|
28
|
-
500: { description: 'Server Error' },
|
|
29
|
-
204: { description: 'Not Found' },
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
package/src/docs/store.docs.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { auditStoreSchema } from '../dtos/store.dtos.js';
|
|
3
|
-
|
|
4
|
-
export const storeDocs = {
|
|
5
|
-
'/v3/audit/store/audit-stores': {
|
|
6
|
-
post: {
|
|
7
|
-
tags: [ 'Audit/Stores' ],
|
|
8
|
-
description: `sGet list of stores`,
|
|
9
|
-
operationId: 'audit-stores',
|
|
10
|
-
parameters: {},
|
|
11
|
-
requestBody: {
|
|
12
|
-
content: {
|
|
13
|
-
'application/json': {
|
|
14
|
-
schema: j2s( auditStoreSchema ).swagger,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
responses: {
|
|
19
|
-
200: { description: 'Successful' },
|
|
20
|
-
401: { description: 'Unauthorized User' },
|
|
21
|
-
422: { description: 'Field Error' },
|
|
22
|
-
500: { description: 'Server Error' },
|
|
23
|
-
204: { description: 'Not Found' },
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
};
|
package/src/docs/user.docs.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { userSchema } from '../dtos/user.dtos.js';
|
|
3
|
-
|
|
4
|
-
export const userDocs = {
|
|
5
|
-
'/v3/audit/user/tango-users': {
|
|
6
|
-
get: {
|
|
7
|
-
tags: [ 'Audit/User' ],
|
|
8
|
-
description: 'Get user list',
|
|
9
|
-
operationId: 'tango-users',
|
|
10
|
-
parameters: [
|
|
11
|
-
{
|
|
12
|
-
in: 'query',
|
|
13
|
-
name: 'limit',
|
|
14
|
-
scema: j2s( userSchema ).swagger,
|
|
15
|
-
require: false,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
in: 'query',
|
|
19
|
-
name: 'offset',
|
|
20
|
-
scema: j2s( userSchema ).swagger,
|
|
21
|
-
require: false,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
responses: {
|
|
25
|
-
200: { description: 'Successful' },
|
|
26
|
-
401: { description: 'Unauthorized User' },
|
|
27
|
-
422: { description: 'Field Error' },
|
|
28
|
-
500: { description: 'Server Error' },
|
|
29
|
-
204: { description: 'Not Found' },
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
package/src/dtos/client.dtos.js
DELETED
package/src/dtos/store.dtos.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import joi from 'joi';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const auditStoreSchema = joi.object(
|
|
5
|
-
{
|
|
6
|
-
clientId: joi.array().required(),
|
|
7
|
-
limit: joi.number().optional(),
|
|
8
|
-
offset: joi.number().optional(),
|
|
9
|
-
},
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export const auditStoreValid = {
|
|
13
|
-
body: auditStoreSchema,
|
|
14
|
-
};
|
package/src/dtos/user.dtos.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
-
import { clients } from '../controllers/client.controllers.js';
|
|
4
|
-
import { clientValid } from '../dtos/client.dtos.js';
|
|
5
|
-
|
|
6
|
-
export const clientRouter = Router();
|
|
7
|
-
|
|
8
|
-
clientRouter.get( '/clients', isAllowedSessionHandler, validate( clientValid ), clients );
|
|
9
|
-
|
|
10
|
-
export default clientRouter;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
3
|
-
import { auditStoreList } from '../controllers/store.controllers.js';
|
|
4
|
-
import { auditStoreValid } from '../dtos/store.dtos.js';
|
|
5
|
-
|
|
6
|
-
export const storeRouter = Router();
|
|
7
|
-
|
|
8
|
-
storeRouter.post( '/audit-stores', isAllowedSessionHandler, validate( auditStoreValid ), auditStoreList );
|
|
9
|
-
|
|
10
|
-
export default storeRouter;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Router } from 'express';
|
|
2
|
-
import { isAllowedSessionHandler } from 'tango-app-api-middleware';
|
|
3
|
-
import { auditUserList } from '../controllers/user.controllers.js';
|
|
4
|
-
|
|
5
|
-
export const userRouter = Router();
|
|
6
|
-
|
|
7
|
-
userRouter.get( '/tango-users', isAllowedSessionHandler, auditUserList );
|
|
8
|
-
|
|
9
|
-
export default userRouter;
|