tango-app-api-infra 3.0.72-dev → 3.0.73-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.72-dev",
3
+ "version": "3.0.73-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,8 +25,8 @@
25
25
  "joi-to-swagger": "^6.2.0",
26
26
  "mongodb": "^6.4.0",
27
27
  "nodemon": "^3.1.0",
28
- "tango-api-schema": "^2.0.97",
29
- "tango-app-api-middleware": "^1.0.64-dev",
28
+ "tango-api-schema": "^2.0.94",
29
+ "tango-app-api-middleware": "^1.0.63-dev",
30
30
  "winston": "^3.12.0",
31
31
  "winston-daily-rotate-file": "^5.0.0"
32
32
  },
@@ -8,21 +8,8 @@ export async function createTicket( req, res ) {
8
8
  if ( ticketExist ) {
9
9
  return res.sendSuccess( 'MAT Ticket Already Exists for the store' );
10
10
  }
11
- let actionBy = '';
12
- if ( req.user.userType == 'tango' ) {
13
- actionBy = 'Tango';
14
- } else if ( req.user.userType == 'client' ) {
15
- actionBy = 'User';
16
- }
17
- req.body.ticketActivity = [ {
18
- actionType: 'Created',
19
- timeStamp: new Date(),
20
- actionBy: actionBy,
21
- IdentifiedBy: req.user.userName,
22
- } ];
23
-
24
11
  req.body.ticketDetails = {};
25
- req.body.dataMismatch = req.body.dataMismatch;
12
+ req.body.ticketDetails.dataMismatch = req.body.dataMismatch;
26
13
  req.body.issueDate = new Date( req.body.Date );
27
14
  req.body.ticketId = 'TE_DM_' + new Date().valueOf();
28
15
  let create = await createTangoTicket( req.body );
@@ -13,9 +13,12 @@ import handlebars from 'handlebars';
13
13
  import { findOneGroup } from '../services/group.service.js';
14
14
  import htmlpdf from 'html-pdf-node';
15
15
  import mongoose from 'mongoose';
16
+ import _ from 'lodash';
17
+ import { aggregateCamera } from '../services/camera.service.js';
16
18
  export async function createTicket( req, res ) {
17
19
  try {
18
20
  req.body.issueDate = new Date( req.body.Date );
21
+ req.body.ticketDetails.filesCount = req.body.filesCount;
19
22
  if ( req.body.issueType == 'infra' ) {
20
23
  req.body.ticketId = 'TE_INF_' + new Date().valueOf();
21
24
  req.body.ticketActivity = [ {
@@ -639,7 +642,7 @@ export async function getInfraIssues( req, res ) {
639
642
  {
640
643
  $project: {
641
644
  issueType: 1,
642
- issueDate: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
645
+ issueDate: { $dateToString: { format: '%Y-%m-%d', date: '$issueDate' } },
643
646
  ticketActivity: {
644
647
  $filter: {
645
648
  input: '$ticketActivity',
@@ -649,6 +652,7 @@ export async function getInfraIssues( req, res ) {
649
652
  },
650
653
  },
651
654
  },
655
+
652
656
  {
653
657
  $unwind: {
654
658
  path: '$ticketActivity', preserveNullAndEmptyArrays: true,
@@ -688,12 +692,99 @@ export async function getInfraIssues( req, res ) {
688
692
  issueDate: 1,
689
693
  primaryIssue: 1,
690
694
  secondaryReason: 1,
695
+ downTime: { $ifNull: [ 0, 0 ] },
696
+ speedTest: { $ifNull: [ 0.5, 0.5 ] },
691
697
  },
692
698
 
693
699
  },
694
700
  ];
701
+
702
+
703
+ let retVal = [];
704
+ let current = new Date( inputData.fromDate );
705
+ let end = new Date( inputData.toDate );
706
+
707
+ while ( current <= end ) {
708
+ retVal.push( { issueDate: dayjs( current ).format( 'YYYY-MM-DD' ), downTime: 0, speedTest: 0.6 } );
709
+ current.setDate( current.getDate() + 1 );
710
+ }
711
+
695
712
  const result = await aggregateTangoTicket( query );
696
- return res.sendSuccess( { result: result } );
713
+
714
+ const mergeValue =_.values(
715
+ _.merge(
716
+ _.keyBy( retVal, 'issueDate' ),
717
+ _.keyBy( result, 'issueDate' ),
718
+ ),
719
+ );
720
+ logger.info( { message: mergeValue, value1: result } );
721
+
722
+ if ( mergeValue.length == 0 ) {
723
+ return res.sendError( 'NO Data Found', 204 );
724
+ }
725
+ for ( let i =0; i< mergeValue.length; i++ ) {
726
+ const downTime = await getOpenSearchData( 'live_downtime_hourly',
727
+ {
728
+ 'size': 100,
729
+ 'query': {
730
+ 'bool': {
731
+ 'must': [
732
+ {
733
+ 'term': {
734
+ 'doc.date.keyword': dayjs( mergeValue[i].issueDate ).format( 'DD-MM-YYYY' ),
735
+ },
736
+ },
737
+ {
738
+ 'term': {
739
+ 'doc.store_id.keyword': inputData.storeId,
740
+ },
741
+ },
742
+
743
+ ],
744
+
745
+ },
746
+ },
747
+
748
+ } );
749
+ let streamwiseDowntime = [];
750
+ logger.info( { streamwiseDowntime: downTime.body.hits.hits.length } );
751
+ if ( downTime.body.hits.hits.length > 0 ) {
752
+ for ( let i = 0; i< downTime.body.hits.hits.length; i++ ) {
753
+ const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
754
+ return accumulator + currentValue.down_time;
755
+ }, 0 );
756
+ const average = sum / streamwiseDowntime.length;
757
+ mergeValue.downTime = Math.round( average );
758
+ // streamwiseDowntime.push( ...downTime.body.hits.hits[i]._source.doc.streamwise_downtime );
759
+ }
760
+ }
761
+ }
762
+ const camQuery = [
763
+ {
764
+ $match: {
765
+ $and: [
766
+ // { isUp: { $eq: true } },
767
+ // { isActivated: { $eq: true } },
768
+ { storeId: inputData.storeId },
769
+ ],
770
+ },
771
+ },
772
+ {
773
+ $group: {
774
+ _id: null,
775
+ streams: { $push: '$streamName' },
776
+ },
777
+ },
778
+ {
779
+ $project: {
780
+ _id: 0,
781
+ streams: 1,
782
+ },
783
+ },
784
+ ];
785
+ const camera = await aggregateCamera( camQuery );
786
+ logger.info( { message: camera } );
787
+ return res.sendSuccess( { result: mergeValue, streams: camera[0]?.streams } );
697
788
  } catch ( error ) {
698
789
  logger.error( { error: error, function: 'getInfraIssues' } );
699
790
  return res.sendError( error, 500 );
@@ -1379,32 +1470,3 @@ export async function storeFilter( req, res ) {
1379
1470
  return res.sendError( error, 500 );
1380
1471
  }
1381
1472
  }
1382
-
1383
- export async function updateMat( req, res ) {
1384
- try {
1385
- if ( req.body.actionType && req.body.actionType != '' ) {
1386
- let actionBy = '';
1387
- if ( req.user.userType == 'tango' ) {
1388
- actionBy = 'Tango';
1389
- } else if ( req.user.userType == 'client' ) {
1390
- actionBy = 'User';
1391
- }
1392
- req.body.ticketActivity.push( {
1393
- actionType: req.body.actionType,
1394
- actionBy: actionBy,
1395
- timeStamp: new Date(),
1396
- IdentifiedBy: actionBy == 'Tango' ? actionBy : req.user.userName,
1397
- attachments: req.body.attachments,
1398
- } );
1399
- updateValue = { ticketActivity: req.body.ticketActivity };
1400
- }
1401
-
1402
- let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, updateValue );
1403
- if ( updateTicket ) {
1404
- res.sendSuccess( 'Ticket Updated Successfully' );
1405
- }
1406
- } catch ( error ) {
1407
- logger.error( { error: error, function: 'updateMat' } );
1408
- return res.sendError( error, 500 );
1409
- }
1410
- }
@@ -1,5 +1,5 @@
1
1
  import j2s from 'joi-to-swagger';
2
- import { getInfraIssueValid } from '../dtos/infra.dtos.js';
2
+ import { getInfraIssueSchema } from '../dtos/infra.dtos.js';
3
3
 
4
4
  export const infraDocs = {
5
5
 
@@ -12,7 +12,7 @@ export const infraDocs = {
12
12
  requestBody: {
13
13
  content: {
14
14
  'application/json': {
15
- schema: j2s( getInfraIssueValid ).swagger,
15
+ schema: j2s( getInfraIssueSchema ).swagger,
16
16
  },
17
17
  },
18
18
  },
@@ -4,7 +4,7 @@ import { isAllowedSessionHandler, authorize, validate } from 'tango-app-api-midd
4
4
  import { validateDetails, bulkvalidateDetails, validateTicket, bulkvalidateTicket, validateTicketstatus, ticketExists, infraReasonExists, InfrastepstoResolve, InfraAlert } from '../validations/infra.validation.js';
5
5
  import { createTicket, bulkcreateTicket, updateStatus, createReason, PrimaryReasons, matTable,
6
6
  secondaryReason, updateTicketIssue, viewTicket, AlertTicketReply, uploadAttachments, getInfraIssues,
7
- updateInstallationTicket, updateMat, emailUserList, saveInfraEmailConfig, invoice, infraTable, storeFilter, assignTicket, installationTable } from '../controllers/infra.controllers.js';
7
+ updateInstallationTicket, emailUserList, saveInfraEmailConfig, invoice, infraTable, storeFilter, assignTicket, installationTable } from '../controllers/infra.controllers.js';
8
8
  import { getInfraIssueValid } from '../dtos/infra.dtos.js';
9
9
 
10
10
 
@@ -80,7 +80,3 @@ infraRouter.post( '/get-infra-issues', isAllowedSessionHandler, authorize( {
80
80
  userType: [ 'client', 'tango' ], access: [
81
81
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
82
82
  } ), validate( getInfraIssueValid ), getInfraIssues );
83
- infraRouter.post( '/updateMat', isAllowedSessionHandler, authorize( {
84
- userType: [ 'client', 'tango' ], access: [
85
- { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
86
- } ), updateMat );
@@ -0,0 +1,5 @@
1
+ import cameraModel from 'tango-api-schema/schema/camera.model.js';
2
+
3
+ export async function aggregateCamera( query ) {
4
+ return await cameraModel.aggregate( query );
5
+ }