tango-app-api-audit 1.0.2 → 1.0.3
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/.eslintrc.cjs +1 -0
- package/package.json +38 -36
- package/src/controllers/audit.controllers.js +744 -0
- package/src/controllers/auditMetrics.controllers.js +396 -10
- package/src/docs/audit.docs.js +39 -0
- package/src/docs/auditMetrics.docs.js +23 -1
- package/src/dtos/audit.dtos.js +27 -0
- package/src/dtos/auditMetrics.dtos.js +32 -0
- package/src/routes/audit.routes.js +6 -0
- package/src/routes/auditMetrics.routes.js +5 -4
- package/src/service/assignAudit.service.js +8 -0
- package/src/service/auditClientData.service.js +6 -0
- package/src/service/client.service.js +6 -0
- package/src/service/storeAudit.service.js +9 -0
- package/src/service/user.service.js +6 -0
- package/src/service/userAudit.service.js +14 -0
- package/src/validation/audit.validation.js +16 -0
|
@@ -1,21 +1,407 @@
|
|
|
1
|
+
import { download, getUTC, logger } from 'tango-app-api-middleware';
|
|
2
|
+
import { aggregateAuditClientData } from '../service/auditClientData.service.js';
|
|
3
|
+
// import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
1
4
|
|
|
2
5
|
|
|
3
6
|
export async function getAuditImageList( req, res ) {
|
|
4
|
-
try {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// try {
|
|
8
|
+
// logger.info( { env: env } );
|
|
9
|
+
// const inputData = req.body;
|
|
10
|
+
// return res.sendSuccess( { result: inputData, config: env.cloud.aws.region } );
|
|
11
|
+
// } catch ( error ) {
|
|
12
|
+
// logger.info( { error: error, message: req.body, function: 'getAuditImageList' } );
|
|
13
|
+
// return res.sendError( error );
|
|
14
|
+
// }
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
export async function userAuditHistory( req, res ) {
|
|
18
|
+
// try {
|
|
19
|
+
// const inputData = req.body;
|
|
20
|
+
// return res.sendSuccess( { result: inputData } );
|
|
21
|
+
// } catch ( error ) {
|
|
22
|
+
// logger.info( { error: error, message: req.body, function: 'userAuditHistory' } );
|
|
23
|
+
// return res.sendError( error );
|
|
24
|
+
// }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function storeMetrics( req, res ) {
|
|
28
|
+
// try {
|
|
29
|
+
// const today = moment().subtract( 1, 'days' ).format( 'YYYY-MM-DD' );
|
|
30
|
+
// const inputData = req.body;
|
|
31
|
+
// const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
32
|
+
// const start = dateRange.start;
|
|
33
|
+
// const end = dateRange.end;
|
|
34
|
+
// const filter = [
|
|
35
|
+
// { fileDateISO: { $gte: start } },
|
|
36
|
+
// { fileDateISO: { $lte: end } },
|
|
37
|
+
// ];
|
|
38
|
+
// if ( inputData.filterByClient && inputData.filterByClient?.length > 0 ) {
|
|
39
|
+
// filter.push( { clientId: { $in: inputData.filterByClient } } );
|
|
40
|
+
// }
|
|
41
|
+
// const query = [
|
|
42
|
+
// {
|
|
43
|
+
// $match: {
|
|
44
|
+
// $and: filter,
|
|
45
|
+
// },
|
|
46
|
+
// },
|
|
47
|
+
// {
|
|
48
|
+
// $project: {
|
|
49
|
+
// fileDate: 1,
|
|
50
|
+
// fileDateISO: 1,
|
|
51
|
+
// clientName: 1,
|
|
52
|
+
// clientId: 1,
|
|
53
|
+
// installedStore: 1,
|
|
54
|
+
// totalFilesCount: 1,
|
|
55
|
+
// queueName: 1,
|
|
56
|
+
// },
|
|
57
|
+
// },
|
|
58
|
+
// {
|
|
59
|
+
// $lookup: {
|
|
60
|
+
// 'from': 'audit',
|
|
61
|
+
// 'let': { 'client_id': '$clientId', 'file_date': '$fileDate', 'total_files_count': '$totalFilesCount' },
|
|
62
|
+
// 'pipeline': [
|
|
63
|
+
|
|
64
|
+
// {
|
|
65
|
+
// $match: {
|
|
66
|
+
// $expr: {
|
|
67
|
+
// $and: [
|
|
68
|
+
// { $eq: [ '$clientId', '$$client_id' ] },
|
|
69
|
+
// { $eq: [ '$fileDate', '$$file_date' ] },
|
|
70
|
+
// ],
|
|
71
|
+
// },
|
|
72
|
+
// },
|
|
73
|
+
// },
|
|
74
|
+
// {
|
|
75
|
+
// $project: {
|
|
76
|
+
// completedStores: { $cond: [ { $eq: [ '$storeStatus', 'completed' ] }, 1, 0 ] },
|
|
77
|
+
// assignedStores: { $cond: [ { $or: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted' ] ] }, { $in: [ '$storeStatus', [ 'skipped' ] ] } ] }, 1, 0 ] },
|
|
78
|
+
// },
|
|
79
|
+
// },
|
|
80
|
+
// {
|
|
81
|
+
// $group: {
|
|
82
|
+
// _id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
83
|
+
// completedStores: { $sum: '$completedStores' },
|
|
84
|
+
// assignedStores: { $sum: '$assignedStores' },
|
|
85
|
+
// fileCount: { $sum: 1 },
|
|
86
|
+
|
|
87
|
+
// },
|
|
88
|
+
// },
|
|
89
|
+
// {
|
|
90
|
+
// $project: {
|
|
91
|
+
// _id: 0,
|
|
92
|
+
// fileDateISO: 1,
|
|
93
|
+
// completedStores: 1,
|
|
94
|
+
// assignedStores: 1,
|
|
95
|
+
// completePercentage: {
|
|
96
|
+
// $round: [ {
|
|
97
|
+
// $multiply: [
|
|
98
|
+
// 100, {
|
|
99
|
+
// $divide: [
|
|
100
|
+
// '$completedStores', '$$total_files_count',
|
|
101
|
+
// ],
|
|
102
|
+
// },
|
|
103
|
+
// ],
|
|
104
|
+
// }, 1 ],
|
|
105
|
+
|
|
106
|
+
// },
|
|
107
|
+
// fileCount: 1,
|
|
108
|
+
// },
|
|
109
|
+
|
|
110
|
+
// },
|
|
111
|
+
// ], 'as': 'audit',
|
|
112
|
+
// },
|
|
113
|
+
// },
|
|
114
|
+
// {
|
|
115
|
+
// $unwind: { path: '$audit', preserveNullAndEmptyArrays: true },
|
|
116
|
+
// },
|
|
117
|
+
// {
|
|
118
|
+
// $project: {
|
|
119
|
+
// _id: 0,
|
|
120
|
+
// clientId: 1,
|
|
121
|
+
// clientName: 1,
|
|
122
|
+
// fileDate: 1,
|
|
123
|
+
// fileDateISO: 1,
|
|
124
|
+
// installedStore: 1,
|
|
125
|
+
// totalFilesCount: 1,
|
|
126
|
+
// queueName: 1,
|
|
127
|
+
// completedStores: { $ifNull: [ '$audit.completedStores', 0 ] },
|
|
128
|
+
// assignedStores: { $ifNull: [ '$audit.assignedStores', 0 ] },
|
|
129
|
+
// completePercentage: { $ifNull: [ '$audit.completePercentage', 0 ] },
|
|
130
|
+
// notAssigned: '',
|
|
131
|
+
// status: '',
|
|
132
|
+
// fileCount: { $ifNull: [ '$audit.fileCount', 0 ] },
|
|
133
|
+
// },
|
|
134
|
+
// },
|
|
135
|
+
|
|
136
|
+
// ];
|
|
137
|
+
// query.push( {
|
|
138
|
+
// $sort: {
|
|
139
|
+
// fileDateISO: -1,
|
|
140
|
+
// },
|
|
141
|
+
// } );
|
|
142
|
+
|
|
143
|
+
// if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
144
|
+
// query.push( {
|
|
145
|
+
// $match: {
|
|
146
|
+
// $or: [
|
|
147
|
+
// { clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
148
|
+
// { clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
149
|
+
// ],
|
|
150
|
+
// },
|
|
151
|
+
// } );
|
|
152
|
+
// }
|
|
153
|
+
// const result = await auditFilesCount.aggregate( query );
|
|
154
|
+
|
|
155
|
+
// if ( result.length == 0 ) {
|
|
156
|
+
// return res.sendError( 'No data Found', 204 );
|
|
157
|
+
// }
|
|
158
|
+
// let count;
|
|
159
|
+
// if ( inputData.filterByStatus && inputData.filterByStatus.length > 0 ) {
|
|
160
|
+
// let testCount;
|
|
161
|
+
// for ( let i = 0; i < result.length; i++ ) {
|
|
162
|
+
// const item = result[i];
|
|
163
|
+
// if ( inputData.fromDate === inputData.toDate && inputData.fromDate === today ) {
|
|
164
|
+
// const temp = await listQueue( item.queueName );
|
|
165
|
+
// item.notAssigned = Number( temp );
|
|
166
|
+
// } else {
|
|
167
|
+
// item.notAssigned = 'No Data';
|
|
168
|
+
// }
|
|
169
|
+
// item.status = ( item.totalFilesCount === item.completedStores && item.assignedStores === 0 && ( item.notAssigned == 0 || item.notAssigned === 'No Data' ) ) ? 'completed' :
|
|
170
|
+
// item.fileCount > 0 ? 'pending' : 'not_taken';
|
|
171
|
+
// delete item.fileCount;
|
|
172
|
+
// testCount = result.filter( ( i ) => inputData.filterByStatus.includes( i.status ) );
|
|
173
|
+
// count = testCount.length;
|
|
174
|
+
// }
|
|
175
|
+
// if ( !inputData.export ) {
|
|
176
|
+
// const skip = ( inputData.offset - 1 ) * inputData.limit;
|
|
177
|
+
// testCount = testCount.slice( skip, skip + inputData.limit );
|
|
178
|
+
// }
|
|
179
|
+
// if ( inputData.export ) {
|
|
180
|
+
// const exportdata = [];
|
|
181
|
+
// testCount.forEach( ( element ) => {
|
|
182
|
+
// exportdata.push( {
|
|
183
|
+
// 'File Date': element.fileDate,
|
|
184
|
+
// 'Client Name': element.clientName,
|
|
185
|
+
// 'Client Id': element.clientId,
|
|
186
|
+
// 'Completed Percentage': element.completePercentage + ' %',
|
|
187
|
+
// 'Installed Stores': element.installedStore,
|
|
188
|
+
// 'Audit Stores': element.totalFilesCount,
|
|
189
|
+
// 'Inprogress Stores': element.assignedStores,
|
|
190
|
+
// 'Not Assigned': element.notAssigned && element.notAssigned == 'No Data' ? 0 : element.notAssigned,
|
|
191
|
+
// 'Completed': element.completedStores,
|
|
192
|
+
// 'Status': element.status,
|
|
193
|
+
// } );
|
|
194
|
+
// } );
|
|
195
|
+
// await download( exportdata, res );
|
|
196
|
+
// return;
|
|
197
|
+
// }
|
|
198
|
+
// return res.sendSuccess( { result: testCount, count: count } );
|
|
199
|
+
// }
|
|
200
|
+
// for ( let i = 0; i < result.length; i++ ) {
|
|
201
|
+
// const item = result[i];
|
|
202
|
+
// if ( inputData.fromDate === inputData.toDate && inputData.fromDate === today ) {
|
|
203
|
+
// const temp = await listQueue( item.queueName );
|
|
204
|
+
// item.notAssigned = Number( temp );
|
|
205
|
+
// } else {
|
|
206
|
+
// item.notAssigned = 'No Data';
|
|
207
|
+
// }
|
|
208
|
+
// item.status = ( item.totalFilesCount === item.completedStores && item.assignedStores === 0 && ( item.notAssigned == 0 || item.notAssigned === 'No Data' ) ) ? 'completed' :
|
|
209
|
+
// item.fileCount > 0 ? 'pending' : 'not_taken';
|
|
210
|
+
// delete item.fileCount;
|
|
211
|
+
// }
|
|
212
|
+
// if ( inputData.export ) {
|
|
213
|
+
// const exportdata = [];
|
|
214
|
+
// result.forEach( ( element ) => {
|
|
215
|
+
// exportdata.push( {
|
|
216
|
+
// 'File Date': element.fileDate,
|
|
217
|
+
// 'Client Name': element.clientName,
|
|
218
|
+
// 'Client Id': element.clientId,
|
|
219
|
+
// 'Completed Percentage': element.completePercentage + ' %',
|
|
220
|
+
// 'Installed Stores': element.installedStore,
|
|
221
|
+
// 'Audit Stores': element.totalFilesCount,
|
|
222
|
+
// 'Assigned Stores': element.assignedStores,
|
|
223
|
+
// 'Not Assigned': element.notAssigned && element.notAssigned == 'No Data' ? 0 : element.notAssigned,
|
|
224
|
+
// 'Completed': element.completedStores,
|
|
225
|
+
// 'Status': element.status,
|
|
226
|
+
// } );
|
|
227
|
+
// } );
|
|
228
|
+
// await download( exportdata, res );
|
|
229
|
+
// return;
|
|
230
|
+
// }
|
|
231
|
+
// return res.sendSuccess( { result: result, count: count } );
|
|
232
|
+
// } catch ( error ) {
|
|
233
|
+
// logger.error( { error: error, data: req.body, function: 'storeMetrics' } );
|
|
234
|
+
// return res.sendError( error, 500 );
|
|
235
|
+
// }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export async function clientMetrics( req, res ) {
|
|
14
239
|
try {
|
|
240
|
+
// const sqs = JSON.parse( process.env.SQS );
|
|
15
241
|
const inputData = req.body;
|
|
16
|
-
|
|
242
|
+
const limit = inputData.limit || 10;
|
|
243
|
+
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
244
|
+
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
245
|
+
let filter = [
|
|
246
|
+
{ fileDateISO: { $gte: dateRange.start } },
|
|
247
|
+
{ fileDateISO: { $lte: dateRange.end } },
|
|
248
|
+
{ clientId: { $in: inputData.filterByClient } },
|
|
249
|
+
];
|
|
250
|
+
const query = [
|
|
251
|
+
{
|
|
252
|
+
$match: {
|
|
253
|
+
$and: filter,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
$project: {
|
|
258
|
+
fileDate: 1,
|
|
259
|
+
clientId: 1,
|
|
260
|
+
clientName: 1,
|
|
261
|
+
queueName: 1,
|
|
262
|
+
installedStore: 1,
|
|
263
|
+
totalFilesCount: 1,
|
|
264
|
+
notAssignedCount: { $ifNull: [ 0, 0 ] },
|
|
265
|
+
clientStatus: { $ifNull: [ '', '' ] },
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
$lookup: {
|
|
270
|
+
'from': 'storeAudit',
|
|
271
|
+
'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalAuditFiles' },
|
|
272
|
+
'pipeline': [
|
|
273
|
+
|
|
274
|
+
{
|
|
275
|
+
$match: {
|
|
276
|
+
$expr: {
|
|
277
|
+
$and: [
|
|
278
|
+
{ $eq: [ '$clientId', '$$clientId' ] },
|
|
279
|
+
{ $eq: [ '$fileDate', '$$fileDate' ] },
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
$project: {
|
|
286
|
+
completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
|
|
287
|
+
inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
$group: {
|
|
292
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
293
|
+
completedStores: { $sum: '$completedStores' },
|
|
294
|
+
inprogressStores: { $sum: '$inprogressStores' },
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
$project: {
|
|
299
|
+
_id: 0,
|
|
300
|
+
completedStores: 1,
|
|
301
|
+
inprogressStores: 1,
|
|
302
|
+
completionPercentage: { $ifNull: [
|
|
303
|
+
{
|
|
304
|
+
$round: [ {
|
|
305
|
+
$multiply: [
|
|
306
|
+
100, {
|
|
307
|
+
$divide: [
|
|
308
|
+
'$completedStores', '$$totalAuditFiles',
|
|
309
|
+
],
|
|
310
|
+
},
|
|
311
|
+
],
|
|
312
|
+
}, 1 ],
|
|
313
|
+
|
|
314
|
+
},
|
|
315
|
+
0,
|
|
316
|
+
],
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
], 'as': 'storeAudit',
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
$unwind: {
|
|
325
|
+
path: '$storeAudit',
|
|
326
|
+
preserveNullAndEmptyArrays: true,
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
$project: {
|
|
331
|
+
fileDate: 1,
|
|
332
|
+
clientId: 1,
|
|
333
|
+
clientName: 1,
|
|
334
|
+
totalFilesCount: 1,
|
|
335
|
+
installedStore: 1,
|
|
336
|
+
inprogressStoresCount: '$storeAudit.inprogressStores',
|
|
337
|
+
notAssignedCount: 1,
|
|
338
|
+
clientStatus: { $cond: [ { $gt: [ '$storeAudit.inprogressStores', 0 ] }, 'not-taken', { $cond: [ { $gt: [ '$notAssignedCount', 0 ] }, 'pending', 'completed' ] } ] },
|
|
339
|
+
completedStores: '$storeAudit.completedStores',
|
|
340
|
+
completionPercentage: '$storeAudit.completionPercentage',
|
|
341
|
+
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
];
|
|
345
|
+
if ( inputData.searchValue ) {
|
|
346
|
+
query.push( {
|
|
347
|
+
$match: {
|
|
348
|
+
$or: [
|
|
349
|
+
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
350
|
+
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
351
|
+
],
|
|
352
|
+
|
|
353
|
+
},
|
|
354
|
+
} );
|
|
355
|
+
}
|
|
356
|
+
if ( inputData.sortColumnName ) {
|
|
357
|
+
const sortBy = inputData.sortBy || -1;
|
|
358
|
+
query.push( {
|
|
359
|
+
$sort: { [inputData.sortColumName]: sortBy },
|
|
360
|
+
},
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const count = await aggregateAuditClientData( query );
|
|
365
|
+
if ( count.length == 0 ) {
|
|
366
|
+
return res.sendError( 'No Data Found', 204 );
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
query.push(
|
|
370
|
+
{ $skip: offset },
|
|
371
|
+
{ $limit: limit },
|
|
372
|
+
);
|
|
373
|
+
if ( inputData.isExport ) {
|
|
374
|
+
query.push(
|
|
375
|
+
{
|
|
376
|
+
$project: {
|
|
377
|
+
'File Date': '$fileDate',
|
|
378
|
+
'Client Name': '$clientName',
|
|
379
|
+
'Client Id': '$clientId',
|
|
380
|
+
'Completed Percentage': '$completionPercentage' + ' %',
|
|
381
|
+
'Installed Stores': '$installedStore',
|
|
382
|
+
'Audit Stores': '$totalFilesCount',
|
|
383
|
+
'Inprogress Stores': '$inprogressStoresCount',
|
|
384
|
+
'Not Assigned': '$notAssignedCount',
|
|
385
|
+
'Completed': '$completedStores',
|
|
386
|
+
'Status': '$clientStatus',
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
|
|
391
|
+
},
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
const result = await aggregateAuditClientData( query );
|
|
397
|
+
if ( inputData.isExport ) {
|
|
398
|
+
await download( result, res );
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
return res.sendSuccess( { result: result, count: count.length } );
|
|
17
402
|
} catch ( error ) {
|
|
18
|
-
|
|
19
|
-
|
|
403
|
+
const err = error.error || 'Internal Server Error';
|
|
404
|
+
logger.info( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
405
|
+
return res.sendError( err, 500 );
|
|
20
406
|
}
|
|
21
407
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getFileSchema } from '../dtos/audit.dtos.js';
|
|
2
|
+
import j2s from 'joi-to-swagger';
|
|
3
|
+
|
|
4
|
+
export const auditDocs = {
|
|
5
|
+
'/v3/audit/get-file': {
|
|
6
|
+
get: {
|
|
7
|
+
tags: [ 'Audit' ],
|
|
8
|
+
description: 'Get a file via queue message',
|
|
9
|
+
operationId: 'get-file',
|
|
10
|
+
parameters: [
|
|
11
|
+
{
|
|
12
|
+
in: 'query',
|
|
13
|
+
name: 'queueName',
|
|
14
|
+
scema: j2s( getFileSchema ).swagger,
|
|
15
|
+
require: true,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
in: 'query',
|
|
19
|
+
name: 'nextId',
|
|
20
|
+
scema: j2s( getFileSchema ).swagger,
|
|
21
|
+
require: false,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
in: 'query',
|
|
25
|
+
name: 'limit',
|
|
26
|
+
scema: j2s( getFileSchema ).swagger,
|
|
27
|
+
require: false,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
responses: {
|
|
31
|
+
200: { description: 'Successfully' },
|
|
32
|
+
401: { description: 'Unauthorized User' },
|
|
33
|
+
422: { description: 'Field Error' },
|
|
34
|
+
500: { description: 'Server Error' },
|
|
35
|
+
204: { description: 'Not Found' },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import j2s from 'joi-to-swagger';
|
|
2
|
-
import { getAuditImagesSchema } from '../dtos/auditMetrics.dtos.js';
|
|
2
|
+
import { clientMetricsSchema, getAuditImagesSchema } from '../dtos/auditMetrics.dtos.js';
|
|
3
3
|
|
|
4
4
|
export const auditMetricsDocs = {
|
|
5
5
|
|
|
@@ -25,4 +25,26 @@ export const auditMetricsDocs = {
|
|
|
25
25
|
},
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
|
+
'/v3/audit-metrics/client-metrics': {
|
|
29
|
+
post: {
|
|
30
|
+
tags: [ 'Audit Metrics' ],
|
|
31
|
+
description: `Get list of client wise details with date range`,
|
|
32
|
+
operationId: 'client-metrics',
|
|
33
|
+
parameters: {},
|
|
34
|
+
requestBody: {
|
|
35
|
+
content: {
|
|
36
|
+
'application/json': {
|
|
37
|
+
schema: j2s( clientMetricsSchema ).swagger,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
responses: {
|
|
42
|
+
200: { description: 'Successful' },
|
|
43
|
+
401: { description: 'Unauthorized User' },
|
|
44
|
+
422: { description: 'Field Error' },
|
|
45
|
+
500: { description: 'Server Error' },
|
|
46
|
+
204: { description: 'Not Found' },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
28
50
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import joi from 'joi';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const getFileSchema = joi.object(
|
|
5
|
+
{
|
|
6
|
+
queueName: joi.string().required(),
|
|
7
|
+
nextId: joi.string().optional(),
|
|
8
|
+
limit: joi.number().optional(),
|
|
9
|
+
},
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const getFileValid = {
|
|
13
|
+
query: getFileSchema,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const getQueueDetailListSchema = joi.object(
|
|
17
|
+
{
|
|
18
|
+
searchValue: joi.string().optional(),
|
|
19
|
+
offset: joi.string().optional(),
|
|
20
|
+
limit: joi.number().optional(),
|
|
21
|
+
export: joi.number().optional(),
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const getQueueDetailListValid = {
|
|
26
|
+
query: getQueueDetailListSchema,
|
|
27
|
+
};
|
|
@@ -27,3 +27,35 @@ export const userAuditHistorySchema = joi.object(
|
|
|
27
27
|
export const userAuditHistoryValid = {
|
|
28
28
|
body: userAuditHistorySchema,
|
|
29
29
|
};
|
|
30
|
+
|
|
31
|
+
export const storeMetricsSchema = joi.object(
|
|
32
|
+
{
|
|
33
|
+
fromDate: joi.string().required(),
|
|
34
|
+
toDate: joi.string().required(),
|
|
35
|
+
searchValue: joi.string().optional(),
|
|
36
|
+
clientId: joi.array().required(),
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const storeMetricsValid = {
|
|
41
|
+
body: storeMetricsSchema,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const clientMetricsSchema = joi.object(
|
|
45
|
+
{
|
|
46
|
+
fromDate: joi.string().required(),
|
|
47
|
+
toDate: joi.string().required(),
|
|
48
|
+
searchValue: joi.string().optional(),
|
|
49
|
+
filterByClient: joi.array().required(),
|
|
50
|
+
status: joi.array().optional(),
|
|
51
|
+
sortColumnName: joi.string().optional(),
|
|
52
|
+
sortBy: joi.number().optional(),
|
|
53
|
+
limit: joi.number().optional(),
|
|
54
|
+
offset: joi.number().optional(),
|
|
55
|
+
isExport: joi.boolean().optional(),
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
export const clientMetricsValid = {
|
|
60
|
+
body: clientMetricsSchema,
|
|
61
|
+
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
|
+
import { isExistsQueue } from '../validation/audit.validation.js';
|
|
3
|
+
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
+
import { getAuditFile, getQueueDetailList } from '../controllers/audit.controllers.js';
|
|
5
|
+
import { getFileValid, getQueueDetailListValid } from '../dtos/audit.dtos.js';
|
|
2
6
|
|
|
3
7
|
export const auditRouter = express.Router();
|
|
4
8
|
|
|
9
|
+
auditRouter.get( '/get-file', validate( getFileValid ), isAllowedSessionHandler, isExistsQueue, getAuditFile );
|
|
10
|
+
auditRouter.get( '/get-queue-detail-list', validate( getQueueDetailListValid ), isAllowedSessionHandler, getQueueDetailList );
|
|
5
11
|
|
|
6
12
|
export default auditRouter;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { isAllowedSessionHandler, validate } from 'tango-app-api-middleware';
|
|
4
|
-
import { getAuditImageList, userAuditHistory } from '../controllers/auditMetrics.controllers.js';
|
|
5
|
-
import { getAuditImagesValid, userAuditHistoryValid } from '../dtos/auditMetrics.dtos.js';
|
|
4
|
+
import { clientMetrics, getAuditImageList, storeMetrics, userAuditHistory } from '../controllers/auditMetrics.controllers.js';
|
|
5
|
+
import { clientMetricsValid, getAuditImagesValid, storeMetricsValid, userAuditHistoryValid } from '../dtos/auditMetrics.dtos.js';
|
|
6
6
|
|
|
7
7
|
export const auditMetricsRouter = express.Router();
|
|
8
8
|
|
|
9
|
-
auditMetricsRouter.post( '/get-audit-images', validate( getAuditImagesValid ),
|
|
9
|
+
auditMetricsRouter.post( '/get-audit-images', validate( getAuditImagesValid ), getAuditImageList );
|
|
10
10
|
auditMetricsRouter.post( '/user-audit-history', validate( userAuditHistoryValid ), isAllowedSessionHandler, userAuditHistory );
|
|
11
|
-
|
|
11
|
+
auditMetricsRouter.post( '/store-metrics', validate( storeMetricsValid ), isAllowedSessionHandler, storeMetrics );
|
|
12
|
+
auditMetricsRouter.post( '/client-metrics', validate( clientMetricsValid ), isAllowedSessionHandler, clientMetrics );
|
|
12
13
|
export default auditMetricsRouter;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import assignAuditModel from 'tango-api-schema/schema/assignAudit.model.js';
|
|
2
|
+
|
|
3
|
+
export function aggregateAssignAudit( query ) {
|
|
4
|
+
return assignAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
5
|
+
}
|
|
6
|
+
export function updateOneAssignAudit( query, record ) {
|
|
7
|
+
return assignAuditModel.updateOne( query, record );
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import storeAuditModel from 'tango-api-schema/schema/storeAudit.model.js';
|
|
2
|
+
|
|
3
|
+
export function updateOneStoreAudit( query, record ) {
|
|
4
|
+
return storeAuditModel.updateOne( query, record );
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function createStoreAudit( record ) {
|
|
8
|
+
return storeAuditModel.create( record );
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import userAuditModel from 'tango-api-schema/schema/userAudit.model.js';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export function aggregateUserAudit( query ) {
|
|
5
|
+
return userAuditModel.aggregate( query, { collation: { locale: 'en', strength: 2 } } );
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function updateOneUserAudit( query, record ) {
|
|
9
|
+
return userAuditModel.updateOne( query, record );
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function createUserAudit( record ) {
|
|
13
|
+
return userAuditModel.create( record );
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getQueueUrl, logger } from 'tango-app-api-middleware';
|
|
2
|
+
|
|
3
|
+
export async function isExistsQueue( req, res, next ) {
|
|
4
|
+
try {
|
|
5
|
+
const inputData = req.query;
|
|
6
|
+
const isExist = await getQueueUrl( inputData.queueName );
|
|
7
|
+
if ( isExist.statusCode ) {
|
|
8
|
+
return res.sendError( `Queue doesn't Exist`, 400 );
|
|
9
|
+
} else {
|
|
10
|
+
next();
|
|
11
|
+
}
|
|
12
|
+
} catch ( error ) {
|
|
13
|
+
logger.error( { error: error, message: req.query, function: 'isExistsQueue' } );
|
|
14
|
+
return res.sendError( error, 500 );
|
|
15
|
+
}
|
|
16
|
+
}
|