tango-app-api-infra 3.1.14 → 3.1.15

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.1.14",
3
+ "version": "3.1.15",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -134,10 +134,15 @@ export async function infraCard( req, res ) {
134
134
  count: 0,
135
135
  } ) );
136
136
  }
137
+
137
138
  response.unshift( {
138
- name: 'All Issues',
139
+ name: 'Identified Issues',
139
140
  count: infraStoreCount.length > 0 ? infraStoreCount[0].identifiedcount : 0,
140
141
  } );
142
+ response.unshift( {
143
+ name: 'All Issues',
144
+ count: infraStoreCount.length > 0 ? infraStoreCount[0].infraCount : 0,
145
+ } );
141
146
  response.push( {
142
147
  name: 'Issues Not Identified',
143
148
  count: infraStoreCount.length > 0 ? infraStoreCount[0].infraCount - infraStoreCount[0].identifiedcount : 0,
@@ -279,9 +284,12 @@ export async function installationCard( req, res ) {
279
284
  export async function infraIssuesTable( req, res ) {
280
285
  try {
281
286
  let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
282
- let issueStatus = 'identified';
287
+ let issueStatus = [ 'identified' ];
283
288
  if ( req.body.filterIssue == 'Issues Not Identified' ) {
284
- issueStatus = 'notidentified';
289
+ issueStatus = [ 'notidentified' ];
290
+ };
291
+ if ( req.body.filterIssue == 'All Issues' ) {
292
+ issueStatus = [ 'notidentified', 'identified' ];
285
293
  };
286
294
  let query = [ {
287
295
  $match: {
@@ -289,7 +297,7 @@ export async function infraIssuesTable( req, res ) {
289
297
  { issueType: 'infra' },
290
298
  { status: { $ne: 'closed' } },
291
299
  { 'basicDetails.clientId': { $in: req.body.clientId } },
292
- { 'ticketDetails.issueStatus': issueStatus },
300
+ { 'ticketDetails.issueStatus': { $in: issueStatus } },
293
301
  // { createdAt: { $gte: date.start } },
294
302
  { createdAt: { $lte: date.end } },
295
303
  ],
@@ -361,7 +369,7 @@ export async function infraIssuesTable( req, res ) {
361
369
  },
362
370
  },
363
371
  ];
364
- if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'All Issues' && req.body.filterIssue != 'Issues Not Identified' ) {
372
+ if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'Identified Issues' && req.body.filterIssue != 'Issues Not Identified'&&req.body.filterIssue != 'All Issues' ) {
365
373
  query.push( {
366
374
  $match: {
367
375
  primaryIssue: req.body.filterIssue,
@@ -393,6 +401,7 @@ export async function infraIssuesTable( req, res ) {
393
401
  } );
394
402
  }
395
403
  let count = await aggregateTangoTicket( query );
404
+ console.log( count.length );
396
405
  if ( req.body.limit && req.body.offset && !req.body.export ) {
397
406
  query.push(
398
407
  { $skip: ( req.body.offset - 1 ) * req.body.limit },
@@ -407,9 +416,9 @@ export async function infraIssuesTable( req, res ) {
407
416
  'CREATED AT': element.createdAt,
408
417
  'STORE ID': element.storeId,
409
418
  'STORE NAME': element.storeName,
419
+ 'PRIMARY ISSUE': element.primaryIssue,
410
420
  'SUB ISSUE': element.secondaryIssue,
411
- 'ISSUE IDENTIFIED ON': element.issueIdentifiedDate,
412
- 'ISSUE CLOSED ON': element.issueClosedDate,
421
+ 'ISSUE IDENTIFIED ON': dayjs( element.issueIdentifiedDate ).tz( 'Asia/Kolkata' ).format( 'YYYY-MM-DD HH:mm A' ),
413
422
  'STATUS': element.status,
414
423
  } );
415
424
  } );
@@ -709,12 +718,20 @@ export async function hourWiseDownstores( req, res ) {
709
718
  try {
710
719
  let inputData = req.body;
711
720
  inputData.Date = dayjs( req.body.toDate ).format( 'YYYY-MM-DD' );
712
-
721
+ let issueStatus = [ 'identified' ];
722
+ if ( req.body.filterIssue == 'Issues Not Identified' ) {
723
+ issueStatus = [ 'notidentified' ];
724
+ };
725
+ if ( req.body.filterIssue == 'All Issues' ) {
726
+ issueStatus = [ 'notidentified', 'identified' ];
727
+ };
713
728
  let query = [ {
714
729
  $match: {
715
730
  $and: [
716
731
  { 'basicDetails.clientId': req.body.clientId },
717
732
  { 'status': { $ne: 'closed' } },
733
+ { issueType: 'infra' },
734
+ { 'ticketDetails.issueStatus': { $in: issueStatus } },
718
735
  { 'issueDate': { $lte: new Date( req.body.toDate ) } },
719
736
  ],
720
737
  },
@@ -773,7 +790,7 @@ export async function hourWiseDownstores( req, res ) {
773
790
  $sort: { [req.body.sortColumName]: req.body.sortBy },
774
791
  } );
775
792
  }
776
- if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'All Issues' && req.body.filterIssue != 'Issues Not Identified' ) {
793
+ if ( req.body.filterIssue && req.body.filterIssue != '' && req.body.filterIssue != 'Identified Issues' && req.body.filterIssue != 'Issues Not Identified'&&req.body.filterIssue != 'All Issues' ) {
777
794
  query.push( {
778
795
  $match: {
779
796
  primaryIssue: req.body.filterIssue,
@@ -3,9 +3,9 @@
3
3
  import { aggregateTangoTicket, createTangoTicket, findOneTangoTicket, updateOneTangoTicket, updateManyTangoTicket, findTangoTicket } from '../services/tangoTicket.service.js';
4
4
  import { createinfraReason, findinfraReason } from '../services/infraReason.service.js';
5
5
  import { updateOneStore, findStore } from '../services/store.service.js';
6
- import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, download, appConfig, getUTC } from 'tango-app-api-middleware';
6
+ import { logger, fileUpload, signedUrl, sendEmailWithSES, getOpenSearchData, insertOpenSearchData, download, appConfig, getUTC } from 'tango-app-api-middleware';
7
7
  import { aggregateUser, updateOneUser } from '../services/user.service.js';
8
- import { updateoneClient } from '../services/client.service.js';
8
+ import { findOneClient, updateoneClient } from '../services/client.service.js';
9
9
  import dayjs from 'dayjs';
10
10
  import { readFileSync } from 'fs';
11
11
  import { join } from 'path';
@@ -518,7 +518,7 @@ export async function emailUserList( req, res ) {
518
518
  export async function saveInfraEmailConfig( req, res ) {
519
519
  try {
520
520
  let inputData = req.body;
521
-
521
+ let client = await findOneClient( { clientId: inputData.clientId } );
522
522
  await updateoneClient( { clientId: inputData.clientId }, {
523
523
  'ticketConfigs.infraReport': {
524
524
  start: inputData.start,
@@ -535,6 +535,29 @@ export async function saveInfraEmailConfig( req, res ) {
535
535
  } );
536
536
  }
537
537
  }
538
+
539
+ const logObj = {
540
+ clientId: inputData.clientId,
541
+ userName: req.user?.userName,
542
+ email: req.user?.email,
543
+ date: new Date(),
544
+ logType: 'configuration',
545
+ logSubType: 'emailConfig',
546
+ eventType: 'update',
547
+ showTo: [ 'tango' ],
548
+ changes: [ `Email Config` ],
549
+ previous: client.ticketConfigs.infraReport,
550
+ current: {
551
+ infraReport: {
552
+ start: inputData.start,
553
+ end: inputData.end,
554
+ },
555
+ },
556
+ };
557
+
558
+ await insertOpenSearchData( appConfig.opensearch.activityLog, logObj );
559
+
560
+
538
561
  res.sendSuccess( 'Updated Successfully' );
539
562
  } catch ( error ) {
540
563
  logger.error( { error: error, function: 'emailUserList' } );
@@ -876,9 +876,21 @@ export async function cameraAngleChange( req, res ) {
876
876
  file_path: changeDetected[0].path,
877
877
  };
878
878
  let Image = await signedUrl( params );
879
+ let expectedparams = {
880
+ Bucket: appConfig.cloud.aws.bucket.cameraAngle,
881
+ file_path: changeDetected[0].expected,
882
+ };
883
+ let expectedImage = await signedUrl( expectedparams );
884
+ let actualparams = {
885
+ Bucket: appConfig.cloud.aws.bucket.cameraAngle,
886
+ file_path: changeDetected[0].actual,
887
+ };
888
+ let actualImage = await signedUrl( actualparams );
879
889
  res.sendSuccess( {
880
890
  StreamName: req.body.StreamName,
881
891
  angleChangeImage: Image,
892
+ expected: expectedImage,
893
+ actual: actualImage,
882
894
  anglechange: true,
883
895
  resolution: changeDetected[0].resolution,
884
896
  } );
@@ -907,7 +919,7 @@ function getDatesArray( fromDate, toDate ) {
907
919
  }
908
920
 
909
921
  function paginateArray( array, offset, limit ) {
910
- return array.slice( ( offset - 1 ) * limit, offset*limit );
922
+ return array.slice( ( offset - 1 ) * limit, offset * limit );
911
923
  }
912
924
  export async function datewiseDowntime( req, res ) {
913
925
  try {
@@ -927,7 +939,7 @@ export async function datewiseDowntime( req, res ) {
927
939
  end: endHour,
928
940
  interval: 60,
929
941
  };
930
- req.body.Date= singleDate;
942
+ req.body.Date = singleDate;
931
943
  let storedata = await livecountCheck( inputData, req );
932
944
  result.push( storedata[0] );
933
945
  }
@@ -936,11 +948,71 @@ export async function datewiseDowntime( req, res ) {
936
948
  data: result,
937
949
  } );
938
950
  } catch ( error ) {
939
- logger.error( { error: error, function: 'cameraAngleChange' } );
951
+ logger.error( { error: error, function: 'datewiseDowntime' } );
940
952
  return res.sendError( error, 500 );
941
953
  }
942
954
  }
955
+ export async function streamwiseDowntime( req, res ) {
956
+ try {
957
+ const store = await findOneStore( { storeId: req.body.storeId } );
958
+ if ( !store ) {
959
+ return res.sendError( 'Stores Not fond', 204 );
960
+ }
961
+ let startHour = store.storeProfile.open.split( ':' )[0];
962
+ let endHour = store.storeProfile.close.split( ':' )[0];
963
+ const interval = 60; // 1 hour in minutes
964
+ const TimeSlots = generateTimeSlots( startHour, endHour, interval, req );
965
+ let timewise = [];
966
+ for ( const obj of TimeSlots ) {
967
+ obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
968
+ obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
969
+ let downTimeQuery = {
970
+ 'size': 1,
971
+ 'query': {
972
+ 'bool': {
973
+ 'must': [
974
+ {
975
+ 'term': {
976
+ 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
977
+ },
978
+ },
979
+ {
980
+ 'term': {
981
+ 'doc.store_id.keyword': req.body.storeId,
982
+ },
983
+ },
984
+ {
985
+ 'terms': {
986
+ 'doc.hour.keyword': [ obj.hour ],
987
+ },
988
+ },
989
+ ],
990
+
991
+ },
992
+ },
993
+ };
994
+ const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
943
995
 
996
+ let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
997
+ if ( streamwiseDowntime.length > 0 ) {
998
+ console.log( streamwiseDowntime );
999
+ for ( let stream of streamwiseDowntime ) {
1000
+ if ( stream.stream === req.body.stream ) {
1001
+ obj.downTime= stream.down_time;
1002
+ }
1003
+ }
1004
+ } else {
1005
+ obj.downTime= '';
1006
+ }
1007
+
1008
+ timewise.push( obj );
1009
+ }
1010
+ res.sendSuccess( timewise );
1011
+ } catch ( error ) {
1012
+ logger.error( { error: error, function: 'streamwiseDowntime' } );
1013
+ return res.sendError( error, 500 );
1014
+ }
1015
+ }
944
1016
 
945
1017
  export async function livecountCheck( inputData, req ) {
946
1018
  return new Promise( async ( Resolve, Reject ) => {
@@ -1,7 +1,7 @@
1
1
 
2
2
  import express from 'express';
3
3
  import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
4
- import { storeTicketList, storeTicketcard, edgeAppLogTable, viewedgeAppLog, cameraAngleChange, datewiseDowntime } from '../controllers/storeInfra.controlller.js';
4
+ import { storeTicketList, storeTicketcard, edgeAppLogTable, viewedgeAppLog, cameraAngleChange, datewiseDowntime, streamwiseDowntime } from '../controllers/storeInfra.controlller.js';
5
5
  export const storeInfraRouter = express.Router();
6
6
 
7
7
  storeInfraRouter.post( '/storeTicketList', isAllowedSessionHandler, authorize( {
@@ -29,3 +29,7 @@ storeInfraRouter.post( '/datewiseDowntime', isAllowedSessionHandler, authorize(
29
29
  userType: [ 'client', 'tango' ], access: [
30
30
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
31
31
  } ), datewiseDowntime );
32
+ storeInfraRouter.post( '/streamwiseDowntime', isAllowedSessionHandler, authorize( {
33
+ userType: [ 'client', 'tango' ], access: [
34
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
35
+ } ), streamwiseDowntime );