tango-app-api-infra 3.0.106-dev → 3.0.108-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tango-app-api-infra",
3
- "version": "3.0.106-dev",
3
+ "version": "3.0.108-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -302,7 +302,7 @@ export async function installationCard( req, res ) {
302
302
  onboardedStoresCount: onboardedCount,
303
303
  inactiveStoresCount: deactiveCount,
304
304
  installedStoresCount: installedCount-yettoInstallCount.length,
305
- yettoInstallCount: yettoInstallCount.length,
305
+ yettoInstallCount: yettoInstallCount.length-installFailedCount.length,
306
306
  installFailedCount: installFailedCount.length,
307
307
  infraIssues: response,
308
308
  } );
@@ -516,6 +516,43 @@ export async function infraIssuesTable( req, res ) {
516
516
  { $skip: ( req.body.offset - 1 ) * req.body.limit },
517
517
  { $limit: Number( req.body.limit ) },
518
518
  );
519
+ storesQuery.push( {
520
+ $lookup: {
521
+ from: 'clients',
522
+ let: { clientId: '$clientId' },
523
+ pipeline: [
524
+ {
525
+ $match: {
526
+ $expr: {
527
+ $and: [
528
+ { $eq: [ '$clientId', '$$clientId' ] },
529
+ ],
530
+ },
531
+ },
532
+
533
+ },
534
+ {
535
+ $project: {
536
+ clientName: 1,
537
+ },
538
+ },
539
+ ], as: 'client',
540
+ },
541
+ },
542
+ {
543
+ $unwind: { path: '$client', preserveNullAndEmptyArrays: true },
544
+ },
545
+ {
546
+ $project: {
547
+ clientName: '$client.clientName',
548
+ storeId: 1,
549
+ clientId: 1,
550
+ storeName: 1,
551
+ status: 1,
552
+ createdAt: 1,
553
+ },
554
+ },
555
+ );
519
556
  }
520
557
  let result;
521
558
  if ( req.body.infrafilterIssue == 'Live Stores' || req.body.infrafilterIssue == 'Total Stores' ) {
@@ -19,7 +19,9 @@ export async function createTicket( req, res ) {
19
19
  try {
20
20
  req.body.issueDate = new Date( req.body.Date );
21
21
  if ( req.body.issueType == 'infra' ) {
22
- req.body.ticketId = 'TE_INF_' + new Date().valueOf();
22
+ if ( !req.body.ticketId ) {
23
+ req.body.ticketId = 'TE_INF_' + new Date().valueOf();
24
+ }
23
25
  req.body.ticketActivity = [ {
24
26
  actionType: 'defaultInfra',
25
27
  timeStamp: new Date(),
@@ -28,7 +30,7 @@ export async function createTicket( req, res ) {
28
30
  } ];
29
31
  let ticketExists= await findOneTangoTicket( { ticketId: req.body.ticketId } );
30
32
  if ( ticketExists ) {
31
- res.status( 200 ).send( { storeId: req.body.storeId } );
33
+ return res.status( 200 ).send( { message: 'ticketId Exists', storeId: req.body.storeId } );
32
34
  }
33
35
  }
34
36
  if ( req.body.issueType == 'installation' ) {
@@ -70,7 +72,7 @@ export async function createTicket( req, res ) {
70
72
  downtimetotal = 0;
71
73
  }
72
74
 
73
-
75
+ console.log( req.body );
74
76
  let create = await createTangoTicket( req.body );
75
77
  let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
76
78
  const attachments = null;
@@ -237,7 +239,16 @@ export async function updateTicketIssue( req, res ) {
237
239
  'status': 'inprogress',
238
240
  };
239
241
  }
242
+ if ( req.body.issueType === 'infra' ) {
243
+ let client = await findOneClient( { clientId: req.body.basicDetails.clientId } );
244
+ let refreshdate = dayjs().add( client.ticketConfigs.refreshAlert, 'days' );
245
+ console.log( new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ) );
246
+ query = { ...query, 'ticketDetails.ticketRefreshTime': new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ),
247
+ };
248
+ }
249
+ console.log( query );
240
250
  let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, query );
251
+
241
252
  if ( req.body.ticketDetails.ticketType === 'refreshticket' ) {
242
253
  await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketDetails.refreshTicketStatus': 'identified' } );
243
254
  }
@@ -156,7 +156,7 @@ export async function updateRefreshTicket( req, res ) {
156
156
  try {
157
157
  for ( let ticket of req.body.TicketList ) {
158
158
  let getTicket = await findOneTangoTicket( { ticketId: ticket.ticketId } );
159
- await updateOneTangoTicket( { ticketId: ticket.ticketId }, { 'ticketDetails.ticketType': 'refreshticket' } );
159
+ await updateOneTangoTicket( { ticketId: ticket.ticketId }, { 'ticketDetails.ticketType': 'refreshticket', 'ticketDetails.refreshTicketStatus': 'notidentified' } );
160
160
  await updateOneTangoTicketunset( { ticketId: ticket.ticketId }, { 'ticketDetails.addressingUser': 1 } );
161
161
  let downTimeQuery = {
162
162
  'size': 1,
@@ -901,7 +901,7 @@ export async function edgeApplogsCheck( req, res ) {
901
901
  edgelog: findissue,
902
902
  storeId: ticket.basicDetails.storeId,
903
903
  primary: 'System Issues',
904
- secondary: [ 'Malware or Viruses' ],
904
+ secondary: [ 'Antivirus blockages' ],
905
905
  };
906
906
  updateIssue( findissueEdgeApp );
907
907
  finalresult.push( findissueEdgeApp );
@@ -920,7 +920,7 @@ export async function edgeApplogsCheck( req, res ) {
920
920
  storeId: ticket.basicDetails.storeId,
921
921
  edgelog: findissue.edgelog.data,
922
922
  primary: 'Camera Issues',
923
- secondary: [ 'Camera Not working/RTSP port not working' ],
923
+ secondary: [ 'Camera not working' ],
924
924
  };
925
925
  updateIssue( findissueEdgeApp );
926
926
  finalresult.push( findissueEdgeApp );
@@ -951,7 +951,7 @@ export async function edgeApplogsCheck( req, res ) {
951
951
  edgelog: findissue,
952
952
  storeId: ticket.basicDetails.storeId,
953
953
  primary: 'Internet Issues',
954
- secondary: [ 'Slow Internet Speed' ],
954
+ secondary: [ 'Internet slow' ],
955
955
  };
956
956
  updateIssue( findissueEdgeApp );
957
957
  finalresult.push( findissueEdgeApp );
@@ -62,7 +62,12 @@ export async function storeTicketList( req, res ) {
62
62
  $filter: {
63
63
  input: '$ticketActivity',
64
64
  as: 'item',
65
- cond: { $ne: [ '$$item.actionType', 'statusChange' ] },
65
+ cond: {
66
+ $and: [
67
+ { $ne: [ '$$item.actionType', 'statusChange' ] },
68
+ { $ne: [ '$$item.actionType', 'statusCheck' ] },
69
+ ],
70
+ },
66
71
  },
67
72
  },
68
73
  primaryIssue: {
@@ -284,173 +289,136 @@ export async function edgeAppLogTable( req, res ) {
284
289
  try {
285
290
  const store = await findOneStore( { storeId: req.body.storeId } );
286
291
  if ( !store ) {
287
- return res.sendError( 'Stores Not fond', 204 );
292
+ return res.sendError( 'Store Not found', 204 );
288
293
  }
289
- let startHour = store.storeProfile.open.split( ':' )[0];
290
- let endHour = store.storeProfile.close.split( ':' )[0];
294
+
295
+ let startHour = parseInt( store.storeProfile.open.split( ':' )[0], 10 );
296
+ let endHour = parseInt( store.storeProfile.close.split( ':' )[0], 10 );
291
297
  const interval = 60; // 1 hour in minutes
292
298
  const timeSlots = generateTimeSlots( startHour, endHour, interval, req );
299
+
300
+ const date = dayjs( timeSlots[0].from ).format( 'DD-MM-YYYY' );
301
+ const storeId = req.body.storeId;
302
+
303
+ const internetSpeedQuery = {
304
+ size: 100,
305
+ query: {
306
+ bool: {
307
+ must: [
308
+ { term: { 'log_type.keyword': 'Application' } },
309
+ { term: { 'store_date.keyword': date } },
310
+ { term: { 'storeId.keyword': storeId } },
311
+ { term: { 'log_subtype.keyword': 'Speed_Test' } },
312
+ ],
313
+ },
314
+ },
315
+ sort: [ { timestamp: { order: 'desc' } } ],
316
+ _source: [ 'data.upload_Speed', 'data.occuringTime' ],
317
+ };
318
+
319
+ const fileCountQuery = {
320
+ size: 100,
321
+ query: {
322
+ bool: {
323
+ must: [
324
+ { term: { 'log_type.keyword': 'Application' } },
325
+ { term: { 'store_date.keyword': date } },
326
+ { term: { 'storeId.keyword': storeId } },
327
+ { term: { 'log_subtype.keyword': 'Zip_File_Count' } },
328
+ ],
329
+ },
330
+ },
331
+ sort: [ { timestamp: { order: 'desc' } } ],
332
+ _source: [ 'data.files_pushed', 'data.files_generated', 'data.occuringTime' ],
333
+ };
334
+
335
+ const downTimeQuery = {
336
+ size: 100,
337
+ query: {
338
+ bool: {
339
+ must: [
340
+ { term: { 'doc.date.keyword': date } },
341
+ { term: { 'doc.store_id.keyword': storeId } },
342
+ ],
343
+ },
344
+ },
345
+ _source: [ 'doc.streamwise_downtime', 'doc.hour' ],
346
+ };
347
+
348
+ // Execute all queries in parallel
349
+ const [ speedTestResult, fileCountResult, downtimeResult ] = await Promise.all( [
350
+ getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, internetSpeedQuery ),
351
+ getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, fileCountQuery ),
352
+ getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery ),
353
+ ] );
354
+ // Process results
355
+ const speedTestData = speedTestResult?.body?.hits?.hits ?? [];
356
+ const fileCountData = fileCountResult?.body?.hits?.hits ?? [];
357
+ const downtimeData = downtimeResult?.body?.hits?.hits ?? [];
358
+
293
359
  for ( const obj of timeSlots ) {
360
+ const hour = obj.hour;
294
361
  obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
295
362
  obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
296
- let internetSpeedQuery = {
297
- 'query': {
298
- 'bool': {
299
- 'must': [
300
- {
301
- 'term': {
302
- 'log_type.keyword': 'Application',
303
- },
304
- },
305
- {
306
- 'term': {
307
- 'store_date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
308
- },
309
- },
310
- {
311
- 'term': {
312
- 'storeId.keyword': req.body.storeId,
313
- },
314
- },
315
- {
316
- 'term': {
317
- 'log_subtype.keyword': 'Speed_Test',
318
- },
319
- },
320
- ],
321
- },
322
- },
323
- 'sort': [
324
- { 'timestamp': { 'order': 'desc' } },
325
- ],
326
- };
327
- let speedTest = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, internetSpeedQuery );
328
- if ( speedTest&& speedTest.body.hits && speedTest.body.hits.hits.length > 0 ) {
329
- for ( const sourcedata of speedTest.body.hits.hits ) {
330
- if ( sourcedata._source ) {
331
- if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==obj.hour ) {
332
- const megabytes = bytesToMB( sourcedata._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 );
333
- obj.Internetspeed = megabytes+ ' MB/sec';
334
- }
335
- }
336
- }
337
- } else {
338
- obj.Internetspeed = '';
339
- }
340
- let FileCountQuery = {
341
- 'size': 1000,
342
- 'query': {
343
- 'bool': {
344
- 'must': [
345
- {
346
- 'term': {
347
- 'log_type.keyword': 'Application',
348
- },
349
- },
350
- {
351
- 'term': {
352
- 'store_date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
353
- },
354
- },
355
- {
356
- 'term': {
357
- 'storeId.keyword': req.body.storeId,
358
- },
359
- },
360
- {
361
- 'term': {
362
- 'log_subtype.keyword': 'Zip_File_Count',
363
- },
364
- },
365
- ],
366
363
 
367
- },
368
- },
364
+ // Internet speed
369
365
 
370
- 'sort': [
371
- { 'timestamp': { 'order': 'desc' } },
372
- ],
373
- };
374
- let newFilesCount = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, FileCountQuery );
375
- if ( newFilesCount&& newFilesCount.body.hits && newFilesCount.body.hits.hits.length > 0 ) {
376
- obj.files_pushed = 0;
377
- obj.files_generated = 0;
378
- for ( let sourcedata of newFilesCount.body.hits.hits ) {
379
- if ( sourcedata._source ) {
380
- if ( Number( sourcedata._source.data.occuringTime.split( ':' )[0] )==obj.hour ) {
381
- obj.files_pushed = obj.files_pushed+Number( sourcedata._source.data.files_pushed );
382
- obj.files_generated = obj.files_generated+Number( sourcedata._source.data.files_generated );
383
- }
384
- }
385
- }
386
- } else {
387
- obj.files_pushed = '';
388
- obj.files_generated = '';
389
- }
390
- let downTimeQuery = {
391
- 'size': 1,
392
- 'query': {
393
- 'bool': {
394
- 'must': [
395
- {
396
- 'term': {
397
- 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
398
- },
399
- },
400
- {
401
- 'term': {
402
- 'doc.store_id.keyword': req.body.storeId,
403
- },
404
- },
405
- {
406
- 'terms': {
407
- 'doc.hour.keyword': [ obj.hour ],
408
- },
409
- },
410
- ],
366
+ const speedTest = speedTestData.find(
367
+ ( item ) => Number( item._source.data.occuringTime.split( ':' )[0] ) === hour,
368
+ );
369
+ obj.Internetspeed = speedTest ? `${bytesToMB( speedTest._source.data.upload_Speed.split( '.' )[0] ).toFixed( 2 )} MB/sec` : '';
411
370
 
412
- },
413
- },
414
- };
415
- const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
416
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
417
- if ( streamwiseDowntime.length > 0 ) {
418
- const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
419
- return accumulator + currentValue.down_time;
420
- }, 0 );
421
- const average = sum / streamwiseDowntime.length;
422
- obj.downtime = Math.round( average );
371
+ // File counts
372
+ const fileCounts = fileCountData.filter(
373
+ ( item ) => Number( item._source.data.occuringTime.split( ':' )[0] ) === hour,
374
+ );
375
+ obj.files_pushed = fileCounts.reduce( ( sum, item ) => sum + Number( item._source.data.files_pushed ), 0 ) || '';
376
+ obj.files_generated = fileCounts.reduce( ( sum, item ) => sum + Number( item._source.data.files_generated ), 0 ) || '';
377
+
378
+ // Downtime
379
+
380
+ const downtime = downtimeData.find( ( item ) => Number( item._source.doc.hour ) === hour );
381
+
382
+ if ( downtime ) {
383
+ const streamwiseDowntime = downtime._source.doc.streamwise_downtime || [];
384
+ if ( streamwiseDowntime.length > 0 ) {
385
+ const sum = streamwiseDowntime.reduce( ( acc, cur ) => acc + cur.down_time, 0 );
386
+ const average = sum / streamwiseDowntime.length;
387
+ obj.downtime = Math.round( average );
388
+ } else {
389
+ obj.downtime = '';
390
+ }
423
391
  } else {
424
392
  obj.downtime = '';
425
393
  }
426
394
  }
395
+
427
396
  if ( req.body.export ) {
428
- const exportdata = [];
429
- timeSlots.forEach( ( element ) => {
430
- exportdata.push( {
431
- 'Time Stamp': element.startTime+ '-'+ element.endTime,
432
- 'Downtime': element.ticketId,
433
- 'Avg Internet Speed': element.Date,
434
- 'Files Genarated': element.issueClosedDate,
435
- 'Files Pushed': element.primaryIssue,
436
- } );
437
- } );
438
- await download( exportdata, res );
397
+ const exportData = timeSlots.map( ( element ) => ( {
398
+ 'Time Stamp': `${element.startTime}-${element.endTime}`,
399
+ 'Downtime': element.downtime,
400
+ 'Avg Internet Speed': element.Internetspeed,
401
+ 'Files Generated': element.files_generated,
402
+ 'Files Pushed': element.files_pushed,
403
+ } ) );
404
+ await download( exportData, res );
439
405
  return;
440
406
  }
407
+
441
408
  res.sendSuccess( timeSlots );
442
409
  } catch ( error ) {
443
- logger.error( { error: error, function: 'edgeAppLog' } );
410
+ logger.error( { error, function: 'edgeAppLog' } );
444
411
  return res.sendError( error, 500 );
445
412
  }
446
413
  }
414
+
447
415
  function bytesToMB( bytes ) {
448
416
  return bytes / ( 1024 * 1024 );
449
417
  }
450
418
  function generateTimeSlots( startHour, endHour, interval, req ) {
451
419
  try {
452
420
  const timeSlots = [];
453
- for ( let hour = startHour; hour <= endHour; hour++ ) {
421
+ for ( let hour = startHour; hour < endHour; hour++ ) {
454
422
  for ( let minute = 0; minute < 60; minute += interval ) {
455
423
  let isoDate = new Date();
456
424
 
@@ -496,7 +464,7 @@ export async function viewedgeAppLog( req, res ) {
496
464
 
497
465
 
498
466
  let appStartTimeQuery = {
499
- 'size': 1000,
467
+ 'size': 100,
500
468
  'query': {
501
469
  'bool': {
502
470
  'must': [
@@ -530,7 +498,7 @@ export async function viewedgeAppLog( req, res ) {
530
498
  response.appStartTime = appStartTime.body.hits.hits.length > 0 ? appStartTime.body.hits.hits[0]._source.data.occuringTime : '';
531
499
 
532
500
  let appQuitTimeQuery = {
533
- 'size': 1,
501
+ 'size': 100,
534
502
  'query': {
535
503
  'bool': {
536
504
  'must': [
@@ -571,7 +539,7 @@ export async function viewedgeAppLog( req, res ) {
571
539
  }
572
540
  }
573
541
  let appCrashTimeQuery = {
574
- 'size': 1,
542
+ 'size': 100,
575
543
  'query': {
576
544
  'bool': {
577
545
  'must': [
@@ -613,7 +581,7 @@ export async function viewedgeAppLog( req, res ) {
613
581
  }
614
582
  }
615
583
  const screenStatus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
616
- 'size': 1000,
584
+ 'size': 100,
617
585
  'query': {
618
586
  'bool': {
619
587
  'must': [
@@ -674,7 +642,7 @@ export async function viewedgeAppLog( req, res ) {
674
642
  response.screenStatus = differences.length>0?`${differences[0].minutes}Mins ${differences[0].seconds}Sec`:'';
675
643
  }
676
644
  const FileCountQuery = {
677
- 'size': 1000,
645
+ 'size': 100,
678
646
  'query': {
679
647
  'bool': {
680
648
  'must': [
@@ -726,7 +694,7 @@ export async function viewedgeAppLog( req, res ) {
726
694
 
727
695
 
728
696
  const antiVirus = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).edgeAppSystemLogs, {
729
- 'size': 1,
697
+ 'size': 100,
730
698
  'query': {
731
699
  'bool': {
732
700
  'must': [
@@ -849,27 +817,30 @@ export async function datewiseDowntime( req, res ) {
849
817
  try {
850
818
  const store = await findOneStore( { storeId: req.body.storeId } );
851
819
  if ( !store ) {
852
- return res.sendError( 'Stores Not fond', 204 );
820
+ return res.sendError( 'Store Not Found', 204 );
853
821
  }
854
- let startHour = store.storeProfile.open.split( ':' )[0];
855
- let endHour = store.storeProfile.close.split( ':' )[0];
856
-
857
- let datesArray = getDatesArray( req.body.fromDate, req.body.toDate );
858
- let paginatedDates = paginateArray( datesArray, req.body.offset, req.body.limit );
859
- let result = [];
860
- for ( const singleDate of paginatedDates ) {
861
- let inputData = {
822
+
823
+ const startHour = parseInt( store.storeProfile.open.split( ':' )[0], 10 );
824
+ const endHour = parseInt( store.storeProfile.close.split( ':' )[0], 10 );
825
+
826
+ const datesArray = getDatesArray( req.body.fromDate, req.body.toDate );
827
+ const paginatedDates = paginateArray( datesArray, req.body.offset, req.body.limit );
828
+
829
+ const resultPromises = paginatedDates.map( ( singleDate ) => {
830
+ const inputData = {
862
831
  start: startHour,
863
832
  end: endHour,
864
833
  interval: 60,
865
834
  };
866
835
  req.body.Date = singleDate;
867
- let storedata = await livecountCheck( inputData, req );
868
- result.push( storedata[0] );
869
- }
836
+ return livecountCheck( inputData, singleDate, req );
837
+ } );
838
+
839
+ const result = await Promise.all( resultPromises );
840
+
870
841
  res.sendSuccess( {
871
842
  count: datesArray.length,
872
- data: result,
843
+ data: result.flat(), // Flatten the array of arrays
873
844
  } );
874
845
  } catch ( error ) {
875
846
  logger.error( { error: error, function: 'datewiseDowntime' } );
@@ -880,55 +851,47 @@ export async function streamwiseDowntime( req, res ) {
880
851
  try {
881
852
  const store = await findOneStore( { storeId: req.body.storeId } );
882
853
  if ( !store ) {
883
- return res.sendError( 'Stores Not fond', 204 );
854
+ return res.sendError( 'Store not found', 204 );
884
855
  }
885
- let startHour = store.storeProfile.open.split( ':' )[0];
886
- let endHour = store.storeProfile.close.split( ':' )[0];
856
+
857
+ const startHour = store.storeProfile.open.split( ':' )[0];
858
+ const endHour = store.storeProfile.close.split( ':' )[0];
887
859
  const interval = 60; // 1 hour in minutes
888
860
  const TimeSlots = generateTimeSlots( startHour, endHour, interval, req );
889
- let timewise = [];
890
- for ( const obj of TimeSlots ) {
891
- obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
892
- obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
893
- let downTimeQuery = {
894
- 'size': 1,
895
- 'query': {
896
- 'bool': {
897
- 'must': [
898
- {
899
- 'term': {
900
- 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
901
- },
902
- },
903
- {
904
- 'term': {
905
- 'doc.store_id.keyword': req.body.storeId,
906
- },
907
- },
908
- {
909
- 'term': {
910
- 'doc.hour.keyword': obj.hour,
911
- },
912
- },
913
- ],
914
861
 
862
+ const parsedOpenSearch = JSON.parse( process.env.OPENSEARCH );
863
+ const downTimeIndex = parsedOpenSearch.downTimeHourly;
864
+
865
+ const batchRequests = TimeSlots.map( async ( obj ) => {
866
+ const formattedDate = dayjs( obj.from ).format( 'DD-MM-YYYY' );
867
+ const downTimeQuery = {
868
+ size: 1,
869
+ query: {
870
+ bool: {
871
+ must: [
872
+ { term: { 'doc.date.keyword': formattedDate } },
873
+ { term: { 'doc.store_id.keyword': req.body.storeId } },
874
+ { term: { 'doc.hour.keyword': obj.hour } },
875
+ ],
915
876
  },
916
877
  },
917
878
  };
918
- const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
919
879
 
920
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
921
- if ( streamwiseDowntime.length > 0 ) {
922
- for ( let stream of streamwiseDowntime ) {
923
- if ( stream.stream === req.body.stream ) {
924
- obj.downTime= stream.down_time;
925
- }
926
- }
927
- } else {
928
- obj.downTime= '';
929
- }
930
- timewise.push( obj );
931
- }
880
+ const downtime = await getOpenSearchData( downTimeIndex, downTimeQuery );
881
+ const streamwiseDowntime = downtime.body.hits.hits.length > 0 ?
882
+ downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
883
+
884
+ const foundStream = streamwiseDowntime.find( ( stream ) => stream.stream === req.body.stream );
885
+ return {
886
+ startTime: dayjs( obj.from ).format( 'hh:mm A' ),
887
+ endTime: dayjs( obj.to ).format( 'hh:mm A' ),
888
+ downTime: foundStream ? foundStream.down_time : '',
889
+ hour: obj.hour,
890
+
891
+ };
892
+ } );
893
+
894
+ const timewise = await Promise.all( batchRequests );
932
895
  res.sendSuccess( timewise );
933
896
  } catch ( error ) {
934
897
  logger.error( { error: error, function: 'streamwiseDowntime' } );
@@ -936,73 +899,61 @@ export async function streamwiseDowntime( req, res ) {
936
899
  }
937
900
  }
938
901
 
939
- export async function livecountCheck( inputData, req ) {
940
- return new Promise( async ( Resolve, Reject ) => {
941
- try {
942
- let TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
943
- let timewise = [];
944
- for ( const obj of TimeSlots ) {
945
- obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
946
- obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
947
- let downTimeQuery = {
948
- 'size': 1,
949
- 'query': {
950
- 'bool': {
951
- 'must': [
952
- {
953
- 'term': {
954
- 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
955
- },
956
- },
957
- {
958
- 'term': {
959
- 'doc.store_id.keyword': req.body.storeId,
960
- },
961
- },
962
- {
963
- 'terms': {
964
- 'doc.hour.keyword': [ obj.hour ],
965
- },
966
- },
967
- ],
968
902
 
969
- },
903
+ export async function livecountCheck( inputData, singleDate, req ) {
904
+ try {
905
+ const TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
906
+
907
+ const queryPromises = TimeSlots.map( async ( obj ) => {
908
+ obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
909
+ obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
910
+
911
+ const downTimeQuery = {
912
+ size: 1,
913
+ query: {
914
+ bool: {
915
+ must: [
916
+ { term: { 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ) } },
917
+ { term: { 'doc.store_id.keyword': req.body.storeId } },
918
+ { terms: { 'doc.hour.keyword': [ obj.hour ] } },
919
+ ],
970
920
  },
971
- };
972
- const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
973
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
974
- if ( streamwiseDowntime.length > 0 ) {
975
- const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
976
- return accumulator + currentValue.down_time;
977
- }, 0 );
978
- const average = sum / streamwiseDowntime.length;
979
- obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
980
- } else {
981
- obj[obj.startTime + '-' + obj.endTime] = '';
982
- }
921
+ },
922
+ };
983
923
 
984
- timewise.push( obj );
924
+ const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
925
+ const streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
926
+ if ( streamwiseDowntime.length > 0 ) {
927
+ const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => accumulator + currentValue.down_time, 0 );
928
+ const average = sum / streamwiseDowntime.length;
929
+ obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
930
+ } else {
931
+ obj[obj.startTime + '-' + obj.endTime] = '';
985
932
  }
986
- const mergedData = {
987
- Date: dayjs( req.body.Date ).format( 'YYYY-MM-DD' ),
988
- };
989
- timewise.forEach( ( obj ) => {
990
- for ( const key in obj ) {
991
- if ( key !== 'hour' && key !== 'from' && key !== 'to' && key !== 'startTime' && key !== 'endTime' && key !== 'clientId' ) {
992
- if ( mergedData[key] ) {
993
- mergedData[key] += obj[key];
994
- } else {
995
- mergedData[key] = obj[key];
996
- }
933
+ return obj;
934
+ } );
935
+
936
+ const timewise = await Promise.all( queryPromises );
937
+
938
+
939
+ const mergedData = {
940
+ Date: dayjs( singleDate ).format( 'YYYY-MM-DD' ),
941
+ };
942
+
943
+ timewise.forEach( ( obj ) => {
944
+ for ( const key in obj ) {
945
+ if ( key !== 'hour' && key !== 'from' && key !== 'to' && key !== 'startTime' && key !== 'endTime' && key !== 'clientId' ) {
946
+ if ( mergedData[key] ) {
947
+ mergedData[key] += obj[key];
948
+ } else {
949
+ mergedData[key] = obj[key];
997
950
  }
998
951
  }
999
- } );
952
+ }
953
+ } );
1000
954
 
1001
- // Create an array with the merged data.
1002
- const mergedArray = [ mergedData ];
1003
- Resolve( mergedArray );
1004
- } catch ( err ) {
1005
- Reject( err );
1006
- }
1007
- } );
955
+ return [ mergedData ];
956
+ } catch ( err ) {
957
+ throw err;
958
+ }
1008
959
  }
@@ -24,7 +24,8 @@ export async function userTakeTicket( req, res ) {
24
24
  if ( req.body.issueType == 'infra' ) {
25
25
  let query = {
26
26
  'status': { $ne: 'closed' },
27
- 'issueType': 'infra', 'ticketDetails.assigntoUser': true,
27
+ 'issueType': 'infra',
28
+ 'ticketDetails.assigntoUser': true,
28
29
  'ticketDetails.addressingUser': { $exists: false },
29
30
  'ticketDetails.issueStatus': 'notidentified',
30
31
  'ticketDetails.addressingClient': { $exists: false },
@@ -37,11 +38,12 @@ export async function userTakeTicket( req, res ) {
37
38
  if ( !userTicket ) {
38
39
  let query = {
39
40
  'status': { $ne: 'closed' },
40
- 'basicDetails.clientId': { $in: assignedClients },
41
41
  'issueType': 'infra',
42
- 'ticketType': 'refreshticket',
42
+ 'ticketDetails.ticketType': 'refreshticket',
43
43
  'ticketDetails.refreshTicketStatus': 'notidentified',
44
44
  };
45
+ console.log( query, assignedClients );
46
+
45
47
  if ( assignedClients.length > 0 ) {
46
48
  query = ( { ...query, ...{ 'basicDetails.clientId': { $in: assignedClients } } } );
47
49
  }
@@ -130,22 +132,15 @@ export async function userTicketList( req, res ) {
130
132
  },
131
133
  } );
132
134
  }
133
- if ( req.body.status != 'closed' || req.body.export ) {
134
- query.push( {
135
- $match: {
136
- $and: [
137
- { updatedAt: { $gte: date.start } },
138
- { updatedAt: { $lte: date.end } },
139
- ],
140
- },
141
- } );
142
- } else {
143
- query.push( {
144
- $match: {
145
- updatedAt: { $gte: new Date( dayjs().format( 'YYYY-MM-DD' ) ) },
146
- },
147
- } );
148
- }
135
+
136
+ query.push( {
137
+ $match: {
138
+ $and: [
139
+ { updatedAt: { $gte: date.start } },
140
+ { updatedAt: { $lte: date.end } },
141
+ ],
142
+ },
143
+ } );
149
144
  if ( req.body.status && req.body.status != '' ) {
150
145
  query.push( {
151
146
  $match: {
@@ -359,7 +354,6 @@ export async function workHistory( req, res ) {
359
354
  $match: {
360
355
  $and: [
361
356
  { 'basicDetails.clientId': { $in: req.body.clientId } },
362
- { 'status': 'closed' },
363
357
  { issueType: req.body.issueType },
364
358
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
365
359
  ],
@@ -370,7 +364,6 @@ export async function workHistory( req, res ) {
370
364
  $match: {
371
365
  $and: [
372
366
  { 'basicDetails.clientId': { $in: req.body.clientId } },
373
- { 'status': 'closed' },
374
367
  { issueType: { $in: [ 'highcount', 'lowcount' ] } },
375
368
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
376
369
  ],
@@ -427,6 +420,18 @@ export async function workHistory( req, res ) {
427
420
  },
428
421
  );
429
422
  }
423
+ } else {
424
+ query.push(
425
+ {
426
+ $match: {
427
+ $and: [
428
+ { createdAt: { $gte: date.start } },
429
+ { createdAt: { $lte: date.end } },
430
+ ],
431
+
432
+ },
433
+ },
434
+ );
430
435
  }
431
436
 
432
437
  if ( req.body.storeFilter && req.body.storeFilter.length > 0 ) {
@@ -544,6 +549,8 @@ export async function workHistory( req, res ) {
544
549
  'Closed on': element.issueClosedDate,
545
550
  'Issue Identified on': element.issueIdentifiedDate,
546
551
  'Issue Type': element.infraIssue ? element.infraIssue : '-',
552
+ 'Status': element.status,
553
+
547
554
  };
548
555
  }
549
556
  if ( req.body.issueType === 'dataMismatch' ) {
@@ -557,6 +564,7 @@ export async function workHistory( req, res ) {
557
564
  'Issue date': dayjs( element.issueDate ).format( 'DD MMM, YYYY' ),
558
565
  'Closed on': element.issueClosedDate,
559
566
  'Issue Type': element.issueType ? element.issueType : '-',
567
+ 'Status': element.status,
560
568
  };
561
569
  }
562
570
  exportdata.push( data );
@@ -29,19 +29,18 @@ export async function validateDetails( req, res, next ) {
29
29
  clientName: client.clientName,
30
30
  };
31
31
  req.body.emailAlert = client.ticketConfigs.emailAlert;
32
- if ( req.body.issueType == 'infra' ) {
33
- let refreshdate = dayjs().add( client.ticketConfigs.refreshAlert, 'days' );
34
- req.body.ticketDetails = {
35
- ticketRefreshTime: new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ),
36
- };
37
- } else if ( req.body.issueType == 'installation' ) {
32
+ // if ( req.body.issueType == 'infra' ) {
33
+ // let refreshdate = dayjs().add( client.ticketConfigs.refreshAlert, 'days' );
34
+ // req.body.ticketDetails = {
35
+ // ticketRefreshTime: new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ),
36
+ // };
37
+ // }
38
+ if ( req.body.issueType == 'installation' ) {
38
39
  let refreshdate = dayjs().add( client.ticketConfigs.installationReAssign, 'days' );
39
40
  req.body.ticketDetails = {
40
41
  ticketRefreshTime: new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ),
41
42
  };
42
43
  }
43
-
44
-
45
44
  next();
46
45
  } catch ( error ) {
47
46
  logger.error( { error: error, function: 'validateDetails' } );