tango-app-api-audit 3.4.19 → 3.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/controllers/audit.controllers.js +44 -11
- package/src/controllers/traxAudit.controllers.js +450 -1062
- package/src/docs/traxAudit.docs.js +2 -2
- package/src/dtos/traxAudit.dtos.js +5 -3
- package/src/routes/traxAudit.routes.js +2 -2
- package/src/service/auditUsers.service.js +8 -0
- package/src/validation/traxAuditValidation.js +5 -2
|
@@ -17,454 +17,6 @@ import {
|
|
|
17
17
|
findOneUserEmpDetection,
|
|
18
18
|
} from '../service/userEmpDetection.service.js';
|
|
19
19
|
import { updateOneEmpDetectionOutput } from '../service/empDetectionOutput.service.js';
|
|
20
|
-
// export async function getDetectionAuditFile( req, res ) {
|
|
21
|
-
// try {
|
|
22
|
-
// const bucket = JSON.parse( process.env.BUCKET );
|
|
23
|
-
// const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
24
|
-
// const inputData = req.query;
|
|
25
|
-
// const previousDate = new Date( new Date() - 1 );
|
|
26
|
-
// const data = await getDate( previousDate, new Date() );
|
|
27
|
-
// logger.info( { data: data, function: 'data', newDate: new Date() } );
|
|
28
|
-
// logger.info( { userId: req.user._id, queueName: inputData.queueName, moduleType: inputData.moduleType } );
|
|
29
|
-
// const start = data.start;
|
|
30
|
-
// const end = data.end;
|
|
31
|
-
// const fetchData = {};
|
|
32
|
-
// let msg = {};
|
|
33
|
-
// const userQuery = [
|
|
34
|
-
// {
|
|
35
|
-
// $match: {
|
|
36
|
-
// $and: [
|
|
37
|
-
// { userId: req.user._id },
|
|
38
|
-
// { queueName: inputData.queueName },
|
|
39
|
-
// { auditStatus: { $nin: [ 'completed', 'skipped' ] } },
|
|
40
|
-
// { createdAt: { $gte: start } },
|
|
41
|
-
// { createdAt: { $lte: end } },
|
|
42
|
-
// { moduleType: inputData.moduleType },
|
|
43
|
-
// ],
|
|
44
|
-
// },
|
|
45
|
-
// },
|
|
46
|
-
// {
|
|
47
|
-
// $sort: { createdAt: -1 },
|
|
48
|
-
// },
|
|
49
|
-
// {
|
|
50
|
-
// $limit: 1,
|
|
51
|
-
// },
|
|
52
|
-
// ];
|
|
53
|
-
|
|
54
|
-
// const userDetails = await aggregateUserEmpDetection( userQuery );
|
|
55
|
-
// logger.info( { userDetails: userDetails, function: 'userDetails' } );
|
|
56
|
-
// const auditStatus =
|
|
57
|
-
// userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
58
|
-
// switch ( auditStatus ) {
|
|
59
|
-
// case null:
|
|
60
|
-
// const query = [
|
|
61
|
-
// {
|
|
62
|
-
// $match: {
|
|
63
|
-
// $and: [
|
|
64
|
-
// { userId: { $eq: req.user._id } },
|
|
65
|
-
// { isCompleted: { $eq: false } },
|
|
66
|
-
// { queueName: inputData.queueName },
|
|
67
|
-
// { moduleType: inputData.moduleType },
|
|
68
|
-
// ],
|
|
69
|
-
// },
|
|
70
|
-
// },
|
|
71
|
-
// ];
|
|
72
|
-
// const userAssign = await aggregateAssignAudit( query );
|
|
73
|
-
// if ( userAssign.length > 0 ) {
|
|
74
|
-
// logger.info( 'Hit in user assign', { inputData } );
|
|
75
|
-
// userAssign[0].auditType == 'Audit' ?
|
|
76
|
-
// ( msg = {
|
|
77
|
-
// store_id: userAssign[0].storeId,
|
|
78
|
-
// curr_date: userAssign[0].fileDate,
|
|
79
|
-
// total_count: userAssign[0].fileCount,
|
|
80
|
-
// zone_id: userAssign[0].zoneName,
|
|
81
|
-
// } ) :
|
|
82
|
-
// ( msg = {
|
|
83
|
-
// store_id: userAssign[0].storeId,
|
|
84
|
-
// curr_date: userAssign[0].fileDate,
|
|
85
|
-
// audit_type: userAssign[0].auditType,
|
|
86
|
-
// total_count: userAssign[0].fileCount,
|
|
87
|
-
// zone_id: userAssign[0].zoneName,
|
|
88
|
-
// } );
|
|
89
|
-
// await updateOneAssignAudit(
|
|
90
|
-
// { _id: userAssign[0]._id },
|
|
91
|
-
// { isCompleted: true },
|
|
92
|
-
// );
|
|
93
|
-
// logger.info( 'Hit in auditUserAssignModel updateOne', {
|
|
94
|
-
// _id: userAssign[0]._id,
|
|
95
|
-
// isCompleted: true,
|
|
96
|
-
// } );
|
|
97
|
-
// } else {
|
|
98
|
-
// logger.info( 'Hit in new file', { inputData } );
|
|
99
|
-
// const consumer = await sqsReceive( inputData.queueName );
|
|
100
|
-
// if ( !consumer ) {
|
|
101
|
-
// logger.error( {
|
|
102
|
-
// error: consumer,
|
|
103
|
-
// function: 'getAuditFile',
|
|
104
|
-
// message: 'SQS Receive queue is empty',
|
|
105
|
-
// } );
|
|
106
|
-
// return res.sendError( `${inputData.queueName} is Empty`, 204 );
|
|
107
|
-
// }
|
|
108
|
-
// msg = JSON.parse( consumer );
|
|
109
|
-
// }
|
|
110
|
-
// break;
|
|
111
|
-
|
|
112
|
-
// case 'drafted':
|
|
113
|
-
// logger.info( 'userDetails drafted', { inputData } );
|
|
114
|
-
// const log = await findOneAuditLog(
|
|
115
|
-
// {
|
|
116
|
-
// userId: userDetails[0].userId,
|
|
117
|
-
// fileDate: userDetails[0].fileDate,
|
|
118
|
-
// storeId: userDetails[0].storeId,
|
|
119
|
-
// totalCount: userDetails[0].beforeCount,
|
|
120
|
-
// moduleType: userDetails[0].moduleType,
|
|
121
|
-
// zoneName: userDetails[0].zoneName,
|
|
122
|
-
// },
|
|
123
|
-
// {},
|
|
124
|
-
// { createdAt: -1 },
|
|
125
|
-
// );
|
|
126
|
-
// if ( !log ) {
|
|
127
|
-
// await updateOneUserAudit(
|
|
128
|
-
// { _id: userDetails[0]._id },
|
|
129
|
-
// { $set: { isDraft: false, auditStatus: 'skipped' } },
|
|
130
|
-
// );
|
|
131
|
-
// logger.info( 'audit update in drafted', {
|
|
132
|
-
// _id: userDetails[0]._id,
|
|
133
|
-
// isDraft: false,
|
|
134
|
-
// auditStatus: 'skipped',
|
|
135
|
-
// } );
|
|
136
|
-
// return res.sendError( 'User saved data has been deleted', 204 );
|
|
137
|
-
// }
|
|
138
|
-
// const file = {
|
|
139
|
-
// auditId: userDetails[0]._id,
|
|
140
|
-
// store_id: userDetails[0].storeId,
|
|
141
|
-
// file_date: userDetails[0].fileDate,
|
|
142
|
-
// type: userDetails[0].auditType,
|
|
143
|
-
// queueName: log.queueName,
|
|
144
|
-
// userId: log.userId,
|
|
145
|
-
// moduleType: userDetails[0].moduleType,
|
|
146
|
-
// zoneName: userDetails[0].zoneName,
|
|
147
|
-
// };
|
|
148
|
-
// const result = {
|
|
149
|
-
// junk: log.junk,
|
|
150
|
-
// junk_count: log.junkCount,
|
|
151
|
-
// employee: log.employee,
|
|
152
|
-
// employee_count: log.employeeCount,
|
|
153
|
-
// customer: log.customer,
|
|
154
|
-
// customer_count: log.customerCount,
|
|
155
|
-
// retag_image: log.retagImage,
|
|
156
|
-
// retag_count: log.retagCount,
|
|
157
|
-
// total_count: log.totalCount,
|
|
158
|
-
// };
|
|
159
|
-
|
|
160
|
-
// const userdata = await findOneUser( { _id: log.userId } );
|
|
161
|
-
// if (
|
|
162
|
-
// !inputData.nextId ||
|
|
163
|
-
// inputData.nextId === '' ||
|
|
164
|
-
// inputData.nextId == null
|
|
165
|
-
// ) {
|
|
166
|
-
// const logData = {
|
|
167
|
-
// userId: log.userId,
|
|
168
|
-
// userName: userdata.name,
|
|
169
|
-
// logType: 'audit',
|
|
170
|
-
// logSubType: 'auditStart',
|
|
171
|
-
// logData: {
|
|
172
|
-
// fileDate: userDetails[0].fileDate,
|
|
173
|
-
// auditType: userDetails[0].auditType,
|
|
174
|
-
// storeId: userDetails[0].storeId,
|
|
175
|
-
// clientName: log.queueName,
|
|
176
|
-
// auditId: userDetails[0]._id,
|
|
177
|
-
// moduleType: userDetails[0].moduleType,
|
|
178
|
-
// zoneName: userDetails[0].zoneName,
|
|
179
|
-
// },
|
|
180
|
-
// createdAt: new Date(),
|
|
181
|
-
// };
|
|
182
|
-
// logger.info( { logData: logData } );
|
|
183
|
-
// await insertOpenSearchData( openSearch.auditLog, logData );
|
|
184
|
-
// }
|
|
185
|
-
// const storeQuery = {
|
|
186
|
-
// storeId: userDetails[0].storeId,
|
|
187
|
-
// };
|
|
188
|
-
// const storeFields = {
|
|
189
|
-
// storeId: 1,
|
|
190
|
-
// storeName: 1,
|
|
191
|
-
// address: '$storeProfile.address',
|
|
192
|
-
// };
|
|
193
|
-
// const storeDetails = await findOneStore( storeQuery, storeFields );
|
|
194
|
-
// res.sendSuccess( {
|
|
195
|
-
// result: result,
|
|
196
|
-
// storeId: storeDetails?.storeId,
|
|
197
|
-
// storeName: storeDetails?.storeName,
|
|
198
|
-
// address: storeDetails?.address || '',
|
|
199
|
-
// count: log.totalCount,
|
|
200
|
-
// file: file,
|
|
201
|
-
// isDraft: userDetails[0].isDraft,
|
|
202
|
-
// } );
|
|
203
|
-
// break;
|
|
204
|
-
|
|
205
|
-
// default:
|
|
206
|
-
// msg = {
|
|
207
|
-
// store_id: userDetails[0].storeId,
|
|
208
|
-
// curr_date: userDetails[0].fileDate,
|
|
209
|
-
// audit_type: userDetails[0].auditType,
|
|
210
|
-
// total_count: userDetails[0].beforeCount,
|
|
211
|
-
// zone_id: userDetails[0].zoneName,
|
|
212
|
-
// };
|
|
213
|
-
// break;
|
|
214
|
-
// }
|
|
215
|
-
// if ( msg.audit_type === 'ReAudit' ) {
|
|
216
|
-
// logger.info( 'Hit in user ReAudit', { inputData } );
|
|
217
|
-
// let reauditInsert = {};
|
|
218
|
-
// const [ filterData, auditImage ] = await Promise.all( [
|
|
219
|
-
// getFilterData( msg ),
|
|
220
|
-
// getAuditImage( msg ),
|
|
221
|
-
// ] );
|
|
222
|
-
// if ( filterData.statusCode == 404 || auditImage.statusCode == 404 ) {
|
|
223
|
-
// return res.sendError( 'No Data found', 204 );
|
|
224
|
-
// }
|
|
225
|
-
// const reauditImg = await getReauditImg( filterData, auditImage );
|
|
226
|
-
// if ( userDetails.length === 0 ) {
|
|
227
|
-
// const [ day, month, year ] = msg.curr_date.split( '-' );
|
|
228
|
-
// const temp = `${year}-${month}-${day}`;
|
|
229
|
-
// let start = new Date( temp );
|
|
230
|
-
// const userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
231
|
-
// start = new Date( start.getTime() - userTimezoneOffset );
|
|
232
|
-
// start.setUTCHours( 0, 0, 0, 0 );
|
|
233
|
-
// const record = {
|
|
234
|
-
// userId: req.user._id,
|
|
235
|
-
// storeId: msg.store_id,
|
|
236
|
-
// clientId: msg.store_id.split( '-' )[0],
|
|
237
|
-
// auditType: msg.audit_type || 'ReAudit',
|
|
238
|
-
// fileDate: msg.curr_date,
|
|
239
|
-
// queueName: inputData.queueName,
|
|
240
|
-
// beforeCount: reauditImg.length,
|
|
241
|
-
// auditStatus: 'inprogress',
|
|
242
|
-
// fileDateISO: start,
|
|
243
|
-
// timeSpent: 0,
|
|
244
|
-
// startTime: new Date(),
|
|
245
|
-
// zoneName: msg.zone_id,
|
|
246
|
-
// moduleType: inputData.moduleType,
|
|
247
|
-
// };
|
|
248
|
-
// const query ={
|
|
249
|
-
// storeId: msg.store_id,
|
|
250
|
-
// zoneName: msg.zone_id,
|
|
251
|
-
// fileDate: msg.curr_date,
|
|
252
|
-
// moduleType: inputData.moduleType,
|
|
253
|
-
// };
|
|
254
|
-
// let storeRecord = {
|
|
255
|
-
// userId: req.user._id,
|
|
256
|
-
// auditType: msg.audit_type || 'ReAudit',
|
|
257
|
-
// status: 'inprogress',
|
|
258
|
-
// timeSpent: 0,
|
|
259
|
-
// };
|
|
260
|
-
// reauditInsert = await createUserAudit( record );
|
|
261
|
-
|
|
262
|
-
// await updateOneStoreAudit( query, storeRecord );
|
|
263
|
-
// } else {
|
|
264
|
-
// reauditInsert = userDetails[0];
|
|
265
|
-
// }
|
|
266
|
-
// const userdata = await findOneUser( { _id: req.user._id } );
|
|
267
|
-
// if ( inputData.nextId ) {
|
|
268
|
-
// const logData = {
|
|
269
|
-
// userId: req.user._id,
|
|
270
|
-
// userName: userdata.name,
|
|
271
|
-
// logType: 'audit',
|
|
272
|
-
// logSubType: 'auditStart',
|
|
273
|
-
// logData: {
|
|
274
|
-
// fileDate: msg.curr_date,
|
|
275
|
-
// auditType: msg.audit_type,
|
|
276
|
-
// storeId: msg.store_id,
|
|
277
|
-
// clientName: inputData.queueName,
|
|
278
|
-
// auditId: reauditInsert._id,
|
|
279
|
-
// zoneName: msg.zone_id,
|
|
280
|
-
// moduleType: inputData.moduleType,
|
|
281
|
-
// },
|
|
282
|
-
// createdAt: new Date(),
|
|
283
|
-
// };
|
|
284
|
-
// await insertOpenSearchData( openSearch.auditLog, logData );
|
|
285
|
-
// }
|
|
286
|
-
|
|
287
|
-
// const storeQuery = {
|
|
288
|
-
// storeId: msg.store_id,
|
|
289
|
-
// };
|
|
290
|
-
// const storeFields = {
|
|
291
|
-
// storeId: 1,
|
|
292
|
-
// storeName: 1,
|
|
293
|
-
// address: '$storeProfile.address',
|
|
294
|
-
// };
|
|
295
|
-
// const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
296
|
-
// return res.sendSuccess( {
|
|
297
|
-
// result: reauditImg,
|
|
298
|
-
// count: reauditImg.length,
|
|
299
|
-
// storeId: storeInfo?.storeId,
|
|
300
|
-
// storeName: storeInfo?.storeName,
|
|
301
|
-
// address: storeInfo?.address || '',
|
|
302
|
-
// file: {
|
|
303
|
-
// store_id: msg.store_id,
|
|
304
|
-
// file_date: msg.curr_date,
|
|
305
|
-
// type: msg.audit_type || 'ReAudit',
|
|
306
|
-
// queueName: inputData.queueName,
|
|
307
|
-
// auditId: reauditInsert._id,
|
|
308
|
-
// userId: reauditInsert.userId,
|
|
309
|
-
// zoneName: msg.zone_id,
|
|
310
|
-
// moduleType: inputData.moduleType,
|
|
311
|
-
// },
|
|
312
|
-
// isDraft: reauditInsert.isDraft,
|
|
313
|
-
// } );
|
|
314
|
-
// }
|
|
315
|
-
// const storeId = msg.store_id;
|
|
316
|
-
// const fileDate = msg.curr_date;
|
|
317
|
-
|
|
318
|
-
// const files = [];
|
|
319
|
-
// let insertData = {};
|
|
320
|
-
// fetchData.Bucket = bucket.auditInput; // need to change
|
|
321
|
-
// fetchData.file_path = `${fileDate}/${storeId}/${msg.zone_id}/`;
|
|
322
|
-
// if ( inputData.limit ) {
|
|
323
|
-
// fetchData.MaxKeys = inputData.limit;
|
|
324
|
-
// }
|
|
325
|
-
// if ( inputData.nextId ) {
|
|
326
|
-
// fetchData.ContinuationToken = decodeURIComponent( inputData.nextId );
|
|
327
|
-
// }
|
|
328
|
-
// const list = await listFileByPath( fetchData );
|
|
329
|
-
// const folderPath = list.data;
|
|
330
|
-
// const nextQuery = list.pageToken;
|
|
331
|
-
// if ( folderPath?.length > 0 ) {
|
|
332
|
-
// for ( let i = 0; i < folderPath.length; i++ ) {
|
|
333
|
-
// const img = folderPath[i].Key.split( '/' );
|
|
334
|
-
// const image = img[3].split( '.' );
|
|
335
|
-
// const indexes = image[0].split( '_' );
|
|
336
|
-
// fetchData.file_path = folderPath[i].Key;
|
|
337
|
-
// const data = await signedUrl( fetchData );
|
|
338
|
-
// const mapimg = {
|
|
339
|
-
// img_path: data,
|
|
340
|
-
// img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
341
|
-
// img_id: img[3],
|
|
342
|
-
// };
|
|
343
|
-
// files.push( {
|
|
344
|
-
// img_path: data,
|
|
345
|
-
// img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
346
|
-
// img_id: img[3],
|
|
347
|
-
// selected: false,
|
|
348
|
-
// dropped: false,
|
|
349
|
-
// singleDetection: false,
|
|
350
|
-
// count: 1,
|
|
351
|
-
// mappedid: [ mapimg ],
|
|
352
|
-
// } );
|
|
353
|
-
// }
|
|
354
|
-
// if ( userDetails.length === 0 ) {
|
|
355
|
-
// const [ day, month, year ] = msg.curr_date.split( '-' );
|
|
356
|
-
// const temp = `${year}-${month}-${day}`;
|
|
357
|
-
// let start = new Date( temp );
|
|
358
|
-
// logger.info( { start: start, date: msg.curr_date } );
|
|
359
|
-
// const userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
360
|
-
// start = new Date( start.getTime() - userTimezoneOffset );
|
|
361
|
-
// start.setUTCHours( 0, 0, 0, 0 );
|
|
362
|
-
// const record = {
|
|
363
|
-
// userId: req.user._id,
|
|
364
|
-
// storeId: msg.store_id,
|
|
365
|
-
// clientId: msg.store_id.split( '-' )[0],
|
|
366
|
-
// auditType: 'Audit',
|
|
367
|
-
// fileDate: msg.curr_date,
|
|
368
|
-
// queueName: inputData.queueName,
|
|
369
|
-
// beforeCount: msg.total_count || files.length,
|
|
370
|
-
// auditStatus: 'inprogress',
|
|
371
|
-
// fileDateISO: start,
|
|
372
|
-
// timeSpent: 0,
|
|
373
|
-
// startTime: new Date(),
|
|
374
|
-
// zoneName: msg.zone_id,
|
|
375
|
-
// moduleType: inputData.moduleType,
|
|
376
|
-
// };
|
|
377
|
-
// const query ={
|
|
378
|
-
// storeId: msg.store_id,
|
|
379
|
-
// zoneName: msg.zone_id,
|
|
380
|
-
// fileDate: msg.curr_date,
|
|
381
|
-
// moduleType: inputData.moduleType,
|
|
382
|
-
// };
|
|
383
|
-
// const storeRecord = {
|
|
384
|
-
// userId: req.user._id,
|
|
385
|
-
// storeId: msg.store_id,
|
|
386
|
-
// clientId: msg.store_id.split( '-' )[0],
|
|
387
|
-
// auditType: 'Audit',
|
|
388
|
-
// fileDate: msg.curr_date,
|
|
389
|
-
// queueName: inputData.queueName,
|
|
390
|
-
// beforeCount: msg.total_count || files.length,
|
|
391
|
-
// status: 'inprogress',
|
|
392
|
-
// fileDateISO: start,
|
|
393
|
-
// timeSpent: 0,
|
|
394
|
-
// zoneName: msg.zone_id,
|
|
395
|
-
// moduleType: inputData.moduleType,
|
|
396
|
-
// };
|
|
397
|
-
|
|
398
|
-
// insertData = await createUserEmpDetection( record );
|
|
399
|
-
// await updateManyStoreEmpDetection( query, storeRecord );
|
|
400
|
-
// } else {
|
|
401
|
-
// insertData = userDetails[0];
|
|
402
|
-
// }
|
|
403
|
-
// } else {
|
|
404
|
-
// logger.error( {
|
|
405
|
-
// error: { folderPath: folderPath, nextQuery: nextQuery },
|
|
406
|
-
// function: 'getAuditFile',
|
|
407
|
-
// message: 'Bucket image data not availale',
|
|
408
|
-
// } );
|
|
409
|
-
// return res.sendError( 'Bucket is Empty', 204 );
|
|
410
|
-
// }
|
|
411
|
-
// const userdata = await findOneUser( { _id: insertData.userId } );
|
|
412
|
-
// const storeQuery = {
|
|
413
|
-
// storeId: storeId,
|
|
414
|
-
// };
|
|
415
|
-
// const storeFields = {
|
|
416
|
-
// storeName: 1,
|
|
417
|
-
// address: '$storeProfile.address',
|
|
418
|
-
// };
|
|
419
|
-
// const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
420
|
-
// if ( inputData.nextId ) {
|
|
421
|
-
// const logData = {
|
|
422
|
-
// userId: insertData.userId,
|
|
423
|
-
// userName: userdata.name,
|
|
424
|
-
// logType: 'audit',
|
|
425
|
-
// logSubType: 'auditStart',
|
|
426
|
-
// logData: {
|
|
427
|
-
// fileDate: insertData.fileDate,
|
|
428
|
-
// auditType: insertData.auditType,
|
|
429
|
-
// storeId: storeId,
|
|
430
|
-
// clientName: inputData.queueName,
|
|
431
|
-
// auditId: insertData._id,
|
|
432
|
-
// zoneName: msg.zone_id,
|
|
433
|
-
// moduleType: inputData.moduleType,
|
|
434
|
-
// },
|
|
435
|
-
// createdAt: new Date(),
|
|
436
|
-
// };
|
|
437
|
-
// await insertOpenSearchData( openSearch.auditLog, logData );
|
|
438
|
-
// }
|
|
439
|
-
// logger.info( { storeInfo: storeInfo } );
|
|
440
|
-
// return res.sendSuccess( {
|
|
441
|
-
// result: files,
|
|
442
|
-
// count: msg.total_count,
|
|
443
|
-
// storeId: storeId,
|
|
444
|
-
// storeName: storeInfo?.storeName,
|
|
445
|
-
// address: storeInfo?.address,
|
|
446
|
-
// file: {
|
|
447
|
-
// queueName: inputData.queueName,
|
|
448
|
-
// store_id: storeId,
|
|
449
|
-
// file_date: fileDate,
|
|
450
|
-
// type: 'Audit',
|
|
451
|
-
// auditId: insertData._id,
|
|
452
|
-
// userId: insertData.userId,
|
|
453
|
-
// zoneName: msg.zone_id,
|
|
454
|
-
// moduleType: inputData.moduleType,
|
|
455
|
-
// nextToken: nextQuery ? encodeURIComponent( nextQuery ) : null,
|
|
456
|
-
// },
|
|
457
|
-
// isDraft: insertData.isDraft,
|
|
458
|
-
// } );
|
|
459
|
-
// } catch ( error ) {
|
|
460
|
-
// logger.error( {
|
|
461
|
-
// error: error,
|
|
462
|
-
// message: req.query,
|
|
463
|
-
// function: 'getAuditFile',
|
|
464
|
-
// } );
|
|
465
|
-
// return res.sendError( error, 500 );
|
|
466
|
-
// }
|
|
467
|
-
// }
|
|
468
20
|
|
|
469
21
|
export async function workSpace( req, res ) {
|
|
470
22
|
try {
|
|
@@ -476,7 +28,7 @@ export async function workSpace( req, res ) {
|
|
|
476
28
|
const dateRange = await getDate( new Date(), new Date() );
|
|
477
29
|
const filter =[
|
|
478
30
|
{ status: { $in: [ 'active', 'hold' ] } },
|
|
479
|
-
{ 'auditConfigs.
|
|
31
|
+
{ 'auditConfigs.traxAudit': { $eq: true } },
|
|
480
32
|
{ clientId: { $in: inputData.clientId } },
|
|
481
33
|
];
|
|
482
34
|
|
|
@@ -501,7 +53,12 @@ export async function workSpace( req, res ) {
|
|
|
501
53
|
{ $eq: [ inputData.moduleType, 'uniform-detection' ] }, '$auditConfigs.traxQueueName.uniformDetection',
|
|
502
54
|
{
|
|
503
55
|
$cond: [
|
|
504
|
-
{ $eq: [ inputData.moduleType, 'mobile-detection' ] }, '$auditConfigs.traxQueueName.mobileDetection',
|
|
56
|
+
{ $eq: [ inputData.moduleType, 'mobile-detection' ] }, '$auditConfigs.traxQueueName.mobileDetection',
|
|
57
|
+
{
|
|
58
|
+
$cond: [
|
|
59
|
+
{ $eq: [ inputData.moduleType, 'hygiene' ] }, '$auditConfigs.traxQueueName.hygiene', '$auditConfigs.traxQueueName.cameraAngleChange',
|
|
60
|
+
],
|
|
61
|
+
},
|
|
505
62
|
],
|
|
506
63
|
},
|
|
507
64
|
],
|
|
@@ -546,8 +103,10 @@ export async function workSpace( req, res ) {
|
|
|
546
103
|
const clientDetails = await aggregateClient( clientQuery );
|
|
547
104
|
const clientList = clientDetails.map( ( i ) => i.clientId );
|
|
548
105
|
const fileDate = dayjs( dateRange.start ).subtract( 1, 'days' );
|
|
106
|
+
const traxDataQuery = inputData?.moduleType == 'hygine'? { moduleType: inputData.moduleType } : {};
|
|
107
|
+
|
|
549
108
|
const getStoreData = await findOneTraxAuditData(
|
|
550
|
-
|
|
109
|
+
traxDataQuery,
|
|
551
110
|
{ fileDate: 1 },
|
|
552
111
|
{ createdAt: -1 },
|
|
553
112
|
);
|
|
@@ -566,7 +125,6 @@ export async function workSpace( req, res ) {
|
|
|
566
125
|
clientId: { $last: '$clientId' },
|
|
567
126
|
clientName: { $last: '$clientName' },
|
|
568
127
|
installedStore: { $last: '$installedStore' },
|
|
569
|
-
// queueName: { $last: '$queueName' },
|
|
570
128
|
totalCount: { $sum: 1 },
|
|
571
129
|
},
|
|
572
130
|
},
|
|
@@ -600,18 +158,10 @@ export async function workSpace( req, res ) {
|
|
|
600
158
|
},
|
|
601
159
|
},
|
|
602
160
|
},
|
|
603
|
-
// {
|
|
604
|
-
// $group: {
|
|
605
|
-
// _id: { clientId: '$clientId', storeId: '$storeId' },
|
|
606
|
-
// clientId: { $first: '$clientId' },
|
|
607
|
-
// completedStoresCount: { $sum: '$completed' },
|
|
608
|
-
// },
|
|
609
|
-
// },
|
|
610
161
|
{
|
|
611
162
|
$group: {
|
|
612
163
|
_id: '$clientId',
|
|
613
164
|
clientId: { $first: '$clientId' },
|
|
614
|
-
// completedStoresCount: { $first: '$completedStoresCount' },
|
|
615
165
|
completedStoresCount: { $sum: '$completed' },
|
|
616
166
|
},
|
|
617
167
|
},
|
|
@@ -799,11 +349,11 @@ export async function workSpace( req, res ) {
|
|
|
799
349
|
},
|
|
800
350
|
];
|
|
801
351
|
|
|
802
|
-
const auditUserCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
803
|
-
const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
352
|
+
const auditUserCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( auditFiles ) : await aggregateBinaryAudit( auditFiles );
|
|
353
|
+
const userIncompleteFilesCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( userIncompleteFiles ) : await aggregateBinaryAudit( userIncompleteFiles );
|
|
804
354
|
logger.info( { moduleType: inputData.moduleType, userIncompleteFiles: userIncompleteFilesCount } );
|
|
805
355
|
const userAsignAuditCount = await aggregateAssignAudit( userAsignAudit );
|
|
806
|
-
const completedStoresCount = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
|
|
356
|
+
const completedStoresCount = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( completedStores ) : await aggregateBinaryAudit( binarCompletedStores );
|
|
807
357
|
const clientAssignedCount = await aggregateAssignAudit( clientAssign );
|
|
808
358
|
const auditStoreData = await aggregateTraxAuditData(
|
|
809
359
|
auditStoreDataQuery,
|
|
@@ -901,7 +451,7 @@ export async function workSpace( req, res ) {
|
|
|
901
451
|
}
|
|
902
452
|
} catch ( error ) {
|
|
903
453
|
const err = error.message || 'Internal Server Error';
|
|
904
|
-
logger.
|
|
454
|
+
logger.error( { error: error, message: req.query, function: 'workSpace' } );
|
|
905
455
|
return res.sendError( err, 500 );
|
|
906
456
|
}
|
|
907
457
|
}
|
|
@@ -1063,14 +613,6 @@ export async function getAuditFile( req, res ) {
|
|
|
1063
613
|
data,
|
|
1064
614
|
);
|
|
1065
615
|
}
|
|
1066
|
-
// else {
|
|
1067
|
-
// logger.error( {
|
|
1068
|
-
// error: { folderPath: folderPath },
|
|
1069
|
-
// function: `getAuditFile - ${inputData.moduleType}`,
|
|
1070
|
-
// message: 'Bucket image data not availale',
|
|
1071
|
-
// } );
|
|
1072
|
-
// return res.sendError( 'Bucket is Empty', 204 );
|
|
1073
|
-
// }
|
|
1074
616
|
result.push( {
|
|
1075
617
|
type: 'image',
|
|
1076
618
|
file: files,
|
|
@@ -1743,6 +1285,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1743
1285
|
tempId: 1,
|
|
1744
1286
|
streamName: 1,
|
|
1745
1287
|
question: 1,
|
|
1288
|
+
zoneName: 1,
|
|
1746
1289
|
questionType: 1,
|
|
1747
1290
|
answer: 1,
|
|
1748
1291
|
userComments: 1,
|
|
@@ -1826,6 +1369,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1826
1369
|
{ auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1827
1370
|
{ tempId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1828
1371
|
{ question: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1372
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1829
1373
|
{ userComments: { $regex: inputData.searchValue, $options: 'i' } },
|
|
1830
1374
|
],
|
|
1831
1375
|
|
|
@@ -1841,7 +1385,7 @@ export async function userAuditHistory( req, res ) {
|
|
|
1841
1385
|
},
|
|
1842
1386
|
);
|
|
1843
1387
|
}
|
|
1844
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1388
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1845
1389
|
if ( count.length == 0 ) {
|
|
1846
1390
|
return res.sendError( 'No Data Found', 204 );
|
|
1847
1391
|
}
|
|
@@ -1886,10 +1430,6 @@ export async function userAuditHistory( req, res ) {
|
|
|
1886
1430
|
temp['User Comments'] = element.userComments;
|
|
1887
1431
|
break;
|
|
1888
1432
|
case 'uniform-detection':
|
|
1889
|
-
// temp['Customer ID'] = element.tempId;
|
|
1890
|
-
// temp['Question'] = element.question;
|
|
1891
|
-
// temp['Result'] = element.answer;
|
|
1892
|
-
// temp['User Comments'] = element.userComments;
|
|
1893
1433
|
temp['Before Count'] = element.beforeCount;
|
|
1894
1434
|
temp['After Count'] = element.afterCount;
|
|
1895
1435
|
temp['Accuracy'] = element.accuracy || '';
|
|
@@ -1899,6 +1439,12 @@ export async function userAuditHistory( req, res ) {
|
|
|
1899
1439
|
temp['After Count'] = element.afterCount;
|
|
1900
1440
|
temp['Accuracy'] = element.accuracy || '';
|
|
1901
1441
|
break;
|
|
1442
|
+
case 'hygiene':
|
|
1443
|
+
temp['Zone Name'] = element.zoneName;
|
|
1444
|
+
temp['Before Count'] = element.beforeCount;
|
|
1445
|
+
temp['After Count'] = element.afterCount;
|
|
1446
|
+
temp['Accuracy'] = element.accuracy || '';
|
|
1447
|
+
break;
|
|
1902
1448
|
}
|
|
1903
1449
|
exportData.push( temp );
|
|
1904
1450
|
} );
|
|
@@ -1918,12 +1464,12 @@ export async function userAuditHistory( req, res ) {
|
|
|
1918
1464
|
}
|
|
1919
1465
|
|
|
1920
1466
|
|
|
1921
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1467
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
1922
1468
|
|
|
1923
1469
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
1924
1470
|
} catch ( error ) {
|
|
1925
1471
|
const err = error.message || 'Internal Server Error';
|
|
1926
|
-
logger.
|
|
1472
|
+
logger.error( { error: error, message: req.body, function: 'userAuditHistory' } );
|
|
1927
1473
|
return res.sendError( err, 500 );
|
|
1928
1474
|
}
|
|
1929
1475
|
}
|
|
@@ -1952,241 +1498,240 @@ export async function clientMetrics( req, res ) {
|
|
|
1952
1498
|
{ clientId: { $in: inputData.filterByClient } },
|
|
1953
1499
|
);
|
|
1954
1500
|
}
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1501
|
+
let query = [];
|
|
1502
|
+
if ( [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType ) ) {
|
|
1503
|
+
query =[
|
|
1504
|
+
{
|
|
1505
|
+
$match: {
|
|
1506
|
+
$and: filter,
|
|
1507
|
+
},
|
|
1959
1508
|
},
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1509
|
+
{
|
|
1510
|
+
$group: {
|
|
1511
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
|
|
1512
|
+
fileDate: { $last: '$fileDate' },
|
|
1513
|
+
clientId: { $last: '$clientId' },
|
|
1514
|
+
clientName: { $last: '$clientName' },
|
|
1515
|
+
moduleType: { $last: '$moduleType' },
|
|
1516
|
+
installedStore: { $last: '$installedStore' },
|
|
1517
|
+
queueName: { $last: '$queueName' },
|
|
1518
|
+
totalFilesCount: { $sum: 1 },
|
|
1519
|
+
},
|
|
1971
1520
|
},
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1521
|
+
{
|
|
1522
|
+
$project: {
|
|
1523
|
+
fileDate: 1,
|
|
1524
|
+
clientId: 1,
|
|
1525
|
+
clientName: 1,
|
|
1526
|
+
queueName: 1,
|
|
1527
|
+
installedStore: 1,
|
|
1528
|
+
totalFilesCount: 1,
|
|
1529
|
+
moduleType: 1,
|
|
1530
|
+
notAssignedCount: { $ifNull: [ 0, 0 ] },
|
|
1531
|
+
clientStatus: { $ifNull: [ '', '' ] },
|
|
1532
|
+
},
|
|
1984
1533
|
},
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
'pipeline': [
|
|
1534
|
+
{
|
|
1535
|
+
$lookup: {
|
|
1536
|
+
'from': 'storeEmpDetection',
|
|
1537
|
+
'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
|
|
1538
|
+
'pipeline': [
|
|
1991
1539
|
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1540
|
+
{
|
|
1541
|
+
$match: {
|
|
1542
|
+
$expr: {
|
|
1543
|
+
$and: storeAuditFilter,
|
|
1544
|
+
},
|
|
1996
1545
|
},
|
|
1997
1546
|
},
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
1547
|
+
{
|
|
1548
|
+
$project: {
|
|
1549
|
+
completedStores: { $cond: [ { $eq: [ '$status', 'completed' ] }, 1, 0 ] },
|
|
1550
|
+
notAssignedStores: { $cond: [ { $eq: [ '$status', 'not_assign' ] }, 1, 0 ] },
|
|
1551
|
+
inprogressStores: { $cond: [ { $in: [ '$status', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
|
|
1552
|
+
},
|
|
2004
1553
|
},
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
1554
|
+
{
|
|
1555
|
+
$group: {
|
|
1556
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
1557
|
+
completedStores: { $sum: '$completedStores' },
|
|
1558
|
+
inprogressStores: { $sum: '$inprogressStores' },
|
|
1559
|
+
notAssignedStores: { $sum: '$notAssignedStores' },
|
|
1560
|
+
fileCount: { $sum: 1 },
|
|
1561
|
+
},
|
|
2013
1562
|
},
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
],
|
|
2032
|
-
}, 1 ],
|
|
1563
|
+
{
|
|
1564
|
+
$project: {
|
|
1565
|
+
_id: 0,
|
|
1566
|
+
completedStores: 1,
|
|
1567
|
+
inprogressStores: 1,
|
|
1568
|
+
notAssignedStores: 1,
|
|
1569
|
+
fileCount: { $ifNull: [ '$fileCount', 0 ] },
|
|
1570
|
+
completionPercentage: { $ifNull: [
|
|
1571
|
+
{
|
|
1572
|
+
$round: [ {
|
|
1573
|
+
$multiply: [
|
|
1574
|
+
100, {
|
|
1575
|
+
$divide: [
|
|
1576
|
+
'$completedStores', '$$totalAuditFiles',
|
|
1577
|
+
],
|
|
1578
|
+
},
|
|
1579
|
+
],
|
|
1580
|
+
}, 1 ],
|
|
2033
1581
|
|
|
1582
|
+
},
|
|
1583
|
+
0,
|
|
1584
|
+
],
|
|
2034
1585
|
},
|
|
2035
|
-
0,
|
|
2036
|
-
],
|
|
2037
1586
|
},
|
|
2038
1587
|
},
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
},
|
|
2042
|
-
},
|
|
2043
|
-
{
|
|
2044
|
-
$unwind: {
|
|
2045
|
-
path: '$binaryAudit',
|
|
2046
|
-
preserveNullAndEmptyArrays: true,
|
|
1588
|
+
], 'as': 'binaryAudit',
|
|
1589
|
+
},
|
|
2047
1590
|
},
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
fileDate: 1,
|
|
2053
|
-
clientId: 1,
|
|
2054
|
-
clientName: 1,
|
|
2055
|
-
totalFilesCount: 1,
|
|
2056
|
-
moduleType: 1,
|
|
2057
|
-
value: {
|
|
2058
|
-
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1591
|
+
{
|
|
1592
|
+
$unwind: {
|
|
1593
|
+
path: '$binaryAudit',
|
|
1594
|
+
preserveNullAndEmptyArrays: true,
|
|
2059
1595
|
},
|
|
2060
|
-
installedStore: 1,
|
|
2061
|
-
// notAssignedStores: '$binaryAudit.notAssignedStores',
|
|
2062
|
-
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
2063
|
-
// fileCount: '$binaryAudit.fileCount',
|
|
2064
|
-
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
2065
|
-
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
|
|
2066
|
-
completedStores: '$binaryAudit.completedStores',
|
|
2067
|
-
completionPercentage: '$binaryAudit.completionPercentage',
|
|
2068
|
-
|
|
2069
1596
|
},
|
|
2070
|
-
|
|
2071
|
-
|
|
1597
|
+
{
|
|
1598
|
+
$project: {
|
|
1599
|
+
_id: 0,
|
|
1600
|
+
fileDate: 1,
|
|
1601
|
+
clientId: 1,
|
|
1602
|
+
clientName: 1,
|
|
1603
|
+
totalFilesCount: 1,
|
|
1604
|
+
moduleType: 1,
|
|
1605
|
+
value: {
|
|
1606
|
+
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1607
|
+
},
|
|
1608
|
+
installedStore: 1,
|
|
1609
|
+
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
1610
|
+
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
1611
|
+
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
|
|
1612
|
+
completedStores: '$binaryAudit.completedStores',
|
|
1613
|
+
completionPercentage: '$binaryAudit.completionPercentage',
|
|
2072
1614
|
|
|
2073
|
-
|
|
2074
|
-
{
|
|
2075
|
-
$match: {
|
|
2076
|
-
$and: filter,
|
|
1615
|
+
},
|
|
2077
1616
|
},
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
moduleType: { $last: '$moduleType' },
|
|
2086
|
-
installedStore: { $last: '$installedStore' },
|
|
2087
|
-
queueName: { $last: '$queueName' },
|
|
2088
|
-
totalFilesCount: { $sum: 1 },
|
|
1617
|
+
];
|
|
1618
|
+
} else {
|
|
1619
|
+
query = [
|
|
1620
|
+
{
|
|
1621
|
+
$match: {
|
|
1622
|
+
$and: filter,
|
|
1623
|
+
},
|
|
2089
1624
|
},
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
clientStatus: { $ifNull: [ '', '' ] },
|
|
1625
|
+
{
|
|
1626
|
+
$group: {
|
|
1627
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate', moduleType: '$moduleType' },
|
|
1628
|
+
fileDate: { $last: '$fileDate' },
|
|
1629
|
+
clientId: { $last: '$clientId' },
|
|
1630
|
+
clientName: { $last: '$clientName' },
|
|
1631
|
+
moduleType: { $last: '$moduleType' },
|
|
1632
|
+
installedStore: { $last: '$installedStore' },
|
|
1633
|
+
queueName: { $last: '$queueName' },
|
|
1634
|
+
totalFilesCount: { $sum: 1 },
|
|
1635
|
+
},
|
|
2102
1636
|
},
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
1637
|
+
{
|
|
1638
|
+
$project: {
|
|
1639
|
+
fileDate: 1,
|
|
1640
|
+
clientId: 1,
|
|
1641
|
+
clientName: 1,
|
|
1642
|
+
queueName: 1,
|
|
1643
|
+
installedStore: 1,
|
|
1644
|
+
totalFilesCount: 1,
|
|
1645
|
+
moduleType: 1,
|
|
1646
|
+
notAssignedCount: { $ifNull: [ 0, 0 ] },
|
|
1647
|
+
clientStatus: { $ifNull: [ '', '' ] },
|
|
1648
|
+
},
|
|
1649
|
+
},
|
|
1650
|
+
{
|
|
1651
|
+
$lookup: {
|
|
1652
|
+
'from': 'binaryAudit',
|
|
1653
|
+
'let': { clientId: '$clientId', fileDate: '$fileDate', totalAuditFiles: '$totalFilesCount' },
|
|
1654
|
+
'pipeline': [
|
|
2109
1655
|
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
1656
|
+
{
|
|
1657
|
+
$match: {
|
|
1658
|
+
$expr: {
|
|
1659
|
+
$and: storeAuditFilter,
|
|
1660
|
+
},
|
|
2114
1661
|
},
|
|
2115
1662
|
},
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
1663
|
+
{
|
|
1664
|
+
$project: {
|
|
1665
|
+
completedStores: { $cond: [ { $eq: [ '$auditStatus', 'completed' ] }, 1, 0 ] },
|
|
1666
|
+
notAssignedStores: { $cond: [ { $eq: [ '$auditStatus', 'not_assign' ] }, 1, 0 ] },
|
|
1667
|
+
inprogressStores: { $cond: [ { $in: [ '$auditStatus', [ 'inprogress', 'drafted', 'assigned' ] ] }, 1, 0 ] },
|
|
1668
|
+
},
|
|
2122
1669
|
},
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
1670
|
+
{
|
|
1671
|
+
$group: {
|
|
1672
|
+
_id: { clientId: '$clientId', fileDate: '$fileDate' },
|
|
1673
|
+
completedStores: { $sum: '$completedStores' },
|
|
1674
|
+
inprogressStores: { $sum: '$inprogressStores' },
|
|
1675
|
+
notAssignedStores: { $sum: '$notAssignedStores' },
|
|
1676
|
+
fileCount: { $sum: 1 },
|
|
1677
|
+
},
|
|
2131
1678
|
},
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
],
|
|
2150
|
-
}, 1 ],
|
|
1679
|
+
{
|
|
1680
|
+
$project: {
|
|
1681
|
+
_id: 0,
|
|
1682
|
+
completedStores: 1,
|
|
1683
|
+
inprogressStores: 1,
|
|
1684
|
+
notAssignedStores: 1,
|
|
1685
|
+
fileCount: { $ifNull: [ '$fileCount', 0 ] },
|
|
1686
|
+
completionPercentage: { $ifNull: [
|
|
1687
|
+
{
|
|
1688
|
+
$round: [ {
|
|
1689
|
+
$multiply: [
|
|
1690
|
+
100, {
|
|
1691
|
+
$divide: [
|
|
1692
|
+
'$completedStores', '$$totalAuditFiles',
|
|
1693
|
+
],
|
|
1694
|
+
},
|
|
1695
|
+
],
|
|
1696
|
+
}, 1 ],
|
|
2151
1697
|
|
|
1698
|
+
},
|
|
1699
|
+
0,
|
|
1700
|
+
],
|
|
2152
1701
|
},
|
|
2153
|
-
0,
|
|
2154
|
-
],
|
|
2155
1702
|
},
|
|
2156
1703
|
},
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
},
|
|
2160
|
-
},
|
|
2161
|
-
{
|
|
2162
|
-
$unwind: {
|
|
2163
|
-
path: '$binaryAudit',
|
|
2164
|
-
preserveNullAndEmptyArrays: true,
|
|
1704
|
+
], 'as': 'binaryAudit',
|
|
1705
|
+
},
|
|
2165
1706
|
},
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
fileDate: 1,
|
|
2171
|
-
clientId: 1,
|
|
2172
|
-
clientName: 1,
|
|
2173
|
-
totalFilesCount: 1,
|
|
2174
|
-
moduleType: 1,
|
|
2175
|
-
value: {
|
|
2176
|
-
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1707
|
+
{
|
|
1708
|
+
$unwind: {
|
|
1709
|
+
path: '$binaryAudit',
|
|
1710
|
+
preserveNullAndEmptyArrays: true,
|
|
2177
1711
|
},
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
1712
|
+
},
|
|
1713
|
+
{
|
|
1714
|
+
$project: {
|
|
1715
|
+
_id: 0,
|
|
1716
|
+
fileDate: 1,
|
|
1717
|
+
clientId: 1,
|
|
1718
|
+
clientName: 1,
|
|
1719
|
+
totalFilesCount: 1,
|
|
1720
|
+
moduleType: 1,
|
|
1721
|
+
value: {
|
|
1722
|
+
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' }, // Replacing "-" with " "
|
|
1723
|
+
},
|
|
1724
|
+
installedStore: 1,
|
|
1725
|
+
inprogressStoresCount: '$binaryAudit.inprogressStores',
|
|
1726
|
+
notAssignedCount: { $subtract: [ '$totalFilesCount', { $subtract: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, { $ifNull: [ '$binaryAudit.notAssignedStores', 0 ] } ] } ] },
|
|
1727
|
+
clientStatus: { $cond: [ { $eq: [ { $ifNull: [ '$binaryAudit.fileCount', 0 ] }, 0 ] }, 'not-taken', { $cond: [ { $gte: [ '$binaryAudit.completedStores', '$totalFilesCount' ] }, 'completed', 'pending' ] } ] }, // { $cond: [ { $or: [ { $gt: [ '$notAssignedCount', 0 ] }, { $gt: [ '$binaryAudit.notAssignedStores', 0 ] } ] }
|
|
1728
|
+
completedStores: '$binaryAudit.completedStores',
|
|
1729
|
+
completionPercentage: '$binaryAudit.completionPercentage',
|
|
2186
1730
|
|
|
1731
|
+
},
|
|
2187
1732
|
},
|
|
2188
|
-
|
|
2189
|
-
|
|
1733
|
+
];
|
|
1734
|
+
}
|
|
2190
1735
|
|
|
2191
1736
|
|
|
2192
1737
|
if ( inputData?.filterByStatus?.length> 0 ) {
|
|
@@ -2196,12 +1741,6 @@ export async function clientMetrics( req, res ) {
|
|
|
2196
1741
|
},
|
|
2197
1742
|
|
|
2198
1743
|
);
|
|
2199
|
-
MappingQuery.push(
|
|
2200
|
-
{
|
|
2201
|
-
$match: { clientStatus: { $in: inputData.filterByStatus } },
|
|
2202
|
-
},
|
|
2203
|
-
|
|
2204
|
-
);
|
|
2205
1744
|
}
|
|
2206
1745
|
|
|
2207
1746
|
if ( inputData.searchValue && inputData.searchValue!== '' ) {
|
|
@@ -2216,18 +1755,6 @@ export async function clientMetrics( req, res ) {
|
|
|
2216
1755
|
|
|
2217
1756
|
},
|
|
2218
1757
|
} );
|
|
2219
|
-
|
|
2220
|
-
MappingQuery.push( {
|
|
2221
|
-
$match: {
|
|
2222
|
-
$or: [
|
|
2223
|
-
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2224
|
-
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2225
|
-
{ moduleType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2226
|
-
{ clientStatus: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2227
|
-
],
|
|
2228
|
-
|
|
2229
|
-
},
|
|
2230
|
-
} );
|
|
2231
1758
|
}
|
|
2232
1759
|
if ( inputData.sortColumnName ) {
|
|
2233
1760
|
const sortBy = inputData.sortBy || -1;
|
|
@@ -2236,23 +1763,15 @@ export async function clientMetrics( req, res ) {
|
|
|
2236
1763
|
$sort: { [sortColumn]: sortBy },
|
|
2237
1764
|
},
|
|
2238
1765
|
);
|
|
2239
|
-
|
|
2240
|
-
MappingQuery.push( {
|
|
2241
|
-
$sort: { [sortColumn]: sortBy },
|
|
2242
|
-
},
|
|
2243
|
-
);
|
|
2244
1766
|
}
|
|
2245
1767
|
|
|
2246
|
-
const count =
|
|
2247
|
-
logger.info( { count: count } );
|
|
1768
|
+
const count = await aggregateTraxAuditData( query );
|
|
2248
1769
|
if ( count.length == 0 ) {
|
|
2249
1770
|
return res.sendError( 'No Data Found', 204 );
|
|
2250
1771
|
}
|
|
2251
1772
|
|
|
2252
1773
|
if ( inputData.isExport ) {
|
|
2253
1774
|
query.push( { $limit: 10000 } );
|
|
2254
|
-
|
|
2255
|
-
MappingQuery.push( { $limit: 10000 } );
|
|
2256
1775
|
} else {
|
|
2257
1776
|
query.push( {
|
|
2258
1777
|
$skip: offset,
|
|
@@ -2260,13 +1779,6 @@ export async function clientMetrics( req, res ) {
|
|
|
2260
1779
|
{
|
|
2261
1780
|
$limit: limit,
|
|
2262
1781
|
} );
|
|
2263
|
-
|
|
2264
|
-
MappingQuery.push( {
|
|
2265
|
-
$skip: offset,
|
|
2266
|
-
},
|
|
2267
|
-
{
|
|
2268
|
-
$limit: limit,
|
|
2269
|
-
} );
|
|
2270
1782
|
}
|
|
2271
1783
|
if ( inputData.isExport ) {
|
|
2272
1784
|
query.push(
|
|
@@ -2277,32 +1789,10 @@ export async function clientMetrics( req, res ) {
|
|
|
2277
1789
|
'Brand Name': '$clientName',
|
|
2278
1790
|
'Brand Id': '$clientId',
|
|
2279
1791
|
'Product Type': '$value',
|
|
2280
|
-
// 'Completed Percentage': '$completionPercentage',
|
|
2281
|
-
'Installed Stores': '$installedStore',
|
|
2282
|
-
'Audit Stores': '$totalFilesCount',
|
|
2283
|
-
'Inprogress Stores': '$inprogressStoresCount',
|
|
2284
|
-
'Not Assigned Stores': '$notAssignedCount',
|
|
2285
|
-
// 'Not Assigned Stores': '$notAssignedStores',
|
|
2286
|
-
'Completed Stores': '$completedStores',
|
|
2287
|
-
'Status': '$clientStatus',
|
|
2288
|
-
},
|
|
2289
|
-
},
|
|
2290
|
-
);
|
|
2291
|
-
|
|
2292
|
-
MappingQuery.push(
|
|
2293
|
-
{
|
|
2294
|
-
$project: {
|
|
2295
|
-
'_id': 0,
|
|
2296
|
-
'File Date': '$fileDate',
|
|
2297
|
-
'Brand Name': '$clientName',
|
|
2298
|
-
'Brand Id': '$clientId',
|
|
2299
|
-
'Product Type': '$value',
|
|
2300
|
-
// 'Completed Percentage': '$completionPercentage',
|
|
2301
1792
|
'Installed Stores': '$installedStore',
|
|
2302
1793
|
'Audit Stores': '$totalFilesCount',
|
|
2303
1794
|
'Inprogress Stores': '$inprogressStoresCount',
|
|
2304
1795
|
'Not Assigned Stores': '$notAssignedCount',
|
|
2305
|
-
// 'Not Assigned Stores': '$notAssignedStores',
|
|
2306
1796
|
'Completed Stores': '$completedStores',
|
|
2307
1797
|
'Status': '$clientStatus',
|
|
2308
1798
|
},
|
|
@@ -2310,7 +1800,7 @@ export async function clientMetrics( req, res ) {
|
|
|
2310
1800
|
);
|
|
2311
1801
|
}
|
|
2312
1802
|
|
|
2313
|
-
const result =
|
|
1803
|
+
const result = await aggregateTraxAuditData( query );
|
|
2314
1804
|
if ( result.length == 0 ) {
|
|
2315
1805
|
return res.sendError( 'No Data Found', 204 );
|
|
2316
1806
|
}
|
|
@@ -2321,7 +1811,7 @@ export async function clientMetrics( req, res ) {
|
|
|
2321
1811
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
2322
1812
|
} catch ( error ) {
|
|
2323
1813
|
const err = error.error || 'Internal Server Error';
|
|
2324
|
-
logger.
|
|
1814
|
+
logger.error( { error: error, message: req.body, function: 'clientMetrics' } );
|
|
2325
1815
|
return res.sendError( err, 500 );
|
|
2326
1816
|
}
|
|
2327
1817
|
}
|
|
@@ -2345,7 +1835,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2345
1835
|
}
|
|
2346
1836
|
|
|
2347
1837
|
if ( inputData.filterByStatus && inputData.filterByStatus?.length > 0 ) {
|
|
2348
|
-
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
1838
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? filter.push( { status: { $in: inputData.filterByStatus } } ) : filter.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
2349
1839
|
}
|
|
2350
1840
|
|
|
2351
1841
|
if ( inputData.filterByAuditType && inputData.filterByAuditType?.length > 0 ) {
|
|
@@ -2394,6 +1884,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2394
1884
|
fileDate: 1,
|
|
2395
1885
|
storeId: 1,
|
|
2396
1886
|
storeName: '$stores.storeName',
|
|
1887
|
+
zoneName: 1,
|
|
2397
1888
|
clientName: '',
|
|
2398
1889
|
clientId: 1,
|
|
2399
1890
|
moduleType: 1,
|
|
@@ -2409,7 +1900,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2409
1900
|
userId: {
|
|
2410
1901
|
$arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], // need to check if no data
|
|
2411
1902
|
},
|
|
2412
|
-
// userId: 1,
|
|
2413
1903
|
auditType: 1,
|
|
2414
1904
|
beforeCount: 1,
|
|
2415
1905
|
afterCount: { $ifNull: [ '$afterCount', null ] },
|
|
@@ -2485,6 +1975,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2485
1975
|
fileDate: 1,
|
|
2486
1976
|
storeId: 1,
|
|
2487
1977
|
storeName: 1,
|
|
1978
|
+
zoneName: 1,
|
|
2488
1979
|
userName: '$users.userName',
|
|
2489
1980
|
userEmail: '$users.userEmail',
|
|
2490
1981
|
clientId: 1,
|
|
@@ -2591,9 +2082,6 @@ export async function storeMetrics( req, res ) {
|
|
|
2591
2082
|
questionType: 1,
|
|
2592
2083
|
userComments: 1,
|
|
2593
2084
|
answer: 1,
|
|
2594
|
-
// userId: {
|
|
2595
|
-
// $arrayElemAt: [ '$userId', { $subtract: [ { $size: '$userId' }, 1 ] } ], //need to check if no data
|
|
2596
|
-
// },
|
|
2597
2085
|
userId: 1,
|
|
2598
2086
|
auditType: 1,
|
|
2599
2087
|
beforeCount: 1,
|
|
@@ -2731,6 +2219,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2731
2219
|
{ clientName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2732
2220
|
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2733
2221
|
{ storeName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2222
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2734
2223
|
{ userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2735
2224
|
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2736
2225
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
@@ -2778,7 +2267,7 @@ export async function storeMetrics( req, res ) {
|
|
|
2778
2267
|
},
|
|
2779
2268
|
);
|
|
2780
2269
|
}
|
|
2781
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2270
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2782
2271
|
|
|
2783
2272
|
|
|
2784
2273
|
if ( count.length == 0 ) {
|
|
@@ -2802,7 +2291,10 @@ export async function storeMetrics( req, res ) {
|
|
|
2802
2291
|
$limit: limit,
|
|
2803
2292
|
} );
|
|
2804
2293
|
}
|
|
2805
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2294
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryQuery );
|
|
2295
|
+
if ( result.length == 0 ) {
|
|
2296
|
+
return res.sendError( 'No data Found', 204 );
|
|
2297
|
+
}
|
|
2806
2298
|
if ( inputData.isExport ) {
|
|
2807
2299
|
const exportdata = [];
|
|
2808
2300
|
result.forEach( ( element ) => {
|
|
@@ -2843,11 +2335,13 @@ export async function storeMetrics( req, res ) {
|
|
|
2843
2335
|
temp['Accuracy'] = element.accuracy;
|
|
2844
2336
|
break;
|
|
2845
2337
|
case 'uniform-detection':
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2338
|
+
temp['Before Count'] = element.beforeCount;
|
|
2339
|
+
temp['After Count'] = element.afterCount;
|
|
2340
|
+
temp['Status'] = toCamelCase( element.status );
|
|
2341
|
+
temp['Accuracy'] = element.accuracy;
|
|
2342
|
+
break;
|
|
2343
|
+
case 'hygiene':
|
|
2344
|
+
temp['Zone Name'] = element.zoneName;
|
|
2851
2345
|
temp['Before Count'] = element.beforeCount;
|
|
2852
2346
|
temp['After Count'] = element.afterCount;
|
|
2853
2347
|
temp['Status'] = toCamelCase( element.status );
|
|
@@ -2963,11 +2457,6 @@ export async function userMetrics( req, res ) {
|
|
|
2963
2457
|
beforeCount: 1,
|
|
2964
2458
|
afterCount: 1,
|
|
2965
2459
|
createdAt: 1,
|
|
2966
|
-
// mappingPerc: { $round: [
|
|
2967
|
-
// { $multiply: [
|
|
2968
|
-
// { $divide: [ '$afterCount', '$beforeCount' ] }, 100,
|
|
2969
|
-
// ] }, 2,
|
|
2970
|
-
// ] },
|
|
2971
2460
|
checkIntime: 1,
|
|
2972
2461
|
checkOutTime: 1,
|
|
2973
2462
|
differenceInSeconds: {
|
|
@@ -2986,7 +2475,6 @@ export async function userMetrics( req, res ) {
|
|
|
2986
2475
|
checkOutTime: 1,
|
|
2987
2476
|
moduleType: 1,
|
|
2988
2477
|
value: 1,
|
|
2989
|
-
// mappingPerc: 1,
|
|
2990
2478
|
hours: { $floor: { $divide: [ '$differenceInSeconds', 3600 ] } },
|
|
2991
2479
|
minutes: { $floor: { $divide: [ { $mod: [ '$differenceInSeconds', 3600 ] }, 60 ] } },
|
|
2992
2480
|
seconds: { $mod: [ '$differenceInSeconds', 60 ] },
|
|
@@ -3006,7 +2494,6 @@ export async function userMetrics( req, res ) {
|
|
|
3006
2494
|
moduleType: 1,
|
|
3007
2495
|
value: 1,
|
|
3008
2496
|
createdAt: 1,
|
|
3009
|
-
// mappingPerc: 1,
|
|
3010
2497
|
hours: {
|
|
3011
2498
|
$cond: {
|
|
3012
2499
|
if: { $lt: [ '$hours', 10 ] },
|
|
@@ -3045,7 +2532,6 @@ export async function userMetrics( req, res ) {
|
|
|
3045
2532
|
value: {
|
|
3046
2533
|
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
|
|
3047
2534
|
},
|
|
3048
|
-
// mappingPerc: 1,
|
|
3049
2535
|
workingHours: {
|
|
3050
2536
|
$concat: [ '$hours', ':', '$minutes', ':', '$seconds' ],
|
|
3051
2537
|
},
|
|
@@ -3090,7 +2576,6 @@ export async function userMetrics( req, res ) {
|
|
|
3090
2576
|
value: {
|
|
3091
2577
|
$replaceAll: { input: '$moduleType', find: '-', replacement: ' ' },
|
|
3092
2578
|
},
|
|
3093
|
-
// mappingPerc: 1,
|
|
3094
2579
|
checkIntime: {
|
|
3095
2580
|
$dateToString: {
|
|
3096
2581
|
format: '%Y-%m-%d %H:%M:%S',
|
|
@@ -3130,7 +2615,7 @@ export async function userMetrics( req, res ) {
|
|
|
3130
2615
|
);
|
|
3131
2616
|
}
|
|
3132
2617
|
|
|
3133
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2618
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3134
2619
|
if ( count.length == 0 ) {
|
|
3135
2620
|
return res.sendError( 'No Data Found', 204 );
|
|
3136
2621
|
}
|
|
@@ -3152,8 +2637,8 @@ export async function userMetrics( req, res ) {
|
|
|
3152
2637
|
'Check OutTime': '$checkOutTime',
|
|
3153
2638
|
'Working Hours': '$workingHours',
|
|
3154
2639
|
'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
|
|
3155
|
-
// 'Mapping Percentage': '$mappingPerc',
|
|
3156
2640
|
};
|
|
2641
|
+
|
|
3157
2642
|
const YesNo = {
|
|
3158
2643
|
'_id': 0,
|
|
3159
2644
|
'User Name': '$userName',
|
|
@@ -3164,9 +2649,8 @@ export async function userMetrics( req, res ) {
|
|
|
3164
2649
|
'Check OutTime': '$checkOutTime',
|
|
3165
2650
|
'Working Hours': '$workingHours',
|
|
3166
2651
|
'Audited Date': { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
|
|
3167
|
-
// 'Mapping Percentage': '$mappingPerc',
|
|
3168
2652
|
};
|
|
3169
|
-
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?
|
|
2653
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?
|
|
3170
2654
|
query.push(
|
|
3171
2655
|
{
|
|
3172
2656
|
$project: detection,
|
|
@@ -3180,7 +2664,10 @@ export async function userMetrics( req, res ) {
|
|
|
3180
2664
|
}
|
|
3181
2665
|
|
|
3182
2666
|
|
|
3183
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2667
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2668
|
+
if ( result.length == 0 ) {
|
|
2669
|
+
return res.sendError( 'No Data Found', 204 );
|
|
2670
|
+
}
|
|
3184
2671
|
if ( inputData.isExport ) {
|
|
3185
2672
|
await download( result, res );
|
|
3186
2673
|
return;
|
|
@@ -3188,7 +2675,7 @@ export async function userMetrics( req, res ) {
|
|
|
3188
2675
|
return res.sendSuccess( { result: result, count: count.length } );
|
|
3189
2676
|
} catch ( error ) {
|
|
3190
2677
|
const err = error.error || 'Internal Server Error';
|
|
3191
|
-
logger.
|
|
2678
|
+
logger.error( { error: error, message: req.body, function: 'userMetrics' } );
|
|
3192
2679
|
return res.sendError( err, 500 );
|
|
3193
2680
|
}
|
|
3194
2681
|
}
|
|
@@ -3305,6 +2792,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3305
2792
|
$match: {
|
|
3306
2793
|
$or: [
|
|
3307
2794
|
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
2795
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3308
2796
|
{ fileDate: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3309
2797
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3310
2798
|
{ auditStatus: { $regex: inputData.searchValue, $options: 'i' } },
|
|
@@ -3324,7 +2812,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3324
2812
|
},
|
|
3325
2813
|
);
|
|
3326
2814
|
}
|
|
3327
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2815
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3328
2816
|
if ( count.length == 0 ) {
|
|
3329
2817
|
return res.sendError( 'No Data Found', 204 );
|
|
3330
2818
|
}
|
|
@@ -3340,7 +2828,7 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3340
2828
|
} );
|
|
3341
2829
|
}
|
|
3342
2830
|
|
|
3343
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
2831
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateUserEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3344
2832
|
if ( inputData.isExport ) {
|
|
3345
2833
|
const exportdata = [];
|
|
3346
2834
|
result.forEach( ( element ) => {
|
|
@@ -3369,8 +2857,10 @@ export async function pendingSummaryTable( req, res ) {
|
|
|
3369
2857
|
temp['Before Count'] = element.beforeCount;
|
|
3370
2858
|
break;
|
|
3371
2859
|
case 'uniform-detection':
|
|
3372
|
-
|
|
3373
|
-
|
|
2860
|
+
temp['Before Count'] = element.beforeCount;
|
|
2861
|
+
break;
|
|
2862
|
+
case 'hygiene':
|
|
2863
|
+
temp['Zone Name'] = element.zoneName;
|
|
3374
2864
|
temp['Before Count'] = element.beforeCount;
|
|
3375
2865
|
break;
|
|
3376
2866
|
}
|
|
@@ -3536,7 +3026,7 @@ export async function overAllAuditSummary( req, res ) {
|
|
|
3536
3026
|
},
|
|
3537
3027
|
];
|
|
3538
3028
|
|
|
3539
|
-
const storeAudit = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3029
|
+
const storeAudit = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )?await aggregateStoreEmpDetection( storeAuditQuery ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3540
3030
|
if ( storeAudit.length > 0 ) {
|
|
3541
3031
|
temp.inprogressStores= storeAudit[0].inprogressStores;
|
|
3542
3032
|
temp.completedStores = storeAudit[0].completedStores;
|
|
@@ -3724,7 +3214,7 @@ export async function summarySplit( req, res ) {
|
|
|
3724
3214
|
},
|
|
3725
3215
|
},
|
|
3726
3216
|
];
|
|
3727
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3217
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( binaryAuditQuery );
|
|
3728
3218
|
const totalCount = await aggregateTraxAuditData( totalQuery );
|
|
3729
3219
|
result[0].totalCount = totalCount[0]?.total;
|
|
3730
3220
|
return res.sendSuccess( { result: result.length> 0? result[0]: temp } );
|
|
@@ -3754,7 +3244,7 @@ export async function overviewTable( req, res ) {
|
|
|
3754
3244
|
}
|
|
3755
3245
|
|
|
3756
3246
|
if ( inputData.filterByStatus.length > 0 ) {
|
|
3757
|
-
[ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3247
|
+
[ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? filters.push( { status: { $in: inputData.filterByStatus } } ):filters.push( { auditStatus: { $in: inputData.filterByStatus } } );
|
|
3758
3248
|
}
|
|
3759
3249
|
|
|
3760
3250
|
const query =[
|
|
@@ -3769,6 +3259,7 @@ export async function overviewTable( req, res ) {
|
|
|
3769
3259
|
_id: 0,
|
|
3770
3260
|
storeId: 1,
|
|
3771
3261
|
clientId: 1,
|
|
3262
|
+
zoneName: 1,
|
|
3772
3263
|
streamName: 1,
|
|
3773
3264
|
tempId: 1,
|
|
3774
3265
|
question: 1,
|
|
@@ -3786,41 +3277,14 @@ export async function overviewTable( req, res ) {
|
|
|
3786
3277
|
auditType: 1,
|
|
3787
3278
|
status: 1,
|
|
3788
3279
|
auditStatus: 1,
|
|
3789
|
-
// userId: 1,
|
|
3790
3280
|
},
|
|
3791
3281
|
},
|
|
3792
|
-
// {
|
|
3793
|
-
// $lookup: {
|
|
3794
|
-
// from: 'users',
|
|
3795
|
-
// let: { userId: '$userId' },
|
|
3796
|
-
// pipeline: [
|
|
3797
|
-
// {
|
|
3798
|
-
// $match: {
|
|
3799
|
-
// $expr: {
|
|
3800
|
-
// $eq: [ '$_id', '$$userId' ],
|
|
3801
|
-
// },
|
|
3802
|
-
// },
|
|
3803
|
-
// },
|
|
3804
|
-
// {
|
|
3805
|
-
// $project: {
|
|
3806
|
-
// userName: 1,
|
|
3807
|
-
// userEmail: '$email',
|
|
3808
|
-
// },
|
|
3809
|
-
// },
|
|
3810
|
-
// ], as: 'user',
|
|
3811
|
-
// },
|
|
3812
|
-
// },
|
|
3813
|
-
// {
|
|
3814
|
-
// $unwind: {
|
|
3815
|
-
// path: '$user',
|
|
3816
|
-
// preserveNullAndEmptyArrays: true,
|
|
3817
|
-
// },
|
|
3818
|
-
// },
|
|
3819
3282
|
{
|
|
3820
3283
|
$project: {
|
|
3821
3284
|
storeId: 1,
|
|
3822
3285
|
clientId: 1,
|
|
3823
3286
|
streamName: 1,
|
|
3287
|
+
zoneName: 1,
|
|
3824
3288
|
tempId: 1,
|
|
3825
3289
|
question: 1,
|
|
3826
3290
|
questionType: 1,
|
|
@@ -3834,8 +3298,6 @@ export async function overviewTable( req, res ) {
|
|
|
3834
3298
|
auditType: 1,
|
|
3835
3299
|
status: 1,
|
|
3836
3300
|
auditStatus: 1,
|
|
3837
|
-
// userName: '$user.userName',
|
|
3838
|
-
// userEmail: '$user.userEmail',
|
|
3839
3301
|
|
|
3840
3302
|
},
|
|
3841
3303
|
},
|
|
@@ -3846,6 +3308,7 @@ export async function overviewTable( req, res ) {
|
|
|
3846
3308
|
$or: [
|
|
3847
3309
|
{ storeId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3848
3310
|
{ clientId: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3311
|
+
{ zoneName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3849
3312
|
{ fileDate: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3850
3313
|
{ auditType: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3851
3314
|
{ status: { $regex: inputData.searchValue, $options: 'i' } },
|
|
@@ -3856,8 +3319,6 @@ export async function overviewTable( req, res ) {
|
|
|
3856
3319
|
{ question: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3857
3320
|
{ answer: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3858
3321
|
{ userComments: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3859
|
-
// { userName: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3860
|
-
// { userEmail: { $regex: inputData.searchValue, $options: 'i' } },
|
|
3861
3322
|
],
|
|
3862
3323
|
|
|
3863
3324
|
},
|
|
@@ -3871,7 +3332,7 @@ export async function overviewTable( req, res ) {
|
|
|
3871
3332
|
},
|
|
3872
3333
|
);
|
|
3873
3334
|
}
|
|
3874
|
-
const count = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3335
|
+
const count = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3875
3336
|
if ( count.length == 0 ) {
|
|
3876
3337
|
return res.sendError( 'No Data Found', 204 );
|
|
3877
3338
|
}
|
|
@@ -3886,7 +3347,7 @@ export async function overviewTable( req, res ) {
|
|
|
3886
3347
|
$limit: limit,
|
|
3887
3348
|
} );
|
|
3888
3349
|
}
|
|
3889
|
-
const result = [ 'mobile-detection', 'uniform-detection' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3350
|
+
const result = [ 'mobile-detection', 'uniform-detection', 'hygiene' ].includes( inputData.moduleType )? await aggregateStoreEmpDetection( query ) : await aggregateBinaryAudit( query );
|
|
3890
3351
|
if ( inputData.isExport ) {
|
|
3891
3352
|
const exportdata = [];
|
|
3892
3353
|
result.forEach( ( element ) => {
|
|
@@ -3923,11 +3384,13 @@ export async function overviewTable( req, res ) {
|
|
|
3923
3384
|
temp['Status'] = toCamelCase( element.status );
|
|
3924
3385
|
break;
|
|
3925
3386
|
case 'uniform-detection':
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3387
|
+
temp['Before Count'] = element.beforeCount;
|
|
3388
|
+
temp['After Count'] = element.afterCount;
|
|
3389
|
+
temp['Audit Type'] = element.auditType;
|
|
3390
|
+
temp['Status'] = toCamelCase( element.status );
|
|
3391
|
+
break;
|
|
3392
|
+
case 'hygiene':
|
|
3393
|
+
temp['Zone Name'] = element.zoneName;
|
|
3931
3394
|
temp['Before Count'] = element.beforeCount;
|
|
3932
3395
|
temp['After Count'] = element.afterCount;
|
|
3933
3396
|
temp['Audit Type'] = element.auditType;
|
|
@@ -3951,6 +3414,7 @@ export async function overviewTable( req, res ) {
|
|
|
3951
3414
|
export async function getDetectionAuditFile( req, res ) {
|
|
3952
3415
|
try {
|
|
3953
3416
|
const openSearch = JSON.parse( process.env.OPENSEARCH );
|
|
3417
|
+
const url = JSON.parse( process.env.URL );
|
|
3954
3418
|
const inputData = req.query;
|
|
3955
3419
|
const previousDate = dayjs( new Date() ).subtract( 1, 'days' );
|
|
3956
3420
|
const data = await getDate( new Date( dayjs( previousDate ).format( 'YYYY-MM-DD' ) ), new Date() );
|
|
@@ -3960,6 +3424,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3960
3424
|
const end = data.end;
|
|
3961
3425
|
const fetchData = {};
|
|
3962
3426
|
let msg = {};
|
|
3427
|
+
// get user's inprogress files
|
|
3963
3428
|
const userQuery = [
|
|
3964
3429
|
{
|
|
3965
3430
|
$match: {
|
|
@@ -3983,62 +3448,61 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
3983
3448
|
|
|
3984
3449
|
const userDetails = await aggregateUserEmpDetection( userQuery );
|
|
3985
3450
|
logger.info( { userDetails: userDetails, function: 'userDetails' } );
|
|
3986
|
-
const auditStatus =
|
|
3987
|
-
userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
3451
|
+
const auditStatus = userDetails && userDetails.length > 0 ? userDetails[0].auditStatus : null;
|
|
3988
3452
|
switch ( auditStatus ) {
|
|
3989
3453
|
case null:
|
|
3990
|
-
const query = [
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
];
|
|
4002
|
-
const userAssign = await aggregateAssignAudit( query );
|
|
4003
|
-
if ( userAssign.length > 0 ) {
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
3454
|
+
// const query = [
|
|
3455
|
+
// {
|
|
3456
|
+
// $match: {
|
|
3457
|
+
// $and: [
|
|
3458
|
+
// { userId: { $eq: req.user._id } },
|
|
3459
|
+
// { isCompleted: { $eq: false } },
|
|
3460
|
+
// { queueName: inputData.queueName },
|
|
3461
|
+
// { moduleType: inputData.moduleType },
|
|
3462
|
+
// ],
|
|
3463
|
+
// },
|
|
3464
|
+
// },
|
|
3465
|
+
// ];
|
|
3466
|
+
// const userAssign = await aggregateAssignAudit( query );
|
|
3467
|
+
// if ( userAssign.length > 0 ) {
|
|
3468
|
+
// logger.info( 'Hit in user assign', { inputData } );
|
|
3469
|
+
// userAssign[0].auditType == 'Audit' ?
|
|
3470
|
+
// ( msg = {
|
|
3471
|
+
// storeId: userAssign[0].storeId,
|
|
3472
|
+
// fileDate: userAssign[0].fileDate,
|
|
3473
|
+
// fileCount: userAssign[0].fileCount,
|
|
3474
|
+
// inputBucketName: userAssign[0].inputBucketName,
|
|
3475
|
+
// folderPath: userAssign[0].folderPath,
|
|
3476
|
+
// } ) :
|
|
3477
|
+
// ( msg = {
|
|
3478
|
+
// storeId: userAssign[0].storeId,
|
|
3479
|
+
// fileDate: userAssign[0].fileDate,
|
|
3480
|
+
// auditType: userAssign[0].auditType,
|
|
3481
|
+
// fileCount: userAssign[0].fileCount,
|
|
3482
|
+
// inputBucketName: userAssign[0].inputBucketName,
|
|
3483
|
+
// folderPath: userAssign[0].folderPath,
|
|
3484
|
+
// } );
|
|
3485
|
+
// await updateOneAssignAudit(
|
|
3486
|
+
// { _id: userAssign[0]._id },
|
|
3487
|
+
// { isCompleted: true },
|
|
3488
|
+
// );
|
|
3489
|
+
// logger.info( 'Hit in auditUserAssignModel updateOne', {
|
|
3490
|
+
// _id: userAssign[0]._id,
|
|
3491
|
+
// isCompleted: true,
|
|
3492
|
+
// } );
|
|
3493
|
+
// } else {
|
|
3494
|
+
logger.info( 'Hit in new file', { inputData } );
|
|
3495
|
+
const consumer = await sqsReceive( inputData.queueName );
|
|
3496
|
+
if ( !consumer ) {
|
|
3497
|
+
logger.error( {
|
|
3498
|
+
error: consumer,
|
|
3499
|
+
function: `getAuditFile - ${inputData.moduleType}`,
|
|
3500
|
+
message: 'SQS Receive queue is empty',
|
|
4028
3501
|
} );
|
|
4029
|
-
|
|
4030
|
-
logger.info( 'Hit in new file', { inputData } );
|
|
4031
|
-
const consumer = await sqsReceive( inputData.queueName );
|
|
4032
|
-
if ( !consumer ) {
|
|
4033
|
-
logger.error( {
|
|
4034
|
-
error: consumer,
|
|
4035
|
-
function: 'getAuditFile',
|
|
4036
|
-
message: 'SQS Receive queue is empty',
|
|
4037
|
-
} );
|
|
4038
|
-
return res.sendError( `${inputData.queueName} is Empty`, 204 );
|
|
4039
|
-
}
|
|
4040
|
-
msg = JSON.parse( consumer );
|
|
3502
|
+
return res.sendError( `${inputData.queueName} is Empty`, 204 );
|
|
4041
3503
|
}
|
|
3504
|
+
msg = JSON.parse( consumer );
|
|
3505
|
+
// }
|
|
4042
3506
|
break;
|
|
4043
3507
|
|
|
4044
3508
|
case 'drafted':
|
|
@@ -4069,6 +3533,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4069
3533
|
const file = {
|
|
4070
3534
|
auditId: userDetails[0]._id,
|
|
4071
3535
|
storeId: userDetails[0].storeId,
|
|
3536
|
+
zoneName: userDetails[0].zoneName,
|
|
4072
3537
|
fileDate: userDetails[0].fileDate,
|
|
4073
3538
|
auditType: userDetails[0].auditType,
|
|
4074
3539
|
queueName: log.queueName,
|
|
@@ -4133,6 +3598,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4133
3598
|
default:
|
|
4134
3599
|
msg = {
|
|
4135
3600
|
storeId: userDetails[0].storeId,
|
|
3601
|
+
zoneName: userDetails[0].zoneName,
|
|
4136
3602
|
fileDate: userDetails[0].fileDate,
|
|
4137
3603
|
auditType: userDetails[0].auditType,
|
|
4138
3604
|
fileCount: userDetails[0].beforeCount,
|
|
@@ -4141,112 +3607,12 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4141
3607
|
};
|
|
4142
3608
|
break;
|
|
4143
3609
|
}
|
|
4144
|
-
// if ( msg.auditType === 'ReAudit' ) {
|
|
4145
|
-
// logger.info( 'Hit in user ReAudit', { inputData } );
|
|
4146
|
-
// let reauditInsert = {};
|
|
4147
|
-
// const [ filterData, auditImage ] = await Promise.all( [
|
|
4148
|
-
// getFilterData( msg ),
|
|
4149
|
-
// getAuditImage( msg ),
|
|
4150
|
-
// ] );
|
|
4151
|
-
// if ( filterData.statusCode == 404 || auditImage.statusCode == 404 ) {
|
|
4152
|
-
// return res.sendError( 'No Data found', 204 );
|
|
4153
|
-
// }
|
|
4154
|
-
// const reauditImg = await getReauditImg( filterData, auditImage );
|
|
4155
|
-
// if ( userDetails.length === 0 ) {
|
|
4156
|
-
// const [ day, month, year ] = msg.curr_date.split( '-' );
|
|
4157
|
-
// const temp = `${year}-${month}-${day}`;
|
|
4158
|
-
// let start = new Date( temp );
|
|
4159
|
-
// const userTimezoneOffset = start.getTimezoneOffset() * 60000;
|
|
4160
|
-
// start = new Date( start.getTime() - userTimezoneOffset );
|
|
4161
|
-
// start.setUTCHours( 0, 0, 0, 0 );
|
|
4162
|
-
// const record = {
|
|
4163
|
-
// userId: req.user._id,
|
|
4164
|
-
// storeId: msg.store_id,
|
|
4165
|
-
// clientId: msg.store_id.split( '-' )[0],
|
|
4166
|
-
// auditType: msg.audit_type || 'ReAudit',
|
|
4167
|
-
// fileDate: msg.curr_date,
|
|
4168
|
-
// queueName: inputData.queueName,
|
|
4169
|
-
// beforeCount: reauditImg.length,
|
|
4170
|
-
// auditStatus: 'inprogress',
|
|
4171
|
-
// fileDateISO: start,
|
|
4172
|
-
// timeSpent: 0,
|
|
4173
|
-
// startTime: new Date(),
|
|
4174
|
-
// zoneName: msg.zone_id,
|
|
4175
|
-
// moduleType: inputData.moduleType,
|
|
4176
|
-
// };
|
|
4177
|
-
// const query = {
|
|
4178
|
-
// storeId: msg.store_id,
|
|
4179
|
-
// zoneName: msg.zone_id,
|
|
4180
|
-
// fileDate: msg.curr_date,
|
|
4181
|
-
// moduleType: inputData.moduleType,
|
|
4182
|
-
// };
|
|
4183
|
-
// let storeRecord = {
|
|
4184
|
-
// userId: req.user._id,
|
|
4185
|
-
// auditType: msg.audit_type || 'ReAudit',
|
|
4186
|
-
// status: 'inprogress',
|
|
4187
|
-
// timeSpent: 0,
|
|
4188
|
-
// };
|
|
4189
|
-
// reauditInsert = await createUserAudit( record );
|
|
4190
|
-
|
|
4191
|
-
// await updateOneStoreAudit( query, storeRecord );
|
|
4192
|
-
// } else {
|
|
4193
|
-
// reauditInsert = userDetails[0];
|
|
4194
|
-
// }
|
|
4195
|
-
// const userdata = await findOneUser( { _id: req.user._id } );
|
|
4196
|
-
// if ( inputData.nextId ) {
|
|
4197
|
-
// const logData = {
|
|
4198
|
-
// userId: req.user._id,
|
|
4199
|
-
// userName: userdata.name,
|
|
4200
|
-
// logType: 'audit',
|
|
4201
|
-
// logSubType: 'auditStart',
|
|
4202
|
-
// logData: {
|
|
4203
|
-
// fileDate: msg.curr_date,
|
|
4204
|
-
// auditType: msg.audit_type,
|
|
4205
|
-
// storeId: msg.store_id,
|
|
4206
|
-
// clientName: inputData.queueName,
|
|
4207
|
-
// auditId: reauditInsert._id,
|
|
4208
|
-
// zoneName: msg.zone_id,
|
|
4209
|
-
// moduleType: inputData.moduleType,
|
|
4210
|
-
// },
|
|
4211
|
-
// createdAt: new Date(),
|
|
4212
|
-
// };
|
|
4213
|
-
// await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4214
|
-
// }
|
|
4215
|
-
|
|
4216
|
-
// const storeQuery = {
|
|
4217
|
-
// storeId: msg.store_id,
|
|
4218
|
-
// };
|
|
4219
|
-
// const storeFields = {
|
|
4220
|
-
// storeId: 1,
|
|
4221
|
-
// storeName: 1,
|
|
4222
|
-
// address: '$storeProfile.address',
|
|
4223
|
-
// };
|
|
4224
|
-
// const storeInfo = await findOneStore( storeQuery, storeFields );
|
|
4225
|
-
// return res.sendSuccess( {
|
|
4226
|
-
// result: reauditImg,
|
|
4227
|
-
// count: reauditImg.length,
|
|
4228
|
-
// storeId: storeInfo?.storeId,
|
|
4229
|
-
// storeName: storeInfo?.storeName,
|
|
4230
|
-
// address: storeInfo?.address || '',
|
|
4231
|
-
// file: {
|
|
4232
|
-
// store_id: msg.store_id,
|
|
4233
|
-
// file_date: msg.curr_date,
|
|
4234
|
-
// type: msg.audit_type || 'ReAudit',
|
|
4235
|
-
// queueName: inputData.queueName,
|
|
4236
|
-
// auditId: reauditInsert._id,
|
|
4237
|
-
// userId: reauditInsert.userId,
|
|
4238
|
-
// zoneName: msg.zone_id,
|
|
4239
|
-
// moduleType: inputData.moduleType,
|
|
4240
|
-
// },
|
|
4241
|
-
// isDraft: reauditInsert.isDraft,
|
|
4242
|
-
// } );
|
|
4243
|
-
// } to wor for reAudit concept
|
|
4244
3610
|
const storeId = msg.storeId;
|
|
4245
3611
|
const fileDate = msg.fileDate;
|
|
4246
3612
|
|
|
4247
3613
|
const files = [];
|
|
4248
3614
|
let insertData = {};
|
|
4249
|
-
fetchData.Bucket = msg.inputBucketName;
|
|
3615
|
+
fetchData.Bucket = msg.inputBucketName;
|
|
4250
3616
|
fetchData.file_path = msg.folderPath;
|
|
4251
3617
|
if ( inputData.limit ) {
|
|
4252
3618
|
fetchData.MaxKeys = inputData.limit;
|
|
@@ -4257,22 +3623,22 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4257
3623
|
const list = await listFileByPath( fetchData );
|
|
4258
3624
|
const folderPath = list.data;
|
|
4259
3625
|
const nextQuery = list.pageToken;
|
|
4260
|
-
|
|
3626
|
+
const bucketCDN = inputData.moduleType=='hygiene' ? url.hygieneInput : url.traxAuditInput;
|
|
4261
3627
|
if ( folderPath?.length > 0 ) {
|
|
4262
3628
|
for ( let i = 0; i < folderPath.length; i++ ) {
|
|
4263
3629
|
const img = folderPath[i].Key.split( '/' );
|
|
4264
3630
|
const image = img[3].split( '.' );
|
|
4265
3631
|
const indexes = image[0].split( '_' );
|
|
4266
|
-
|
|
4267
|
-
const data = await signedUrl( fetchData );
|
|
3632
|
+
const Key = folderPath[i].Key;
|
|
3633
|
+
const data = `${bucketCDN}${Key}`;// await signedUrl( fetchData );
|
|
4268
3634
|
const mapimg = {
|
|
4269
3635
|
img_path: data,
|
|
4270
|
-
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` :image[0],
|
|
3636
|
+
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}` : inputData.moduleType=='hygiene'?`${indexes[2]}-${indexes[3]}`:image[0],
|
|
4271
3637
|
img_id: img[3],
|
|
4272
3638
|
};
|
|
4273
3639
|
files.push( {
|
|
4274
3640
|
img_path: data,
|
|
4275
|
-
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}
|
|
3641
|
+
img_name: inputData.moduleType=='mobile-detection'?`${indexes[0]}-${indexes[3]}`: inputData.moduleType=='hygiene'?`${indexes[2]}-${indexes[3]}`:image[0],
|
|
4276
3642
|
img_id: img[3],
|
|
4277
3643
|
selected: false,
|
|
4278
3644
|
dropped: false,
|
|
@@ -4292,6 +3658,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4292
3658
|
const record = {
|
|
4293
3659
|
userId: req.user._id,
|
|
4294
3660
|
storeId: msg.storeId,
|
|
3661
|
+
zoneName: msg.zoneName,
|
|
4295
3662
|
clientId: msg.storeId.split( '-' )[0],
|
|
4296
3663
|
auditType: msg.auditType || 'Audit',
|
|
4297
3664
|
fileDate: msg.fileDate,
|
|
@@ -4307,12 +3674,14 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4307
3674
|
};
|
|
4308
3675
|
const query = {
|
|
4309
3676
|
storeId: msg.storeId,
|
|
3677
|
+
zoneName: msg.zoneName,
|
|
4310
3678
|
fileDate: msg.fileDate,
|
|
4311
3679
|
moduleType: inputData.moduleType,
|
|
4312
3680
|
};
|
|
4313
3681
|
const storeRecord = {
|
|
4314
3682
|
userId: req.user._id,
|
|
4315
3683
|
storeId: msg.storeId,
|
|
3684
|
+
zoneName: msg.zoneName,
|
|
4316
3685
|
clientId: msg.storeId.split( '-' )[0],
|
|
4317
3686
|
auditType: msg.auditType || 'Audit',
|
|
4318
3687
|
fileDate: msg.fileDate,
|
|
@@ -4334,7 +3703,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4334
3703
|
} else {
|
|
4335
3704
|
logger.error( {
|
|
4336
3705
|
error: { folderPath: folderPath, nextQuery: nextQuery },
|
|
4337
|
-
function:
|
|
3706
|
+
function: `getAuditFile - ${inputData.moduleType }`,
|
|
4338
3707
|
message: 'Bucket image data not availale',
|
|
4339
3708
|
} );
|
|
4340
3709
|
return res.sendError( 'Bucket is Empty', 204 );
|
|
@@ -4358,6 +3727,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4358
3727
|
fileDate: insertData.fileDate,
|
|
4359
3728
|
auditType: insertData.auditType,
|
|
4360
3729
|
storeId: storeId,
|
|
3730
|
+
zoneName: insertData.zoneName,
|
|
4361
3731
|
clientName: inputData.queueName,
|
|
4362
3732
|
auditId: insertData._id,
|
|
4363
3733
|
moduleType: inputData.moduleType,
|
|
@@ -4376,6 +3746,7 @@ export async function getDetectionAuditFile( req, res ) {
|
|
|
4376
3746
|
file: {
|
|
4377
3747
|
queueName: inputData.queueName,
|
|
4378
3748
|
storeId: storeId,
|
|
3749
|
+
zoneName: insertData.zoneName,
|
|
4379
3750
|
fileDate: fileDate,
|
|
4380
3751
|
auditType: msg.auditType || 'Audit',
|
|
4381
3752
|
auditId: insertData._id,
|
|
@@ -4416,11 +3787,13 @@ export async function saveDraft( req, res ) {
|
|
|
4416
3787
|
isDraft: true,
|
|
4417
3788
|
auditStatus: 'drafted',
|
|
4418
3789
|
};
|
|
4419
|
-
|
|
3790
|
+
let storeQuery = {
|
|
4420
3791
|
storeId: inputData.storeId,
|
|
4421
3792
|
fileDate: inputData.fileDate,
|
|
4422
3793
|
};
|
|
4423
3794
|
|
|
3795
|
+
inputData?.zoneName ? storeQuery['zoneName'] = inputData?.zoneName : null;
|
|
3796
|
+
|
|
4424
3797
|
let storeRecord = {
|
|
4425
3798
|
status: 'drafted',
|
|
4426
3799
|
};
|
|
@@ -4447,6 +3820,7 @@ export async function saveDraft( req, res ) {
|
|
|
4447
3820
|
fileDate: inputData.fileDate,
|
|
4448
3821
|
auditType: inputData.auditType,
|
|
4449
3822
|
storeId: inputData.storeId,
|
|
3823
|
+
zoneName: inputData?.zoneName,
|
|
4450
3824
|
clientName: inputData.queueName,
|
|
4451
3825
|
beforeCount: inputData.totalCount,
|
|
4452
3826
|
afterCount: inputData.employeeCount,
|
|
@@ -4512,7 +3886,8 @@ export async function save( req, res ) {
|
|
|
4512
3886
|
const timeDifferenceInMinutes = currentTime.diff( isoDateTime, 'seconds' );
|
|
4513
3887
|
const getUserAuditData = await findOneUserEmpDetection( { _id: inputData.auditId } );
|
|
4514
3888
|
inputData.clientId = getUserAuditData.clientId;
|
|
4515
|
-
|
|
3889
|
+
let query ={ storeId: inputData.storeId, moduleType: inputData.moduleType, fileDate: inputData.fileDate };
|
|
3890
|
+
inputData?.zoneName? query['zoneName'] = inputData.zoneName : null;
|
|
4516
3891
|
const data = await updateOneEmpDetectionOutput( query, { $set: inputData }, { upsert: true } );
|
|
4517
3892
|
if ( data ) {
|
|
4518
3893
|
const userUpdated ={
|
|
@@ -4535,11 +3910,12 @@ export async function save( req, res ) {
|
|
|
4535
3910
|
{
|
|
4536
3911
|
fileDate: inputData.fileDate,
|
|
4537
3912
|
storeId: inputData.storeId,
|
|
3913
|
+
zoneName: inputData.zoneName,
|
|
4538
3914
|
moduleType: inputData.moduleType,
|
|
4539
3915
|
},
|
|
4540
3916
|
);
|
|
4541
3917
|
if ( !getFilePath ) {
|
|
4542
|
-
return res.sendError( '
|
|
3918
|
+
return res.sendError( 'SQS is not sent due to Inserted Data is not there', 400 );
|
|
4543
3919
|
}
|
|
4544
3920
|
const [ getStore, getClient ] = await Promise.all( [ findOneStore( { storeId: inputData.storeId }, { storeName: 1, storeProfile: 1, spocDetails: 1 } ), findOneClient( { clientId: inputData.clientId }, { clientName: 1 } ) ] );
|
|
4545
3921
|
|
|
@@ -4548,31 +3924,33 @@ export async function save( req, res ) {
|
|
|
4548
3924
|
for ( let i =0; i<inputData?.employee.length; i++ ) {
|
|
4549
3925
|
tempId.push( inputData?.employee[i].img_id );
|
|
4550
3926
|
}
|
|
3927
|
+
if ( inputData.moduleType !== 'hygiene' ) {
|
|
3928
|
+
const sqsProduceQueue = {
|
|
3929
|
+
QueueUrl: `${sqs.url}${sqs.uniformOutput}`,
|
|
3930
|
+
MessageBody: JSON.stringify( {
|
|
3931
|
+
storeId: inputData.storeId,
|
|
3932
|
+
storeName: getStore?.storeName,
|
|
3933
|
+
zoneName: inputData?.zoneName,
|
|
3934
|
+
fileDate: inputData?.fileDate,
|
|
3935
|
+
moduleType: inputData?.moduleType,
|
|
3936
|
+
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
3937
|
+
tempId: tempId,
|
|
3938
|
+
count: inputData?.employeeCount,
|
|
3939
|
+
folderPath: getFilePath?.sqs?.Body?.folderPath,
|
|
3940
|
+
} ),
|
|
3941
|
+
};
|
|
3942
|
+
const sqsQueue = await sendMessageToQueue(
|
|
3943
|
+
sqsProduceQueue.QueueUrl,
|
|
3944
|
+
sqsProduceQueue.MessageBody,
|
|
3945
|
+
);
|
|
4551
3946
|
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
inputBucketName: getFilePath?.sqs?.Body?.inputBucketName,
|
|
4560
|
-
tempId: tempId,
|
|
4561
|
-
count: inputData.employeeCount,
|
|
4562
|
-
folderPath: getFilePath?.sqs?.Body?.folderPath,
|
|
4563
|
-
} ),
|
|
4564
|
-
};
|
|
4565
|
-
const sqsQueue = await sendMessageToQueue(
|
|
4566
|
-
sqsProduceQueue.QueueUrl,
|
|
4567
|
-
sqsProduceQueue.MessageBody,
|
|
4568
|
-
);
|
|
4569
|
-
|
|
4570
|
-
if ( sqsQueue.statusCode ) {
|
|
4571
|
-
logger.error( {
|
|
4572
|
-
error: `${sqsQueue}`,
|
|
4573
|
-
type: 'UPLOAD_ERROR',
|
|
4574
|
-
} );
|
|
4575
|
-
return res.sendError( 'SQS not sent', 500 );
|
|
3947
|
+
if ( sqsQueue.statusCode ) {
|
|
3948
|
+
logger.error( {
|
|
3949
|
+
error: `${sqsQueue}`,
|
|
3950
|
+
type: 'UPLOAD_ERROR',
|
|
3951
|
+
} );
|
|
3952
|
+
return res.sendError( 'SQS not sent', 500 );
|
|
3953
|
+
}
|
|
4576
3954
|
}
|
|
4577
3955
|
}
|
|
4578
3956
|
|
|
@@ -4583,6 +3961,7 @@ export async function save( req, res ) {
|
|
|
4583
3961
|
clientName: getClient?.clientName,
|
|
4584
3962
|
storeId: inputData.storeId,
|
|
4585
3963
|
storeName: getStore?.storeName,
|
|
3964
|
+
zoneName: inputData?.zoneName,
|
|
4586
3965
|
spocName: getStore?.spocDetails? getStore?.spocDetails[0]?.name : '',
|
|
4587
3966
|
spocEmail: getStore?.spocDetails? getStore?.spocDetails[0]?.email:'',
|
|
4588
3967
|
spocContact: getStore?.spocDetails? getStore?.spocDetails[0].contact:'',
|
|
@@ -4605,6 +3984,7 @@ export async function save( req, res ) {
|
|
|
4605
3984
|
fileDate: getUserAuditData?.fileDate,
|
|
4606
3985
|
auditType: getUserAuditData?.auditType,
|
|
4607
3986
|
storeId: getUserAuditData?.storeId,
|
|
3987
|
+
zoneName: inputData?.zoneName,
|
|
4608
3988
|
moduleType: getUserAuditData?.moduleType,
|
|
4609
3989
|
queueName: req.userAudit?.queueName,
|
|
4610
3990
|
clientId: req.userAudit?.clientId,
|
|
@@ -4640,82 +4020,90 @@ export async function reTrigger( req, res ) {
|
|
|
4640
4020
|
const message = req.sqs;
|
|
4641
4021
|
const sqs = JSON.parse( process.env.SQS );
|
|
4642
4022
|
const getQueueName = await findOneClient( { clientId: req.audit.clientId }, { 'auditConfigs': 1 } );
|
|
4643
|
-
const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : getQueueName?.auditConfigs?.traxQueueName?.mobileDetection;
|
|
4023
|
+
const queueName = inputData.moduleType == 'uniform-detection' ? getQueueName?.auditConfigs?.traxQueueName?.uniformDetection : inputData.moduleType == 'mobile-detection' ?getQueueName?.auditConfigs?.traxQueueName?.mobileDetection : getQueueName?.auditConfigs?.traxQueueName?.hygiene;
|
|
4644
4024
|
if ( !getQueueName || queueName == '' ) {
|
|
4645
4025
|
return res.sendError( 'queueName does not create', 400 );
|
|
4646
4026
|
}
|
|
4647
|
-
|
|
4648
|
-
fileDate: message.fileDate,
|
|
4649
|
-
moduleType: message.moduleType, auditStatus: 'completed' } );
|
|
4650
|
-
const msg = {
|
|
4027
|
+
let getQuery ={
|
|
4651
4028
|
storeId: message.storeId,
|
|
4652
4029
|
fileDate: message.fileDate,
|
|
4653
|
-
moduleType: message.moduleType,
|
|
4654
|
-
inputBucketName: message.inputBucketName,
|
|
4655
|
-
questionType: message.questionType,
|
|
4656
|
-
question: message.question,
|
|
4657
|
-
folderPath: message.folderPath,
|
|
4658
|
-
fileCount: message.fileCount,
|
|
4659
|
-
auditType: getRecord > 0? 'ReAudit':'Audit',
|
|
4660
|
-
};
|
|
4661
|
-
const sqsProduceQueue = {
|
|
4662
|
-
QueueUrl: `${sqs.url}${queueName}`,
|
|
4663
|
-
MessageBody: JSON.stringify( msg ),
|
|
4030
|
+
moduleType: message.moduleType, auditStatus: 'completed',
|
|
4664
4031
|
};
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
const
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4032
|
+
inputData.moduleType == 'hygiene'? getQuery.zoneName = inputData?.zoneName : null;
|
|
4033
|
+
const getRecord = await countDocumentsUserEmpDetection( getQuery );
|
|
4034
|
+
const msg = {
|
|
4035
|
+
storeId: message.storeId,
|
|
4036
|
+
zoneName: message.zoneName,
|
|
4037
|
+
fileDate: message.fileDate,
|
|
4038
|
+
moduleType: message.moduleType,
|
|
4039
|
+
inputBucketName: message.inputBucketName,
|
|
4040
|
+
questionType: message.questionType,
|
|
4041
|
+
question: message.question,
|
|
4042
|
+
folderPath: message.folderPath,
|
|
4043
|
+
fileCount: message.fileCount,
|
|
4044
|
+
auditType: getRecord > 0? 'ReAudit':'Audit',
|
|
4045
|
+
};
|
|
4046
|
+
const sqsProduceQueue = {
|
|
4047
|
+
QueueUrl: `${sqs.url}${queueName}`,
|
|
4048
|
+
MessageBody: JSON.stringify( msg ),
|
|
4049
|
+
};
|
|
4050
|
+
const sqsQueue = await sendMessageToQueue( sqsProduceQueue.QueueUrl, sqsProduceQueue.MessageBody );
|
|
4051
|
+
if ( sqsQueue?.errorCode ) {
|
|
4052
|
+
const error = sqsQueue?.errorMsg;
|
|
4053
|
+
const code = sqsQueue?.errorCode;
|
|
4054
|
+
return res.sendError( error, code );
|
|
4055
|
+
} else {
|
|
4056
|
+
if ( req.audit.status !== 'completed' ) {
|
|
4057
|
+
const userRecord = {
|
|
4058
|
+
auditStatus: 'skipped',
|
|
4059
|
+
isDraft: false,
|
|
4060
|
+
};
|
|
4061
|
+
const query = {
|
|
4062
|
+
storeId: inputData.storeId,
|
|
4063
|
+
fileDate: inputData.fileDate,
|
|
4064
|
+
auditStatus: req.audit.status,
|
|
4065
|
+
moduleType: inputData.moduleType,
|
|
4066
|
+
|
|
4067
|
+
};
|
|
4068
|
+
inputData.moduleType == 'hygiene'? query.zoneName = inputData?.zoneName : null;
|
|
4069
|
+
await updateOneUserEmpDetection( query, userRecord );
|
|
4070
|
+
}
|
|
4071
|
+
|
|
4072
|
+
const storeQuery = {
|
|
4677
4073
|
storeId: inputData.storeId,
|
|
4678
4074
|
fileDate: inputData.fileDate,
|
|
4679
|
-
auditStatus: req.audit.status,
|
|
4680
4075
|
moduleType: inputData.moduleType,
|
|
4681
4076
|
|
|
4682
4077
|
};
|
|
4683
|
-
|
|
4684
|
-
}
|
|
4685
|
-
|
|
4686
|
-
const storeQuery = {
|
|
4687
|
-
storeId: inputData.storeId,
|
|
4688
|
-
fileDate: inputData.fileDate,
|
|
4689
|
-
moduleType: inputData.moduleType,
|
|
4690
|
-
|
|
4691
|
-
};
|
|
4078
|
+
inputData.moduleType == 'hygiene'? storeQuery.zoneName = inputData?.zoneName : null;
|
|
4692
4079
|
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4080
|
+
const storeRecord = {
|
|
4081
|
+
status: 'not_assign',
|
|
4082
|
+
};
|
|
4696
4083
|
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4084
|
+
await updateOneStoreEmpDetection( storeQuery, storeRecord );
|
|
4085
|
+
const logData = {
|
|
4086
|
+
userId: req.user._id,
|
|
4087
|
+
userName: req.user.userName,
|
|
4088
|
+
logType: 'traxAudit',
|
|
4089
|
+
logSubType: 'reTrigger',
|
|
4090
|
+
logData: {
|
|
4091
|
+
beforeCount: message.fileCount,
|
|
4092
|
+
afterCount: '',
|
|
4093
|
+
fileDate: inputData.fileDate,
|
|
4094
|
+
auditType: req.audit.auditType,
|
|
4095
|
+
storeId: inputData.storeId,
|
|
4096
|
+
zoneName: inputData.zoneName,
|
|
4097
|
+
moduleType: inputData.moduleType,
|
|
4098
|
+
queueName: queueName,
|
|
4099
|
+
triggerBy: req.user.userName,
|
|
4100
|
+
triggerId: req.user._id,
|
|
4101
|
+
},
|
|
4102
|
+
createdAt: new Date(),
|
|
4103
|
+
};
|
|
4104
|
+
await insertOpenSearchData( openSearch.auditLog, logData );
|
|
4105
|
+
}
|
|
4106
|
+
return res.sendSuccess( { result: 'The File has been Re-Triggered Succesfully' } );
|
|
4719
4107
|
} catch ( error ) {
|
|
4720
4108
|
const err = error.message;
|
|
4721
4109
|
logger.error( { error: error, message: req.body, function: 'reTrigger' } );
|