tango-app-api-infra 3.0.72-dev → 3.0.74-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.74-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.100",
29
+ "tango-app-api-middleware": "^1.0.67-dev",
30
30
  "winston": "^3.12.0",
31
31
  "winston-daily-rotate-file": "^5.0.0"
32
32
  },
@@ -1,6 +1,6 @@
1
1
 
2
- import { findOneTangoTicket, createTangoTicket } from '../services/tangoTicket.service.js';
3
- import { logger } from 'tango-app-api-middleware';
2
+ import { findOneTangoTicket, createTangoTicket, updateOneTangoTicket, aggregateTangoTicket, countDocumentsTangoTicket } from '../services/tangoTicket.service.js';
3
+ import { logger, getUTC, appConfig, fileUpload, signedUrl } from 'tango-app-api-middleware';
4
4
  export async function createTicket( req, res ) {
5
5
  try {
6
6
  let ticketExist = await findOneTangoTicket( { 'issueType': req.body.issueType, 'issueDate': ( new Date( req.body.Date ) ), 'basicDetails.storeId': req.body.storeId } );
@@ -14,18 +14,41 @@ export async function createTicket( req, res ) {
14
14
  } else if ( req.user.userType == 'client' ) {
15
15
  actionBy = 'User';
16
16
  }
17
+ req.body.ticketDetails = {};
18
+ req.body.dataMismatch ={
19
+ actualCount: req.body.actualCount,
20
+ expectedCount: req.body.expectedCount,
21
+ contactEmail: req.body.contactEmail,
22
+ };
23
+ req.body.issueDate = new Date( req.body.Date );
24
+ req.body.ticketId = 'TE_DM_' + new Date().valueOf();
25
+ let create = await createTangoTicket( req.body );
26
+ let getObject = {};
27
+ if ( req.files ) {
28
+ let params = {
29
+ Bucket: appConfig.cloud.aws.bucket.ticket,
30
+ Key: create.ticketId + '/',
31
+ ContentType: 'multipart/form-data',
32
+ body: req.files.img.data,
33
+ fileName: req.files.img.name,
34
+ };
35
+ let upload = await fileUpload( params );
36
+ if ( upload ) {
37
+ getObject = {
38
+ fileName: req.files.img.name,
39
+ filePath: create.ticketId + '/' + req.files.img.name,
40
+ };
41
+ }
42
+ }
17
43
  req.body.ticketActivity = [ {
18
44
  actionType: 'Created',
19
45
  timeStamp: new Date(),
20
46
  actionBy: actionBy,
21
47
  IdentifiedBy: req.user.userName,
48
+ description: req.body.description,
49
+ attachments: [ getObject ],
22
50
  } ];
23
-
24
- req.body.ticketDetails = {};
25
- req.body.dataMismatch = req.body.dataMismatch;
26
- req.body.issueDate = new Date( req.body.Date );
27
- req.body.ticketId = 'TE_DM_' + new Date().valueOf();
28
- let create = await createTangoTicket( req.body );
51
+ await updateOneTangoTicket( { ticketId: create.ticketId }, { ticketActivity: req.body.ticketActivity } );
29
52
  if ( create ) {
30
53
  res.sendSuccess( 'Ticket Created Successfully' );
31
54
  }
@@ -34,3 +57,165 @@ export async function createTicket( req, res ) {
34
57
  return res.sendError( error, 500 );
35
58
  }
36
59
  }
60
+
61
+ export async function updateMat( req, res ) {
62
+ try {
63
+ let updateValue = {};
64
+ if ( req.body.actionType && req.body.actionType != '' ) {
65
+ let actionBy = '';
66
+ if ( req.user.userType == 'tango' ) {
67
+ actionBy = 'Tango';
68
+ } else if ( req.user.userType == 'client' ) {
69
+ actionBy = 'User';
70
+ }
71
+ req.body.ticketActivity.push( {
72
+ actionType: req.body.actionType,
73
+ actionBy: actionBy,
74
+ timeStamp: new Date(),
75
+ IdentifiedBy: req.user.userName,
76
+ description: req.body.description,
77
+ attachments: req.body.attachments,
78
+ } );
79
+ updateValue = { ticketActivity: req.body.ticketActivity };
80
+ }
81
+
82
+ let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, updateValue );
83
+ if ( updateTicket ) {
84
+ res.sendSuccess( 'Ticket Updated Successfully' );
85
+ }
86
+ } catch ( error ) {
87
+ logger.error( { error: error, function: 'updateMat' } );
88
+ return res.sendError( error, 500 );
89
+ }
90
+ }
91
+
92
+
93
+ export async function activityList( req, res ) {
94
+ try {
95
+ let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
96
+ let query = [ {
97
+ $match: {
98
+ $and: [
99
+ { 'basicDetails.storeId': req.body.storeId },
100
+ { issueType: { $in: [ 'lowcount', 'highcount' ] } },
101
+ { createdAt: { $gte: date.start } },
102
+ { createdAt: { $lte: date.end } },
103
+ ],
104
+ },
105
+ },
106
+ {
107
+ $project: {
108
+ storeId: '$basicDetails.storeId',
109
+ status: 1,
110
+ issueDate: '$issueDate',
111
+ Date: { $dateToString: { format: '%d-%m-%Y', date: '$createdAt' } },
112
+ issueClosedDate: 1,
113
+ ticketId: 1,
114
+ issueType: 1,
115
+ ticketActivity: 1,
116
+ comments: { $size: '$ticketActivity' },
117
+ },
118
+ },
119
+ {
120
+ $unwind: {
121
+ path: '$ticketActivity', preserveNullAndEmptyArrays: true,
122
+ },
123
+ },
124
+ {
125
+ $group: {
126
+ _id: '$ticketId',
127
+ storeId: { $first: '$storeId' },
128
+ Date: { $first: '$Date' },
129
+ issueClosedDate: { $first: '$issueClosedDate' },
130
+ status: { $first: '$status' },
131
+ issueDate: { $first: '$issueDate' },
132
+ ticketId: { $first: '$ticketId' },
133
+ issueType: { $first: '$issueType' },
134
+ comments: { $first: '$comments' },
135
+ description: { $last: '$ticketActivity.description' },
136
+ },
137
+ },
138
+ {
139
+ $sort: {
140
+ issueDate: -1,
141
+ },
142
+ },
143
+ ];
144
+
145
+ if ( req.body.filter && req.body.filter !== '' ) {
146
+ query.push( {
147
+ $match: {
148
+ issueType: req.body.filter,
149
+ },
150
+ } );
151
+ }
152
+ let ticketList = await aggregateTangoTicket( query );
153
+ if ( req.body.export && ticketList.length > 0 ) {
154
+ const exportdata = [];
155
+ ticketList.forEach( ( element ) => {
156
+ exportdata.push( {
157
+ 'STORE ID': element.storeId,
158
+ 'TICKET ID': element.ticketId,
159
+ 'DATE': element.Date,
160
+ 'ISSUE CLOSED DATE': element.issueClosedDate,
161
+ 'STATUS': element.status,
162
+ 'COMMENT': element.description,
163
+ } );
164
+ } );
165
+ await download( exportdata, res );
166
+ return;
167
+ }
168
+ if ( ticketList.length ) {
169
+ let highCount = await countDocumentsTangoTicket( {
170
+ $and: [
171
+ { 'basicDetails.storeId': req.body.storeId },
172
+ { issueType: 'highcount' },
173
+ { createdAt: { $gte: date.start } },
174
+ { createdAt: { $lte: date.end } },
175
+ ],
176
+ } );
177
+ let lowCount = await countDocumentsTangoTicket( {
178
+ $and: [
179
+ { 'basicDetails.storeId': req.body.storeId },
180
+ { issueType: 'lowcount' },
181
+ { createdAt: { $gte: date.start } },
182
+ { createdAt: { $lte: date.end } },
183
+ ],
184
+ } );
185
+
186
+ res.sendSuccess( {
187
+ count: ticketList.length,
188
+ data: ticketList,
189
+ highCount: highCount,
190
+ lowCount: lowCount,
191
+ } );
192
+ } else {
193
+ return res.sendError( 'NO data', 204 );
194
+ }
195
+ } catch ( error ) {
196
+ logger.error( { error: error, function: 'activityList' } );
197
+ return res.sendError( error, 500 );
198
+ }
199
+ }
200
+
201
+
202
+ export async function showActivity( req, res ) {
203
+ try {
204
+ for ( let activity of req.body.ticketActivity ) {
205
+ if ( activity.attachments&&activity.attachments.length>0 ) {
206
+ for ( let attchment of activity.attachments ) {
207
+ let params = {
208
+ Bucket: appConfig.cloud.aws.bucket.ticket,
209
+ file_path: attchment.filePath,
210
+ };
211
+ let attachments = await signedUrl( params );
212
+ attchment.signedUrl = attachments;
213
+ }
214
+ }
215
+ }
216
+ res.sendSuccess( req.body );
217
+ } catch ( error ) {
218
+ logger.error( { error: error, function: 'showActivity' } );
219
+ return res.sendError( error, 500 );
220
+ }
221
+ }
@@ -13,6 +13,8 @@ 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 );
@@ -639,7 +641,7 @@ export async function getInfraIssues( req, res ) {
639
641
  {
640
642
  $project: {
641
643
  issueType: 1,
642
- issueDate: { $dateToString: { format: '%d-%m-%Y', date: '$issueDate' } },
644
+ issueDate: { $dateToString: { format: '%Y-%m-%d', date: '$issueDate' } },
643
645
  ticketActivity: {
644
646
  $filter: {
645
647
  input: '$ticketActivity',
@@ -649,6 +651,7 @@ export async function getInfraIssues( req, res ) {
649
651
  },
650
652
  },
651
653
  },
654
+
652
655
  {
653
656
  $unwind: {
654
657
  path: '$ticketActivity', preserveNullAndEmptyArrays: true,
@@ -688,12 +691,99 @@ export async function getInfraIssues( req, res ) {
688
691
  issueDate: 1,
689
692
  primaryIssue: 1,
690
693
  secondaryReason: 1,
694
+ downTime: { $ifNull: [ 0, 0 ] },
695
+ speedTest: { $ifNull: [ 0.5, 0.5 ] },
691
696
  },
692
697
 
693
698
  },
694
699
  ];
700
+
701
+
702
+ let retVal = [];
703
+ let current = new Date( inputData.fromDate );
704
+ let end = new Date( inputData.toDate );
705
+
706
+ while ( current <= end ) {
707
+ retVal.push( { issueDate: dayjs( current ).format( 'YYYY-MM-DD' ), downTime: 0, speedTest: 0.6 } );
708
+ current.setDate( current.getDate() + 1 );
709
+ }
710
+
695
711
  const result = await aggregateTangoTicket( query );
696
- return res.sendSuccess( { result: result } );
712
+
713
+ const mergeValue =_.values(
714
+ _.merge(
715
+ _.keyBy( retVal, 'issueDate' ),
716
+ _.keyBy( result, 'issueDate' ),
717
+ ),
718
+ );
719
+ logger.info( { message: mergeValue, value1: result } );
720
+
721
+ if ( mergeValue.length == 0 ) {
722
+ return res.sendError( 'NO Data Found', 204 );
723
+ }
724
+ for ( let i =0; i< mergeValue.length; i++ ) {
725
+ const downTime = await getOpenSearchData( 'live_downtime_hourly',
726
+ {
727
+ 'size': 100,
728
+ 'query': {
729
+ 'bool': {
730
+ 'must': [
731
+ {
732
+ 'term': {
733
+ 'doc.date.keyword': dayjs( mergeValue[i].issueDate ).format( 'DD-MM-YYYY' ),
734
+ },
735
+ },
736
+ {
737
+ 'term': {
738
+ 'doc.store_id.keyword': inputData.storeId,
739
+ },
740
+ },
741
+
742
+ ],
743
+
744
+ },
745
+ },
746
+
747
+ } );
748
+ let streamwiseDowntime = [];
749
+ logger.info( { streamwiseDowntime: downTime.body.hits.hits.length } );
750
+ if ( downTime.body.hits.hits.length > 0 ) {
751
+ for ( let i = 0; i< downTime.body.hits.hits.length; i++ ) {
752
+ const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
753
+ return accumulator + currentValue.down_time;
754
+ }, 0 );
755
+ const average = sum / streamwiseDowntime.length;
756
+ mergeValue.downTime = Math.round( average );
757
+ // streamwiseDowntime.push( ...downTime.body.hits.hits[i]._source.doc.streamwise_downtime );
758
+ }
759
+ }
760
+ }
761
+ const camQuery = [
762
+ {
763
+ $match: {
764
+ $and: [
765
+ // { isUp: { $eq: true } },
766
+ // { isActivated: { $eq: true } },
767
+ { storeId: inputData.storeId },
768
+ ],
769
+ },
770
+ },
771
+ {
772
+ $group: {
773
+ _id: null,
774
+ streams: { $push: '$streamName' },
775
+ },
776
+ },
777
+ {
778
+ $project: {
779
+ _id: 0,
780
+ streams: 1,
781
+ },
782
+ },
783
+ ];
784
+ const camera = await aggregateCamera( camQuery );
785
+ logger.info( { message: camera } );
786
+ return res.sendSuccess( { result: mergeValue, streams: camera[0]?.streams } );
697
787
  } catch ( error ) {
698
788
  logger.error( { error: error, function: 'getInfraIssues' } );
699
789
  return res.sendError( error, 500 );
@@ -1380,31 +1470,3 @@ export async function storeFilter( req, res ) {
1380
1470
  }
1381
1471
  }
1382
1472
 
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
- }
@@ -445,11 +445,10 @@ export async function emailUserList( req, res ) {
445
445
  }
446
446
  export async function infraReportSent( req, res ) {
447
447
  try {
448
- let date;
449
448
  // if ( req.body.type == 'start' ) {
450
449
  // date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
451
450
  // } else if ( req.body.type == 'end' ) {
452
- date = dayjs().format( 'YYYY-MM-DD' );
451
+ let date = dayjs( ).format( 'YYYY-MM-DD' );
453
452
  // };
454
453
  let query = [ {
455
454
  $match: {
@@ -590,23 +589,23 @@ export async function infraReportSent( req, res ) {
590
589
  count: 0,
591
590
  } ) );
592
591
  }
593
- let reportdate = dayjs().format( 'YYYY-MM-DD' );
592
+
594
593
  let attachments = null;
595
594
  let buffer = await download( exportdata );
596
595
  attachments = {
597
- filename: `dailyInfraReport- ${reportdate}.xlsx`,
596
+ filename: `dailyInfraReport- ${date}.xlsx`,
598
597
  content: buffer,
599
598
  contentType: 'application/xlsx', // e.g., 'application/pdf'
600
599
  };
601
600
 
602
601
 
603
- const subject = `Daily Digest - Infra Downtime Report - ${reportdate}`;
602
+ const subject = `Daily Digest - Infra Downtime Report - ${date}`;
604
603
  const fileContent = readFileSync( join() + '/src/hbs/dailyInfraReport.hbs', 'utf8' );
605
604
  const htmlContent = handlebars.compile( fileContent );
606
605
  let Uidomain = `${appConfig.url.domain}`;
607
606
 
608
607
 
609
- const html = htmlContent( { ...req.body, Uidomain: Uidomain, issueCount: issueCount, avgDownTime: avgDownTime, reportdate: reportdate, content: response, date: date, domain: appConfig.url.apiDomain } );
608
+ const html = htmlContent( { ...req.body, Uidomain: Uidomain, issueCount: issueCount, avgDownTime: avgDownTime, reportdate: date, content: response, date: date, domain: appConfig.url.apiDomain } );
610
609
  if ( isValidEmail( req.body.email ) ) {
611
610
  const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
612
611
  res.sendSuccess( result );
@@ -92,7 +92,7 @@ export async function userTakeTicket( req, res ) {
92
92
  }
93
93
  userTicket = await findOneTangoTicket( query );
94
94
  }
95
- if ( userTicket ) {
95
+ if ( userTicket&&userTicket.ticketId ) {
96
96
  let assignTicket = await updateOneTangoTicket( { ticketId: userTicket.ticketId }, { 'ticketDetails.addressingUser': req.body.userId } );
97
97
  if ( assignTicket ) {
98
98
  res.sendSuccess( 'Ticket Assigned Successfully' );
@@ -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
  },
@@ -1,10 +1,22 @@
1
1
  import express from 'express';
2
2
  import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
3
- import { createTicket } from '../controllers/dataMismatch.controller.js';
4
- import { validateDetails } from '../validations/infra.validation.js';
3
+ import { createTicket, updateMat, activityList, showActivity } from '../controllers/dataMismatch.controller.js';
4
+ import { ticketExists, validateDetails } from '../validations/infra.validation.js';
5
5
  export const dataMismatchTicketRouter = express.Router();
6
6
 
7
7
  dataMismatchTicketRouter.post( '/createTicket', isAllowedSessionHandler, authorize( {
8
8
  userType: [ 'client', 'tango' ], access: [
9
9
  { featureName: 'manage', name: 'tickets', permissions: [ 'isView', 'isEdit' ] } ],
10
10
  } ), validateDetails, createTicket );
11
+ dataMismatchTicketRouter.post( '/updateMat', isAllowedSessionHandler, authorize( {
12
+ userType: [ 'client', 'tango' ], access: [
13
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
14
+ } ), ticketExists, updateMat );
15
+ dataMismatchTicketRouter.post( '/activityList', isAllowedSessionHandler, authorize( {
16
+ userType: [ 'client', 'tango' ], access: [
17
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
18
+ } ), activityList );
19
+ dataMismatchTicketRouter.post( '/showActivity', isAllowedSessionHandler, authorize( {
20
+ userType: [ 'client', 'tango' ], access: [
21
+ { featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
22
+ } ), ticketExists, showActivity );
@@ -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,4 @@ 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 );
83
+
@@ -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
+ }
@@ -9,11 +9,11 @@ export async function validateDetails( req, res, next ) {
9
9
  try {
10
10
  let store = await findOneStore( { storeId: req.body.storeId } );
11
11
  if ( !store ) {
12
- return res.sendError( 'Store Not Available' );
12
+ return res.sendError( 'Store Not Available', 500 );
13
13
  }
14
14
  let client = await findOneClient( { clientId: store.clientId } );
15
15
  if ( !client ) {
16
- return res.sendError( 'Client Not Available' );
16
+ return res.sendError( 'Client Not Available', 500 );
17
17
  }
18
18
 
19
19
  if ( store.spocDetails && store.spocDetails.length > 0 ) {