tango-app-api-infra 3.0.52-dev → 3.1.0

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.52-dev",
3
+ "version": "3.1.0",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  "mongodb": "^6.4.0",
26
26
  "nodemon": "^3.1.0",
27
27
  "tango-api-schema": "^2.0.77",
28
- "tango-app-api-middleware": "^1.0.54-dev",
28
+ "tango-app-api-middleware": "^3.1.1",
29
29
  "winston": "^3.12.0",
30
30
  "winston-daily-rotate-file": "^5.0.0"
31
31
  },
@@ -75,7 +75,7 @@ export async function createTicket( req, res ) {
75
75
  let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${req.body.basicDetails.storeId}`;
76
76
 
77
77
  const html = htmlContent( { ...req.body, Uidomain: Uidomain, domain: appConfig.url.apiDomain, date: dayjs( req.body.issueDate ).format( 'YYYY-MM-DD' ), downtimetotal: downtimetotal, Timestamp: Timestamp } );
78
- if ( req.body.spocEmail&&req.body.issueType == 'infra' ) {
78
+ if ( req.body.spocEmail&&req.body.issueType == 'infra'&&isValidEmail( req.body.spocEmail ) ) {
79
79
  await sendEmailWithSES( req.body.spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
80
80
  }
81
81
  if ( create ) {
@@ -86,6 +86,10 @@ export async function createTicket( req, res ) {
86
86
  return res.sendError( error, 500 );
87
87
  }
88
88
  }
89
+ function isValidEmail( email ) {
90
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
91
+ return emailRegex.test( email );
92
+ }
89
93
  export async function bulkcreateTicket( req, res ) {
90
94
  try {
91
95
  let response = {};
@@ -284,7 +288,7 @@ export async function viewTicket( req, res ) {
284
288
  if ( ticket.attachments.hasOwnProperty( index ) ) {
285
289
  let file = ticket.attachments[index];
286
290
  let params = {
287
- Bucket: 'tango-client-sandbox',
291
+ Bucket: appConfig.cloud.aws.bucket.ticket,
288
292
  file_path: file.filePath,
289
293
  };
290
294
  let attachments = await signedUrl( params );
@@ -336,7 +340,7 @@ export async function uploadAttachments( req, res ) {
336
340
  for ( let singleImg in req.files.img ) {
337
341
  if ( req.files.img.hasOwnProperty( singleImg ) ) {
338
342
  let params = {
339
- Bucket: 'tango-client-sandbox',
343
+ Bucket: appConfig.cloud.aws.bucket.ticket,
340
344
  Key: req.params.ticketId + '/',
341
345
  ContentType: 'multipart/form-data',
342
346
  body: req.files.img[singleImg].data,
@@ -360,7 +364,7 @@ export async function uploadAttachments( req, res ) {
360
364
  let oldticket = await findOneTangoTicket( { ticketId: req.params.ticketId } );
361
365
  let attachments = oldticket.attachments;
362
366
  let params = {
363
- Bucket: 'tango-client-sandbox',
367
+ Bucket: appConfig.cloud.aws.bucket.ticket,
364
368
  Key: req.params.ticketId + '/',
365
369
  ContentType: 'multipart/form-data',
366
370
  body: req.files.img.data,
@@ -201,7 +201,7 @@ export async function updateRefreshTicket( req, res ) {
201
201
  }
202
202
  let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
203
203
  const html = htmlContent( { ...getTicket, Uidomain: Uidomain, primary: primaryIssue, storeName: getTicket.basicDetails.storeName, hibernation: '', spocName: spocName, date: dayjs( getTicket.issueDate ).format( 'YYYY-MM-DD' ), downtimetotal: downtimetotal, Timestamp: Timestamp, domain: appConfig.url.apiDomain } );
204
- if ( spocEmail ) {
204
+ if ( spocEmail && isValidEmail( spocEmail ) ) {
205
205
  await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
206
206
  }
207
207
  }
@@ -221,6 +221,7 @@ export async function closeTicket( req, res ) {
221
221
  if ( ticket.status == 'closed' ) {
222
222
  getTicket.ticketActivity.push( {
223
223
  actionType: 'dataRecived',
224
+ timeStamp: new Date(),
224
225
  actionBy: 'Tango',
225
226
  } );
226
227
  }
@@ -282,7 +283,7 @@ export async function closeTicket( req, res ) {
282
283
  let spocName = store.spocDetails[0].name;
283
284
  let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
284
285
  const html = htmlContent( { ...getTicket, Uidomain: Uidomain, primaryIssue: primaryIssue, storeName: getTicket.basicDetails.storeName, spocName: spocName, date: dayjs( getTicket.issueDate ).format( 'YYYY-MM-DD HH:mm' ), downtimetotal: downtimetotal, Timestamp: Timestamp, domain: appConfig.url.apiDomain } );
285
- if ( spocEmail && spocEmail != '' &&spocEmail!='none'&& spocEmail != undefined ) {
286
+ if ( spocEmail && isValidEmail( spocEmail ) ) {
286
287
  await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
287
288
  }
288
289
  }
@@ -295,6 +296,10 @@ export async function closeTicket( req, res ) {
295
296
  res.sendError( error, 500 );
296
297
  }
297
298
  }
299
+ function isValidEmail( email ) {
300
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
301
+ return emailRegex.test( email );
302
+ }
298
303
  export async function emailUserList( req, res ) {
299
304
  try {
300
305
  let clientList = await aggregateClient( [
@@ -600,7 +605,10 @@ export async function infraReportSent( req, res ) {
600
605
 
601
606
 
602
607
  const html = htmlContent( { ...req.body, Uidomain: Uidomain, issueCount: issueCount, avgDownTime: avgDownTime, reportdate: reportdate, content: response, date: date, domain: appConfig.url.apiDomain } );
603
- const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
608
+ if ( isValidEmail( req.body.email ) ) {
609
+ const result = await sendEmailWithSES( req.body.email, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
610
+ res.sendSuccess( result );
611
+ }
604
612
  res.sendSuccess( result );
605
613
  } catch ( error ) {
606
614
  logger.error( { error: error, function: 'infraReportSent' } );
@@ -4,7 +4,7 @@ import { aggregateTangoTicket } from '../services/tangoTicket.service.js';
4
4
  import { findOneStore } from '../services/store.service.js';
5
5
  import dayjs from 'dayjs';
6
6
  import { findinfraReason } from '../services/infraReason.service.js';
7
- import { signedUrl } from 'tango-app-api-middleware';
7
+ import { signedUrl, appConfig } from 'tango-app-api-middleware';
8
8
  export async function storeTicketList( req, res ) {
9
9
  try {
10
10
  let date = await getUTC( new Date( req.body.fromDate ), new Date( req.body.toDate ) );
@@ -803,7 +803,7 @@ export async function cameraAngleChange( req, res ) {
803
803
  let changeDetected = result.camera_info.filter( ( cam ) => cam.stream == req.body.StreamName );
804
804
  if ( changeDetected.length == 1 ) {
805
805
  let params = {
806
- Bucket: 'tango-client-sandbox',
806
+ Bucket: appConfig.cloud.aws.bucket.ticket,
807
807
  file_path: changeDetected[0].path,
808
808
  };
809
809
  let Image = await signedUrl( params );