tango-app-api-audit 1.0.53 → 1.0.55
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 -3
- package/package.json +1 -1
- package/src/controllers/audit.controllers.js +1004 -1
- package/src/controllers/auditMetrics.controllers.js +3 -982
- package/src/docs/audit.docs.js +137 -3
- package/src/docs/auditMetrics.docs.js +1 -133
- package/src/dtos/audit.dtos.js +102 -0
- package/src/dtos/auditMetrics.dtos.js +0 -101
- package/src/routes/audit.routes.js +10 -2
- package/src/routes/auditMetrics.routes.js +2 -9
|
@@ -1,995 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { insertOpenSearchData, logger, sendMessageToQueue } from 'tango-app-api-middleware';
|
|
2
|
+
import { updateOneUserAudit } from '../service/userAudit.service.js';
|
|
3
3
|
import mongoose from 'mongoose';
|
|
4
|
-
import {
|
|
4
|
+
import { updateOneStoreAudit } from '../service/storeAudit.service.js';
|
|
5
5
|
import { findOneUser } from '../service/user.service.js';
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import { createAssignAudit } from '../service/assignAudit.service.js';
|
|
8
|
-
import { countDocumentsStore } from '../service/store.service.js';
|
|
9
8
|
import { findOneClient } from '../service/client.service.js';
|
|
10
9
|
import { getAuditFilterData, getAuditImageData, zipDownloadImage } from '../validation/audit.validation.js';
|
|
11
10
|
import { getReauditImg } from './audit.controllers.js';
|
|
12
11
|
// import { listQueue } from 'tango-app-api-middleware/src/utils/aws/sqs.js';
|
|
13
12
|
|
|
14
13
|
|
|
15
|
-
export async function storeMetrics( req, res ) {
|
|
16
|
-
try {
|
|
17
|
-
const inputData = req.body;
|
|
18
|
-
const limit = inputData.limit || 10;
|
|
19
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
20
|
-
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
21
|
-
let filter = [
|
|
22
|
-
{ fileDateISO: { $gte: dateRange.start } },
|
|
23
|
-
{ fileDateISO: { $lte: dateRange.end } },
|
|
24
|
-
];
|
|
25
|
-
if ( inputData.filterByClientId && inputData.filterByClientId?.length > 0 ) {
|
|
26
|
-
filter.push( { clientId: { $in: inputData.filterByClientId } } );
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if ( inputData.filterByStoreId && inputData.filterByStoreId?.length > 0 ) {
|
|
30
|
-
filter.push( { storeId: { $in: inputData.filterByStoreId } } );
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
34
|
-
filter.push( { status: { $in: inputData.filterByStatus } } );
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if ( inputData.filterByType && inputData.filterByType?.length > 0 ) {
|
|
38
|
-
filter.push( { auditType: { $in: inputData.filterByType } } );
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const query = [
|
|
43
|
-
{
|
|
44
|
-
$match: {
|
|
45
|
-
$and: filter,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
{
|
|
50
|
-
$lookup: {
|
|
51
|
-
from: 'stores',
|
|
52
|
-
let: { storeId: '$storeId' },
|
|
53
|
-
pipeline: [
|
|
54
|
-
{
|
|
55
|
-
$match: {
|
|
56
|
-
$expr: {
|
|
57
|
-
$eq: [ '$storeId', '$$storeId' ],
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
$project: {
|
|
63
|
-
_id: 0,
|
|
64
|
-
storeName: 1,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
], as: 'stores',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
$unwind: {
|
|
72
|
-
path: '$stores',
|
|
73
|
-
preserveNullAndEmptyArrays: true,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
$project: {
|
|
78
|
-
_id: 0,
|
|
79
|
-
fileDate: 1,
|
|
80
|
-
storeId: 1,
|
|
81
|
-
storeName: '$store.storeName',
|
|
82
|
-
clientName: '',
|
|
83
|
-
clientId: 1,
|
|
84
|
-
userId: {
|
|
85
|
-
$arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ],
|
|
86
|
-
},
|
|
87
|
-
auditType: 1,
|
|
88
|
-
beforeCount: 1,
|
|
89
|
-
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
90
|
-
accuracy: { $round: [
|
|
91
|
-
{ $divide: [
|
|
92
|
-
{ $multiply: [ { $ifNull: [ '$afterCount', 0 ] }, '$beforeCount' ] }, 100,
|
|
93
|
-
] }, 2,
|
|
94
|
-
],
|
|
95
|
-
|
|
96
|
-
},
|
|
97
|
-
timeSpent: 1,
|
|
98
|
-
status: 1,
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
$lookup: {
|
|
103
|
-
from: 'users',
|
|
104
|
-
let: { userId: '$userId' },
|
|
105
|
-
pipeline: [
|
|
106
|
-
{
|
|
107
|
-
$match: {
|
|
108
|
-
$expr: {
|
|
109
|
-
$eq: [ '$_id', '$$userId' ],
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
$project: {
|
|
115
|
-
_id: 0,
|
|
116
|
-
userName: 1,
|
|
117
|
-
userEmail: '$email',
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
], as: 'users',
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
$unwind: {
|
|
125
|
-
path: '$users',
|
|
126
|
-
preserveNullAndEmptyArrays: true,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
$lookup: {
|
|
131
|
-
from: 'clients',
|
|
132
|
-
let: { clientId: '$clientId' },
|
|
133
|
-
pipeline: [
|
|
134
|
-
{
|
|
135
|
-
$match: {
|
|
136
|
-
$expr: {
|
|
137
|
-
$eq: [ '$clientId', '$$clientId' ],
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
$project: {
|
|
143
|
-
_id: 0,
|
|
144
|
-
clientName: 1,
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
], as: 'client',
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
$unwind: {
|
|
152
|
-
path: '$client',
|
|
153
|
-
preserveNullAndEmptyArrays: true,
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
$project: {
|
|
158
|
-
_id: 0,
|
|
159
|
-
fileDate: 1,
|
|
160
|
-
storeId: 1,
|
|
161
|
-
storeName: '$stores.storeName',
|
|
162
|
-
userName: '$users.userName',
|
|
163
|
-
userEmail: '$users.userEmail',
|
|
164
|
-
clientId: 1,
|
|
165
|
-
clientName: '$client.clientName',
|
|
166
|
-
auditType: 1,
|
|
167
|
-
beforeCount: 1,
|
|
168
|
-
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
169
|
-
accuracy: { $round: [
|
|
170
|
-
{ $divide: [
|
|
171
|
-
{ $multiply: [ { $ifNull: [ '$afterCount', 0 ] }, '$beforeCount' ] }, 100,
|
|
172
|
-
] }, 1,
|
|
173
|
-
],
|
|
174
|
-
|
|
175
|
-
},
|
|
176
|
-
timeSpent: {
|
|
177
|
-
|
|
178
|
-
$cond: [
|
|
179
|
-
{ $lt: [ '$timeSpent', 60 ] }, // Case 1: If less than 60 seconds
|
|
180
|
-
{ $concat: [ { $toString: '$timeSpent' }, ' sec' ] },
|
|
181
|
-
{
|
|
182
|
-
$cond: [
|
|
183
|
-
{ $lt: [ '$timeSpent', 3600 ] }, // Case 2: If less than 60 minutes (3600 seconds)
|
|
184
|
-
{
|
|
185
|
-
$concat: [
|
|
186
|
-
{ $toString: { $round: [ { $divide: [ '$timeSpent', 60 ] }, 1 ] } }, // Convert to minutes
|
|
187
|
-
' min',
|
|
188
|
-
],
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
$concat: [
|
|
192
|
-
{ $toString: { $round: [ { $divide: [ '$timeSpent', 3600 ] }, 1 ] } }, // Convert to hours
|
|
193
|
-
' hr',
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
|
|
200
|
-
},
|
|
201
|
-
status: 1,
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
];
|
|
206
|
-
|
|
207
|
-
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
208
|
-
query.push( {
|
|
209
|
-
$match: {
|
|
210
|
-
$or: [
|
|
211
|
-
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
212
|
-
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
213
|
-
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
214
|
-
{ storeName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
215
|
-
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
216
|
-
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
217
|
-
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
218
|
-
],
|
|
219
|
-
},
|
|
220
|
-
} );
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if ( inputData.sortColumnName ) {
|
|
224
|
-
const sortBy = inputData.sortBy || -1;
|
|
225
|
-
query.push( {
|
|
226
|
-
$sort: { [inputData.sortColumName]: sortBy },
|
|
227
|
-
},
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
const count = await aggregateStoreAudit( query );
|
|
231
|
-
|
|
232
|
-
if ( count.length == 0 ) {
|
|
233
|
-
return res.sendError( 'No data Found', 204 );
|
|
234
|
-
}
|
|
235
|
-
if ( !inputData.isExport ) {
|
|
236
|
-
query.push( {
|
|
237
|
-
$skip: offset,
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
$limit: limit,
|
|
241
|
-
} );
|
|
242
|
-
} else {
|
|
243
|
-
query.push( { $limit: 10000 } );
|
|
244
|
-
}
|
|
245
|
-
const result = await aggregateStoreAudit( query );
|
|
246
|
-
if ( inputData.isExport ) {
|
|
247
|
-
const exportdata = [];
|
|
248
|
-
result.forEach( ( element ) => {
|
|
249
|
-
exportdata.push( {
|
|
250
|
-
'File Date': element.fileDate,
|
|
251
|
-
'Store Id': element.storeId,
|
|
252
|
-
'Store Name': element.storeName,
|
|
253
|
-
'Client Id': element.clientId,
|
|
254
|
-
'Client Name': element.clientName,
|
|
255
|
-
'User Name': element.userName,
|
|
256
|
-
'User Email': element.userEmail,
|
|
257
|
-
'Audit Type': element.auditType,
|
|
258
|
-
'Accuracy': element.accuracy,
|
|
259
|
-
'Time Spent': element.timeSpent,
|
|
260
|
-
'Status': element.status,
|
|
261
|
-
} );
|
|
262
|
-
} );
|
|
263
|
-
await download( exportdata, res );
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
return res.sendSuccess( { result: result, count: count.length } );
|
|
267
|
-
} catch ( error ) {
|
|
268
|
-
const err = error.message || 'Internal Server Error';
|
|
269
|
-
logger.error( { error: error, data: req.body, function: 'storeMetrics' } );
|
|
270
|
-
return res.sendError( err, 500 );
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
export async function userMetrics( req, res ) {
|
|
276
|
-
try {
|
|
277
|
-
const inputData = req.body;
|
|
278
|
-
const limit = inputData.limit || 10;
|
|
279
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
280
|
-
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
281
|
-
let filter = [];
|
|
282
|
-
if ( inputData.fileType == 'auditedDate' ) {
|
|
283
|
-
filter.push(
|
|
284
|
-
{ updatedAt: { $gte: dateRange.start } },
|
|
285
|
-
{ updatedAt: { $lte: dateRange.end } },
|
|
286
|
-
|
|
287
|
-
);
|
|
288
|
-
} else {
|
|
289
|
-
filter.push(
|
|
290
|
-
{ fileDateISO: { $gte: dateRange.start } },
|
|
291
|
-
{ fileDateISO: { $lte: dateRange.end } },
|
|
292
|
-
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
if ( inputData?.filterByAuditType?.length> 0 ) {
|
|
296
|
-
filter.push(
|
|
297
|
-
{ moduleType: { $in: inputData.filterByAuditType } },
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
301
|
-
filter.push(
|
|
302
|
-
{ auditStatus: { $in: inputData.filterByStatus } },
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
if ( inputData?.filterByUser?.length> 0 ) {
|
|
306
|
-
const temp = inputData.filterByUser.map( ( item ) => new mongoose.Types.ObjectId( item ) );
|
|
307
|
-
logger.info( { temp: temp } );
|
|
308
|
-
filter.push(
|
|
309
|
-
{ userId: { $in: temp } },
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const query = [
|
|
314
|
-
{
|
|
315
|
-
$match: {
|
|
316
|
-
$and: filter,
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
$project: {
|
|
321
|
-
userId: 1,
|
|
322
|
-
fileDate: 1,
|
|
323
|
-
startTime: 1,
|
|
324
|
-
endTime: 1,
|
|
325
|
-
totalCompletedFiles: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
326
|
-
beforeCount: 1,
|
|
327
|
-
afterCount: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, '$afterCount', 0 ] },
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
$group: {
|
|
332
|
-
_id: { userId: '$userId', fileDate: '$fileDate' },
|
|
333
|
-
userId: { $first: '$userId' },
|
|
334
|
-
fileDate: { $first: '$fileDate' },
|
|
335
|
-
totalCompletedFiles: { $sum: '$totalCompletedFiles' },
|
|
336
|
-
beforeCount: { $sum: '$beforeCount' },
|
|
337
|
-
afterCount: { $sum: '$afterCount' },
|
|
338
|
-
checkIntime: { $first: '$startTime' },
|
|
339
|
-
checkOutTime: { $last: '$endTime' },
|
|
340
|
-
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
{
|
|
344
|
-
$project: {
|
|
345
|
-
_id: 0,
|
|
346
|
-
userId: 1,
|
|
347
|
-
fileDate: 1,
|
|
348
|
-
totalCompletedFiles: 1,
|
|
349
|
-
beforeCount: 1,
|
|
350
|
-
afterCount: 1,
|
|
351
|
-
mappingPerc: { $round: [
|
|
352
|
-
{ $multiply: [
|
|
353
|
-
{ $divide: [ '$afterCount', '$beforeCount' ] }, 100,
|
|
354
|
-
] }, 2,
|
|
355
|
-
] },
|
|
356
|
-
checkIntime: 1,
|
|
357
|
-
checkOutTime: 1,
|
|
358
|
-
differenceInSeconds: {
|
|
359
|
-
$divide: [ { $subtract: [ '$checkOutTime', '$checkIntime' ] }, 1000 ],
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
{
|
|
364
|
-
$project: {
|
|
365
|
-
userId: 1,
|
|
366
|
-
fileDate: 1,
|
|
367
|
-
totalCompletedFiles: 1,
|
|
368
|
-
beforeCount: 1,
|
|
369
|
-
afterCount: 1,
|
|
370
|
-
checkIntime: 1,
|
|
371
|
-
checkOutTime: 1,
|
|
372
|
-
mappingPerc: 1,
|
|
373
|
-
hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
|
|
374
|
-
minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
|
|
375
|
-
seconds: { $mod: [ '$differenceInSeconds', 60 ] },
|
|
376
|
-
},
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
$project: {
|
|
380
|
-
event: 1,
|
|
381
|
-
userId: 1,
|
|
382
|
-
fileDate: 1,
|
|
383
|
-
totalCompletedFiles: 1,
|
|
384
|
-
beforeCount: 1,
|
|
385
|
-
afterCount: 1,
|
|
386
|
-
checkIntime: 1,
|
|
387
|
-
checkOutTime: 1,
|
|
388
|
-
hours: {
|
|
389
|
-
$cond: {
|
|
390
|
-
if: { $lt: [ '$hours', 10 ] },
|
|
391
|
-
then: { $concat: [ '0', { $toString: { $round: [ '$hours', 0 ] } } ] },
|
|
392
|
-
else: { $toString: { $round: [ '$hours', 0 ] } },
|
|
393
|
-
},
|
|
394
|
-
},
|
|
395
|
-
minutes: {
|
|
396
|
-
$cond: {
|
|
397
|
-
if: { $lt: [ '$minutes', 10 ] },
|
|
398
|
-
then: { $concat: [ '0', { $toString: { $round: [ '$minutes', 0 ] } } ] },
|
|
399
|
-
else: { $toString: { $round: [ '$minutes', 0 ] } },
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
seconds: {
|
|
403
|
-
$cond: {
|
|
404
|
-
if: { $lt: [ '$seconds', 10 ] },
|
|
405
|
-
then: { $concat: [ '0', { $toString: { $round: [ '$seconds', 0 ] } } ] },
|
|
406
|
-
else: { $toString: { $round: [ '$seconds', 0 ] } },
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
},
|
|
411
|
-
},
|
|
412
|
-
{
|
|
413
|
-
$project: {
|
|
414
|
-
event: 1,
|
|
415
|
-
userId: 1,
|
|
416
|
-
fileDate: 1,
|
|
417
|
-
totalCompletedFiles: 1,
|
|
418
|
-
beforeCount: 1,
|
|
419
|
-
afterCount: 1,
|
|
420
|
-
checkIntime: 1,
|
|
421
|
-
zoneName: 1,
|
|
422
|
-
checkOutTime: 1,
|
|
423
|
-
workingHours: {
|
|
424
|
-
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
425
|
-
},
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
$lookup: {
|
|
430
|
-
from: 'users',
|
|
431
|
-
let: { userId: '$userId' },
|
|
432
|
-
pipeline: [
|
|
433
|
-
{
|
|
434
|
-
$match: {
|
|
435
|
-
$expr: {
|
|
436
|
-
$eq: [ '$_id', '$$userId' ],
|
|
437
|
-
},
|
|
438
|
-
},
|
|
439
|
-
},
|
|
440
|
-
{
|
|
441
|
-
$project: {
|
|
442
|
-
_id: 0,
|
|
443
|
-
userName: 1,
|
|
444
|
-
},
|
|
445
|
-
},
|
|
446
|
-
], as: 'userInfo',
|
|
447
|
-
},
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
$unwind: {
|
|
451
|
-
path: '$userInfo', preserveNullAndEmptyArrays: true,
|
|
452
|
-
},
|
|
453
|
-
},
|
|
454
|
-
{
|
|
455
|
-
$project: {
|
|
456
|
-
event: 1,
|
|
457
|
-
userName: '$userInfo.userName',
|
|
458
|
-
userId: 1,
|
|
459
|
-
fileDate: 1,
|
|
460
|
-
totalCompletedFiles: 1,
|
|
461
|
-
beforeCount: 1,
|
|
462
|
-
afterCount: 1,
|
|
463
|
-
checkIntime: {
|
|
464
|
-
$dateToString: {
|
|
465
|
-
format: '%Y-%m-%d %H:%M:%S',
|
|
466
|
-
date: '$checkIntime',
|
|
467
|
-
timezone: 'Asia/Kolkata',
|
|
468
|
-
},
|
|
469
|
-
},
|
|
470
|
-
checkOutTime: {
|
|
471
|
-
$dateToString: {
|
|
472
|
-
format: '%Y-%m-%d %H:%M:%S',
|
|
473
|
-
date: '$checkOutTime',
|
|
474
|
-
timezone: 'Asia/Kolkata',
|
|
475
|
-
},
|
|
476
|
-
},
|
|
477
|
-
workingHours: 1,
|
|
478
|
-
},
|
|
479
|
-
},
|
|
480
|
-
];
|
|
481
|
-
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
482
|
-
query.push( {
|
|
483
|
-
$match: {
|
|
484
|
-
$or: [
|
|
485
|
-
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
486
|
-
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
487
|
-
],
|
|
488
|
-
|
|
489
|
-
},
|
|
490
|
-
} );
|
|
491
|
-
}
|
|
492
|
-
if ( inputData.sortColumnName ) {
|
|
493
|
-
const sortBy = inputData.sortBy || -1;
|
|
494
|
-
query.push( {
|
|
495
|
-
$sort: { [inputData.sortColumName]: sortBy },
|
|
496
|
-
},
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
const count = await aggregateUserAudit( query );
|
|
501
|
-
if ( count.length == 0 ) {
|
|
502
|
-
return res.sendError( 'No Data Found', 204 );
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
query.push(
|
|
506
|
-
{ $skip: offset },
|
|
507
|
-
{ $limit: limit },
|
|
508
|
-
);
|
|
509
|
-
if ( inputData.isExport ) {
|
|
510
|
-
query.push(
|
|
511
|
-
{
|
|
512
|
-
$project: {
|
|
513
|
-
'_id': 0,
|
|
514
|
-
'File Date': '$fileDate',
|
|
515
|
-
'User Name': '$userName',
|
|
516
|
-
'User Id': '$userId',
|
|
517
|
-
'Total Completed Files Count': '$totalCompletedFiles',
|
|
518
|
-
'Total efore Count': '$beforeCount',
|
|
519
|
-
'Total After Count': '$afterCount',
|
|
520
|
-
'check Intime': '$checkIntime',
|
|
521
|
-
'check OutTime': '$checkOutTime',
|
|
522
|
-
'working Hours': '$workingHours',
|
|
523
|
-
},
|
|
524
|
-
},
|
|
525
|
-
);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
const result = await aggregateUserAudit( query );
|
|
530
|
-
if ( inputData.isExport ) {
|
|
531
|
-
await download( result, res );
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
return res.sendSuccess( { result: result, count: count.length } );
|
|
535
|
-
} catch ( error ) {
|
|
536
|
-
const err = error.error || 'Internal Server Error';
|
|
537
|
-
logger.info( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
538
|
-
return res.sendError( err, 500 );
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
export async function overViewCard( req, res ) {
|
|
543
|
-
try {
|
|
544
|
-
const inputData = req.body;
|
|
545
|
-
const temp = {
|
|
546
|
-
totalCount: 0,
|
|
547
|
-
auditFileCount: 0,
|
|
548
|
-
ReAuditFileCount: 0,
|
|
549
|
-
inprogressCount: 0,
|
|
550
|
-
completedCount: 0,
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
554
|
-
let filters =[
|
|
555
|
-
{ fileDateISO: { $gte: dateRange.start } },
|
|
556
|
-
{ fileDateISO: { $lte: dateRange.end } },
|
|
557
|
-
];
|
|
558
|
-
if ( inputData.clientId.length > 0 ) {
|
|
559
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
560
|
-
}
|
|
561
|
-
const query =[
|
|
562
|
-
{
|
|
563
|
-
$match: {
|
|
564
|
-
$and: filters,
|
|
565
|
-
},
|
|
566
|
-
|
|
567
|
-
},
|
|
568
|
-
{
|
|
569
|
-
$project: {
|
|
570
|
-
auditFileCount: {
|
|
571
|
-
$cond: [
|
|
572
|
-
{ $eq: [ '$auditType', 'Audit' ] }, 1, 0,
|
|
573
|
-
],
|
|
574
|
-
},
|
|
575
|
-
ReAuditFileCount: {
|
|
576
|
-
$cond: [
|
|
577
|
-
{ $eq: [ '$auditType', 'ReAudit' ] }, 1, 0,
|
|
578
|
-
],
|
|
579
|
-
},
|
|
580
|
-
inprogressCount: {
|
|
581
|
-
$cond: [
|
|
582
|
-
{ $ne: [ '$status', 'completed' ] }, 1, 0,
|
|
583
|
-
],
|
|
584
|
-
},
|
|
585
|
-
completedCount: {
|
|
586
|
-
$cond: [
|
|
587
|
-
{ $eq: [ '$status', 'completed' ] }, 1, 0,
|
|
588
|
-
],
|
|
589
|
-
},
|
|
590
|
-
},
|
|
591
|
-
},
|
|
592
|
-
{
|
|
593
|
-
$group: {
|
|
594
|
-
_id: { fileDate: '$fileDate', clientId: '$clientId' },
|
|
595
|
-
totalCount: { $sum: 1 },
|
|
596
|
-
auditFileCount: { $sum: '$auditFileCount' },
|
|
597
|
-
ReAuditFileCount: { $sum: '$ReAuditFileCount' },
|
|
598
|
-
inprogressCount: { $sum: '$inprogressCount' },
|
|
599
|
-
completedCount: { $sum: '$completedCount' },
|
|
600
|
-
|
|
601
|
-
},
|
|
602
|
-
},
|
|
603
|
-
{
|
|
604
|
-
$project: {
|
|
605
|
-
_id: 0,
|
|
606
|
-
totalCount: 1,
|
|
607
|
-
auditFileCount: 1,
|
|
608
|
-
ReAuditFileCount: 1,
|
|
609
|
-
inprogressCount: 1,
|
|
610
|
-
completedCount: 1,
|
|
611
|
-
},
|
|
612
|
-
},
|
|
613
|
-
];
|
|
614
|
-
const result = await aggregateStoreAudit( query );
|
|
615
|
-
logger.info( { result: result } );
|
|
616
|
-
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
617
|
-
} catch ( error ) {
|
|
618
|
-
const err = error.message || 'Internal Server Error';
|
|
619
|
-
logger.error( { error: error, message: req.body, function: 'overViewCard' } );
|
|
620
|
-
return res.sendError( err, 500 );
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
export async function summarySplit( req, res ) {
|
|
625
|
-
try {
|
|
626
|
-
const inputData = req.body;
|
|
627
|
-
const temp = {
|
|
628
|
-
totalInprogress: 0,
|
|
629
|
-
auditInprogress: 0,
|
|
630
|
-
reAuditInprogress: 0,
|
|
631
|
-
draft: 0,
|
|
632
|
-
assigned: 0,
|
|
633
|
-
auditCompleted: 0,
|
|
634
|
-
reAuditCompleted: 0,
|
|
635
|
-
completedCount: 0,
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
639
|
-
let filters =[
|
|
640
|
-
{ fileDateISO: { $gte: dateRange.start } },
|
|
641
|
-
{ fileDateISO: { $lte: dateRange.end } },
|
|
642
|
-
];
|
|
643
|
-
if ( inputData.clientId.length > 0 ) {
|
|
644
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
645
|
-
}
|
|
646
|
-
const query =[
|
|
647
|
-
{
|
|
648
|
-
$match: {
|
|
649
|
-
$and: filters,
|
|
650
|
-
},
|
|
651
|
-
|
|
652
|
-
},
|
|
653
|
-
{
|
|
654
|
-
$project: {
|
|
655
|
-
auditInprogress: {
|
|
656
|
-
$cond: [
|
|
657
|
-
{ $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
|
|
658
|
-
],
|
|
659
|
-
},
|
|
660
|
-
reAuditInprogress: {
|
|
661
|
-
$cond: [
|
|
662
|
-
{ $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'inprogress' ] } ] }, 1, 0,
|
|
663
|
-
],
|
|
664
|
-
},
|
|
665
|
-
draft: {
|
|
666
|
-
$cond: [
|
|
667
|
-
{ $ne: [ '$status', 'drafted' ] }, 1, 0,
|
|
668
|
-
],
|
|
669
|
-
},
|
|
670
|
-
assigned: {
|
|
671
|
-
$cond: [
|
|
672
|
-
{ $ne: [ '$status', 'assigned' ] }, 1, 0,
|
|
673
|
-
],
|
|
674
|
-
},
|
|
675
|
-
completedCount: {
|
|
676
|
-
$cond: [
|
|
677
|
-
{ $eq: [ '$status', 'completed' ] }, 1, 0,
|
|
678
|
-
],
|
|
679
|
-
},
|
|
680
|
-
reAuditCompleted: {
|
|
681
|
-
$cond: [
|
|
682
|
-
{ $and: [ { $eq: [ '$auditType', 'ReAudit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
|
|
683
|
-
],
|
|
684
|
-
},
|
|
685
|
-
auditCompleted: {
|
|
686
|
-
$cond: [
|
|
687
|
-
{ $and: [ { $eq: [ '$auditType', 'Audit' ] }, { $eq: [ '$status', 'completed' ] } ] }, 1, 0,
|
|
688
|
-
],
|
|
689
|
-
},
|
|
690
|
-
},
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
$group: {
|
|
694
|
-
_id: { fileDate: '$fileDate', clientId: '$clientId' },
|
|
695
|
-
totalInprogress: { $sum: 1 },
|
|
696
|
-
auditInprogress: { $sum: '$auditInprogress' },
|
|
697
|
-
reAuditInprogress: { $sum: '$reAuditInprogress' },
|
|
698
|
-
draft: { $sum: '$draft' },
|
|
699
|
-
assigned: { $sum: 'assigned' },
|
|
700
|
-
completedCount: { $sum: '$completedCount' },
|
|
701
|
-
reAuditCompleted: { $sum: '$reAuditCompleted' },
|
|
702
|
-
auditCompleted: { $sum: '$auditCompleted' },
|
|
703
|
-
completedCount: { $sum: '$completedCount' },
|
|
704
|
-
|
|
705
|
-
},
|
|
706
|
-
},
|
|
707
|
-
{
|
|
708
|
-
$project: {
|
|
709
|
-
_id: 0,
|
|
710
|
-
totalInprogress: 1,
|
|
711
|
-
auditInprogress: 1,
|
|
712
|
-
reAuditInprogress: 1,
|
|
713
|
-
draft: 1,
|
|
714
|
-
assigned: 1,
|
|
715
|
-
completedCount: 1,
|
|
716
|
-
reAuditCompleted: 1,
|
|
717
|
-
auditCompleted: 1,
|
|
718
|
-
|
|
719
|
-
},
|
|
720
|
-
},
|
|
721
|
-
];
|
|
722
|
-
const result = await aggregateStoreAudit( query );
|
|
723
|
-
logger.info( { result: result } );
|
|
724
|
-
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
725
|
-
} catch ( error ) {
|
|
726
|
-
const err = error.message || 'Internal Server Error';
|
|
727
|
-
logger.error( { error: error, message: req.body, function: 'summarySplit' } );
|
|
728
|
-
return res.sendError( err, 500 );
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
export async function overViewTable( req, res ) {
|
|
733
|
-
try {
|
|
734
|
-
const inputData = req.body;
|
|
735
|
-
const limit = inputData.limit || 10;
|
|
736
|
-
const offset = inputData.offset ? ( inputData.offset - 1 ) * limit : 0;
|
|
737
|
-
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
738
|
-
let filters =[
|
|
739
|
-
{ fileDateISO: { $gte: dateRange.start } },
|
|
740
|
-
{ fileDateISO: { $lte: dateRange.end } },
|
|
741
|
-
{ auditStatus: { $in: inputData.filterByStatus } },
|
|
742
|
-
{ auditType: { $in: inputData.filterByType } },
|
|
743
|
-
|
|
744
|
-
];
|
|
745
|
-
if ( inputData.clientId.length > 0 ) {
|
|
746
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
747
|
-
}
|
|
748
|
-
if ( inputData.filterByAuditType.length > 0 ) {
|
|
749
|
-
filters.push( { moduleType: { $in: inputData.filterByAuditType } } );
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
const query =[
|
|
753
|
-
{
|
|
754
|
-
$match: {
|
|
755
|
-
$and: filters,
|
|
756
|
-
},
|
|
757
|
-
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
$project: {
|
|
761
|
-
_id: 0,
|
|
762
|
-
storeId: 1,
|
|
763
|
-
fileDate: 1,
|
|
764
|
-
beforeCount: 1,
|
|
765
|
-
startTime: 1,
|
|
766
|
-
auditType: 1,
|
|
767
|
-
auditStatus: 1,
|
|
768
|
-
userId: 1,
|
|
769
|
-
},
|
|
770
|
-
},
|
|
771
|
-
{
|
|
772
|
-
$lookup: {
|
|
773
|
-
from: 'users',
|
|
774
|
-
let: { userId: '$userId' },
|
|
775
|
-
pipeline: [
|
|
776
|
-
{
|
|
777
|
-
$match: {
|
|
778
|
-
$expr: {
|
|
779
|
-
$eq: [ '$_id', '$$userId' ],
|
|
780
|
-
},
|
|
781
|
-
},
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
$project: {
|
|
785
|
-
userName: 1,
|
|
786
|
-
userEmail: '$email',
|
|
787
|
-
},
|
|
788
|
-
},
|
|
789
|
-
], as: 'user',
|
|
790
|
-
},
|
|
791
|
-
},
|
|
792
|
-
{
|
|
793
|
-
$unwind: {
|
|
794
|
-
path: '$user',
|
|
795
|
-
preserveNullAndEmptyArrays: true,
|
|
796
|
-
},
|
|
797
|
-
},
|
|
798
|
-
{
|
|
799
|
-
$project: {
|
|
800
|
-
storeId: 1,
|
|
801
|
-
fileDate: 1,
|
|
802
|
-
beforeCount: 1,
|
|
803
|
-
startTime: 1,
|
|
804
|
-
auditType: 1,
|
|
805
|
-
auditStatus: 1,
|
|
806
|
-
userName: '$user.userName',
|
|
807
|
-
userEmail: '$user.userEmail',
|
|
808
|
-
|
|
809
|
-
},
|
|
810
|
-
},
|
|
811
|
-
];
|
|
812
|
-
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
813
|
-
query.push( {
|
|
814
|
-
$match: {
|
|
815
|
-
$or: [
|
|
816
|
-
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
817
|
-
{ fileDate: { $regex: inputData.searchValue, $options: 'i' } },
|
|
818
|
-
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
819
|
-
{ auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
|
|
820
|
-
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
821
|
-
{ userEmail: { $regex: inputData.searchValue, $options: 'i' } },
|
|
822
|
-
],
|
|
823
|
-
|
|
824
|
-
},
|
|
825
|
-
} );
|
|
826
|
-
}
|
|
827
|
-
if ( inputData.sortColumnName ) {
|
|
828
|
-
const sortBy = inputData.sortBy || -1;
|
|
829
|
-
query.push( {
|
|
830
|
-
$sort: { [inputData.sortColumName]: sortBy },
|
|
831
|
-
},
|
|
832
|
-
);
|
|
833
|
-
}
|
|
834
|
-
const count = await aggregateUserAudit( query );
|
|
835
|
-
if ( count.length == 0 ) {
|
|
836
|
-
return res.sendError( 'No Data Found', 204 );
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
if ( inputData.isExport ) {
|
|
840
|
-
query.push( { limit: 10000 } );
|
|
841
|
-
} else {
|
|
842
|
-
query.push( {
|
|
843
|
-
$skip: offset,
|
|
844
|
-
},
|
|
845
|
-
{
|
|
846
|
-
$limit: limit,
|
|
847
|
-
} );
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
const result = await aggregateUserAudit( query );
|
|
851
|
-
if ( inputData.isExport ) {
|
|
852
|
-
const exportdata = [];
|
|
853
|
-
result.forEach( ( element ) => {
|
|
854
|
-
exportdata.push( {
|
|
855
|
-
'Store Id': element.storeId,
|
|
856
|
-
'File Date': element.fileDtae,
|
|
857
|
-
'Type': element.audittype,
|
|
858
|
-
'Before Count': element.beforeCount,
|
|
859
|
-
'Start Time': element.startTime,
|
|
860
|
-
'User Name': element.userName,
|
|
861
|
-
'User Email': element.userEmail,
|
|
862
|
-
'Status': element.auditStatus,
|
|
863
|
-
'Audit Type': element.moduleType,
|
|
864
|
-
} );
|
|
865
|
-
} );
|
|
866
|
-
await download( exportdata, res );
|
|
867
|
-
return;
|
|
868
|
-
}
|
|
869
|
-
return res.sendSuccess( { result: result, count: count.length } );
|
|
870
|
-
} catch ( error ) {
|
|
871
|
-
const err = error.message || 'Internal Server Error';
|
|
872
|
-
logger.error( { error: error, message: req.body, function: 'summarySplit' } );
|
|
873
|
-
return res.sendError( err, 500 );
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
export async function overAllAuditSummary( req, res ) {
|
|
878
|
-
try {
|
|
879
|
-
const inputData = req.body;
|
|
880
|
-
let temp = {
|
|
881
|
-
installedStores: 0,
|
|
882
|
-
auditStores: 0,
|
|
883
|
-
inprogreseStores: 0,
|
|
884
|
-
completedStores: 0,
|
|
885
|
-
auditInprogress: 0,
|
|
886
|
-
reAuditInprogress: 0,
|
|
887
|
-
draft: 0,
|
|
888
|
-
assigned: 0,
|
|
889
|
-
notAssigned: 0,
|
|
890
|
-
auditCompleted: 0,
|
|
891
|
-
reAuditCompleted: 0,
|
|
892
|
-
|
|
893
|
-
};
|
|
894
|
-
const dateRange = await getUTC( new Date( inputData.fromDate ), new Date( inputData.toDate ) );
|
|
895
|
-
let filters =[
|
|
896
|
-
{ fileDateISO: { $gte: dateRange.start } },
|
|
897
|
-
{ fileDateISO: { $lte: dateRange.end } },
|
|
898
|
-
{ moduleType: { $eq: inputData.moduleType },
|
|
899
|
-
},
|
|
900
|
-
];
|
|
901
|
-
if ( inputData.clientId.length > 0 ) {
|
|
902
|
-
filters.push( { clientId: { $in: inputData.clientId } } );
|
|
903
|
-
}
|
|
904
|
-
const storeQuery = inputData.clientId.length? { 'edge.firstFile': true, 'clientId': { $in: inputData. clientId } } : { 'edge.firstFile': true };
|
|
905
|
-
temp.installedStores = await countDocumentsStore( storeQuery );
|
|
906
|
-
// const auditClientDataQuery =[
|
|
907
|
-
// {
|
|
908
|
-
// $match: {
|
|
909
|
-
// $and: filters,
|
|
910
|
-
// },
|
|
911
|
-
|
|
912
|
-
// },
|
|
913
|
-
// {
|
|
914
|
-
// $group: {
|
|
915
|
-
// _id: null,
|
|
916
|
-
// totalFilesCount: { $sum: '$totalFilesCount' },
|
|
917
|
-
// },
|
|
918
|
-
// },
|
|
919
|
-
// ];
|
|
920
|
-
const auditClientData = [];// await aggregateAuditClientData( auditClientDataQuery );
|
|
921
|
-
if ( auditClientData.length >0 ) {
|
|
922
|
-
temp.auditStores = auditClientData[0].totalFilesCount;
|
|
923
|
-
}
|
|
924
|
-
const storeAuditQuery =[
|
|
925
|
-
{
|
|
926
|
-
$match: {
|
|
927
|
-
$and: filters,
|
|
928
|
-
},
|
|
929
|
-
|
|
930
|
-
},
|
|
931
|
-
{
|
|
932
|
-
$project: {
|
|
933
|
-
completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
|
|
934
|
-
auditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
|
|
935
|
-
reAuditInprogress: { $cond: [ { $and: [ { $in: [ '$status', [ 'inprogress' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
|
|
936
|
-
draft: { $cond: [ { $eq: [ '$status', 'drafted' ] }, 1, 0 ] },
|
|
937
|
-
assigned: { $cond: [ { $eq: [ '$status', 'drafted' ] }, 1, 0 ] },
|
|
938
|
-
exceptNoAssigned: { $cond: [ { $in: [ '$status', [ 'skipped', 'not_assign' ] ] }, 1, 0 ] },
|
|
939
|
-
auditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'Audit' ] } ] }, 1, 0 ] },
|
|
940
|
-
reAuditCompleted: { $cond: [ { $and: [ { $in: [ '$status', [ 'completed' ] ] }, { $eq: [ '$auditType', 'ReAudit' ] } ] }, 1, 0 ] },
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
},
|
|
944
|
-
},
|
|
945
|
-
{
|
|
946
|
-
$group: {
|
|
947
|
-
_id: null,
|
|
948
|
-
completedStores: { $sum: '$completedStores' },
|
|
949
|
-
auditInprogress: { $sum: '$auditInprogress' },
|
|
950
|
-
reAuditInprogress: { $sum: '$reAuditInprogress' },
|
|
951
|
-
draft: { $sum: '$draft' },
|
|
952
|
-
assigned: { $sum: '$assigned' },
|
|
953
|
-
exceptNoAssigned: { $sum: '$exceptNoAssigned' },
|
|
954
|
-
auditCompleted: { $sum: '$auditCompleted' },
|
|
955
|
-
reAuditCompleted: { $sum: '$reAuditCompleted' },
|
|
956
|
-
},
|
|
957
|
-
},
|
|
958
|
-
{
|
|
959
|
-
$project: {
|
|
960
|
-
completedStores: 1,
|
|
961
|
-
inprogressStores: { $subtract: [ temp.auditStores, '$completedStores' ] },
|
|
962
|
-
auditInprogress: 1,
|
|
963
|
-
reAuditInprogress: 1,
|
|
964
|
-
draft: 1,
|
|
965
|
-
assigned: 1,
|
|
966
|
-
exceptNoAssigned: { $subtract: [ temp.auditStores, '$exceptNoAssigned' ] },
|
|
967
|
-
auditCompleted: 1,
|
|
968
|
-
reAuditCompleted: 1,
|
|
969
|
-
},
|
|
970
|
-
},
|
|
971
|
-
];
|
|
972
|
-
const storeAudit = await aggregateStoreAudit( storeAuditQuery );
|
|
973
|
-
if ( storeAudit.length > 0 ) {
|
|
974
|
-
temp.inprogreseStores= storeAudit[0].inprogreseStores;
|
|
975
|
-
temp.completedStores = storeAudit[0].completedStores;
|
|
976
|
-
temp.auditInprogress = storeAudit[0].auditInprogress;
|
|
977
|
-
temp.reAuditInprogress = storeAudit[0].reAuditInprogress;
|
|
978
|
-
temp.draft = storeAudit[0].draft;
|
|
979
|
-
temp.assigned = storeAudit[0].assigned;
|
|
980
|
-
temp.notAssigned = storeAudit[0].exceptNoAssigned;
|
|
981
|
-
temp.auditCompleted = storeAudit[0].auditCompleted;
|
|
982
|
-
temp.reAuditCompleted = storeAudit[0].reAuditCompleted;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
return res.sendSuccess( { result: temp } );
|
|
986
|
-
} catch ( error ) {
|
|
987
|
-
const err = error.message || 'Internal Server Error';
|
|
988
|
-
logger.error( { error: error, message: req.body, function: 'summarySplit' } );
|
|
989
|
-
return res.sendError( err, 500 );
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
|
|
993
14
|
export async function reTrigger( req, res ) {
|
|
994
15
|
try {
|
|
995
16
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|