tango-app-api-infra 3.0.48-dev → 3.0.50-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.48-dev",
3
+ "version": "3.0.50-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,7 +16,7 @@ export async function infraCard( req, res ) {
16
16
  $match: {
17
17
  $and: [
18
18
  { issueType: 'infra' },
19
- { 'ticketDetails.issueStatus': 'identified' },
19
+ { status: { $ne: 'closed' } },
20
20
  { 'basicDetails.clientId': { $in: req.body.clientId } },
21
21
  { createdAt: { $gte: date.start } },
22
22
  { createdAt: { $lte: date.end } },
@@ -12,6 +12,7 @@ import { join } from 'path';
12
12
  import handlebars from 'handlebars';
13
13
  import { findOneGroup } from '../services/group.service.js';
14
14
  import htmlpdf from 'html-pdf-node';
15
+ import mongoose from 'mongoose';
15
16
  export async function createTicket( req, res ) {
16
17
  try {
17
18
  req.body.issueDate = new Date( req.body.Date );
@@ -478,7 +479,7 @@ export async function emailUserList( req, res ) {
478
479
  } else if ( user.role != 'superadmin' ) {
479
480
  if ( user.assignedType == 'group' ) {
480
481
  for ( let group of user.assignedValue ) {
481
- let groupdata = await findOneGroup( { groupName: group } );
482
+ let groupdata = await findOneGroup( { _id: new mongoose.Types.ObjectId( group ), clientId: inputData.clientId } );
482
483
  let storelist = await findStore( { clientId: inputData.clientId, storeId: { $in: groupdata.storeList } }, { storeName: 1 } );
483
484
  user.assigned = storelist.length;
484
485
  user.assignedValue = storelist;
@@ -215,71 +215,75 @@ export async function closeTicket( req, res ) {
215
215
  try {
216
216
  for ( let ticket of req.body.TicketList ) {
217
217
  let getTicket = await findOneTangoTicket( { ticketId: ticket.ticketId } );
218
- if ( ticket.status == 'closed' ) {
219
- getTicket.ticketActivity.push( {
220
- actionType: 'dataRecived',
221
- actionBy: 'Tango',
222
- } );
223
- }
224
- await updateOneTangoTicket( { ticketId: ticket.ticketId },
225
- {
226
- status: ticket.status,
227
- ticketActivity: getTicket.ticketActivity,
228
- issueClosedDate: new Date(),
229
- },
230
- );
231
- let downTimeQuery = {
232
- 'size': 1,
233
- 'query': {
234
- 'bool': {
235
- 'must': [
236
- {
237
- 'term': {
238
- 'doc.date.keyword': dayjs( getTicket.issueDate ).format( 'DD-MM-YYYY' ),
218
+ if ( getTicket ) {
219
+ if ( ticket.status == 'closed' ) {
220
+ getTicket.ticketActivity.push( {
221
+ actionType: 'dataRecived',
222
+ actionBy: 'Tango',
223
+ } );
224
+ }
225
+ await updateOneTangoTicket( { ticketId: ticket.ticketId },
226
+ {
227
+ status: ticket.status,
228
+ ticketActivity: getTicket.ticketActivity,
229
+ issueClosedDate: new Date(),
230
+ },
231
+ );
232
+ let downTimeQuery = {
233
+ 'size': 1,
234
+ 'query': {
235
+ 'bool': {
236
+ 'must': [
237
+ {
238
+ 'term': {
239
+ 'doc.date.keyword': dayjs( getTicket.issueDate ).format( 'DD-MM-YYYY' ),
240
+ },
239
241
  },
240
- },
241
- {
242
- 'term': {
243
- 'doc.store_id.keyword': getTicket.basicDetails.storeId,
242
+ {
243
+ 'term': {
244
+ 'doc.store_id.keyword': getTicket.basicDetails.storeId,
245
+ },
244
246
  },
245
- },
246
247
 
247
- ],
248
+ ],
248
249
 
250
+ },
249
251
  },
250
- },
251
- };
252
- let downtimetotal;
253
- const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
254
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
255
- if ( streamwiseDowntime.length > 0 ) {
256
- const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
257
- return accumulator + currentValue.down_time;
258
- }, 0 );
259
- const average = sum / streamwiseDowntime.length;
260
- downtimetotal = Math.round( average );
261
- } else {
262
- downtimetotal = 0;
263
- }
252
+ };
253
+ let downtimetotal;
254
+ const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
255
+ let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
256
+ if ( streamwiseDowntime.length > 0 ) {
257
+ const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
258
+ return accumulator + currentValue.down_time;
259
+ }, 0 );
260
+ const average = sum / streamwiseDowntime.length;
261
+ downtimetotal = Math.round( average );
262
+ } else {
263
+ downtimetotal = 0;
264
+ }
264
265
 
265
- let Issue = getTicket.ticketActivity.filter( ( a ) => a.actionType == 'issueUpdate' );
266
- let primaryIssue = '';
266
+ let Issue = getTicket.ticketActivity.filter( ( a ) => a.actionType == 'issueUpdate' );
267
+ let primaryIssue = '';
267
268
 
268
- if ( Issue.length > 0 && Issue[0].reasons.length > 0 ) {
269
- primaryIssue = Issue[0].reasons[0].primaryIssue;
270
- }
271
- let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
272
- const attachments = null;
273
- const subject = `Tango Eye - Infra Ticket Closed for ${getTicket.basicDetails.storeName} `;
274
- const fileContent = readFileSync( join() + '/src/hbs/closeTicekt.hbs', 'utf8' );
275
- const htmlContent = handlebars.compile( fileContent );
276
- let store = await findOneStore( { storeId: getTicket.basicDetails.storeId } );
277
- if ( store.spocDetails && store.spocDetails.length > 0 ) {
278
- let spocEmail = store.spocDetails[0].email;
279
- let spocName = store.spocDetails[0].name;
280
- let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
281
- 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 } );
282
- await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
269
+ if ( Issue.length > 0 && Issue[0].reasons.length > 0 ) {
270
+ primaryIssue = Issue[0].reasons[0].primaryIssue;
271
+ }
272
+ let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
273
+ const attachments = null;
274
+ const subject = `Tango Eye - Infra Ticket Closed for ${getTicket.basicDetails.storeName} `;
275
+ const fileContent = readFileSync( join() + '/src/hbs/closeTicekt.hbs', 'utf8' );
276
+ const htmlContent = handlebars.compile( fileContent );
277
+ let store = await findOneStore( { storeId: getTicket.basicDetails.storeId } );
278
+ if ( store.spocDetails && store.spocDetails.length > 0 ) {
279
+ let spocEmail = store.spocDetails[0].email;
280
+ let spocName = store.spocDetails[0].name;
281
+ let Uidomain = `${appConfig.url.domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
282
+ 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 } );
283
+ if ( spocEmail ) {
284
+ await sendEmailWithSES( spocEmail, subject, html, attachments, appConfig.cloud.aws.ses.adminEmail );
285
+ }
286
+ }
283
287
  }
284
288
  }
285
289
 
@@ -59,6 +59,17 @@ export async function validateTicket( req, res, next ) {
59
59
  if ( Ticket ) {
60
60
  return res.sendSuccess( 'Infra Ticket Already Exists for the day' );
61
61
  }
62
+ let refreshTicket = await findOneTangoTicket(
63
+ {
64
+ 'basicDetails.storeId': req.body.basicDetails.storeId,
65
+ 'issueType': 'infra',
66
+ 'status': { $ne: 'closed' },
67
+ 'ticketDetails.ticketType': 'refreshticket',
68
+ },
69
+ );
70
+ if ( refreshTicket ) {
71
+ return res.sendSuccess( 'refreshTicket Ticket Already Exists for the Store' );
72
+ }
62
73
  } else if ( req.body.issueType == 'installation' ) {
63
74
  let Ticket = await findOneTangoTicket(
64
75
  {