tango-app-api-infra 3.1.28 → 3.1.29

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.28",
3
+ "version": "3.1.29",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -69,19 +69,6 @@ export async function createTicket( req, res ) {
69
69
  showToClient: req.body.showToClient,
70
70
  processType: ( auditInputData?.data?.length && auditOutputData?.data?.length ) ? 'audit' : 'reduction',
71
71
  };
72
-
73
- const reqData = {
74
- 'dateString': dayjs( new Date( req.body.Date ) ).format( 'YYYY-MM-DD' ),
75
- 'storeId': req.body.storeId,
76
- };
77
-
78
-
79
- const getFootfall = await postApi( `${JSON.parse( process.env.URL ).oldapidomain}/getFootfall`, reqData );
80
-
81
- if ( getFootfall?.data?.length ) {
82
- req.body.dataMismatch['reportedFootfall'] = getFootfall.data[0].footfall_count;
83
- }
84
-
85
72
  req.body.issueDate = new Date( req.body.Date );
86
73
  req.body.ticketId = 'TE_DM_' + new Date().valueOf();
87
74
  let create = await createTangoTicket( req.body );
@@ -131,25 +118,6 @@ export async function createTicket( req, res ) {
131
118
  }
132
119
  }
133
120
 
134
- async function postApi( url, data ) {
135
- const requestOptions = {
136
- method: 'POST',
137
- headers: {
138
- 'Content-Type': 'application/json',
139
- 'Authorization': 'Bearer d47433f8-9a33-47c7-ba43-1a0fbac28f66',
140
- },
141
- body: JSON.stringify( data ),
142
- };
143
-
144
- try {
145
- const response = await fetch( url, requestOptions );
146
- const data = await response.json();
147
- return data;
148
- } catch ( error ) {
149
- logger.error( { error: error, message: data, function: 'postApi' } );
150
- }
151
- }
152
-
153
121
  export async function updateMat( req, res ) {
154
122
  try {
155
123
  let updateValue = {};
@@ -76,7 +76,7 @@ export async function clientList( req, res ) {
76
76
  try {
77
77
  let clientList = await findClient( { status: { $in: [ 'active', 'hold' ] } },
78
78
  { 'clientName': 1, 'clientId': 1, 'ticketConfigs': 1 } );
79
- logger.info({clientList:clientList,"message":"clientList"})
79
+ logger.info( { 'clientList': clientList, 'message': 'clientList' } );
80
80
  res.sendSuccess( clientList );
81
81
  } catch ( error ) {
82
82
  logger.error( { error: error, function: 'basicList' } );
@@ -93,7 +93,7 @@ export async function basicList( req, res ) {
93
93
  }
94
94
  let storeList = await findStore( { 'clientId': { $in: clients }, 'status': 'active', 'edge.firstFile': true },
95
95
  { 'storeName': 1, 'storeId': 1, 'ticketConfigs': 1, 'clientId': 1, 'storeProfile.open': 1, 'storeProfile.close': 1, 'storeProfile.timeZone': 1 } );
96
- logger.info({storeList:storeList,"message":"storeList"})
96
+ logger.info( { 'storeList': storeList, 'message': 'storeList' } );
97
97
 
98
98
  res.sendSuccess( storeList );
99
99
  } catch ( error ) {
@@ -106,7 +106,7 @@ export async function basicList( req, res ) {
106
106
  export async function setTicketTime( req, res ) {
107
107
  try {
108
108
  let input = req.body;
109
- logger.info( { input: input ,"message":"setTicketTime"} );
109
+ logger.info( { 'input': input, 'message': 'setTicketTime' } );
110
110
  for ( let i = 0; i < input.stores.length; i++ ) {
111
111
  await updateOneStore( { storeId: input.stores[i].storeId }, { 'ticketConfigs.nextTicektGenerationTime': new Date( input.stores[i].nextTicektGenerationTime ) } );
112
112
  };
@@ -120,7 +120,7 @@ export async function setTicketTime( req, res ) {
120
120
  export async function downStoresList( req, res ) {
121
121
  try {
122
122
  let storesList = await findStore( { 'ticketConfigs.hibernation': { $lt: new Date() }, 'ticketConfigs.nextTicektGenerationTime': new Date( req.body.getTime ) }, { storeId: 1, storeName: 1, storeProfile: 1, ticketConfigs: 1 } );
123
- logger.info( { storesList: storesList,"message":"downStoresList" } );
123
+ logger.info( { 'storesList': storesList, 'message': 'downStoresList' } );
124
124
  if ( storesList.length > 0 ) {
125
125
  res.sendSuccess( storesList );
126
126
  } else {
@@ -163,58 +163,63 @@ export async function updateRefreshTicket( req, res ) {
163
163
  let getTicket = await findOneTangoTicket( { ticketId: ticket.ticketId } );
164
164
  await updateOneTangoTicket( { ticketId: ticket.ticketId }, { 'ticketDetails.ticketType': 'refreshticket', 'ticketDetails.refreshTicketStatus': 'notidentified' } );
165
165
  await updateOneTangoTicketunset( { ticketId: ticket.ticketId }, { 'ticketDetails.addressingUser': 1 } );
166
- let downTimeQuery = {
167
- 'size': 1,
168
- 'query': {
169
- 'bool': {
170
- 'must': [
171
- {
172
- 'term': {
173
- 'doc.date.keyword': dayjs( getTicket.issueDate ).format( 'DD-MM-YYYY' ),
174
- },
175
- },
176
- {
177
- 'term': {
178
- 'doc.store_id.keyword': getTicket.basicDetails.storeId,
179
- },
180
- },
166
+ if ( getTicket&&getTicket.basicDetails ) {
167
+ let getclient = await findOneClient( { clientId: getTicket.basicDetails.clientId } );
168
+ if ( getclient.ticketConfigs.emailAlert ) {
169
+ let downTimeQuery = {
170
+ 'size': 1,
171
+ 'query': {
172
+ 'bool': {
173
+ 'must': [
174
+ {
175
+ 'term': {
176
+ 'doc.date.keyword': dayjs( getTicket.issueDate ).format( 'DD-MM-YYYY' ),
177
+ },
178
+ },
179
+ {
180
+ 'term': {
181
+ 'doc.store_id.keyword': getTicket.basicDetails.storeId,
182
+ },
183
+ },
181
184
 
182
- ],
185
+ ],
183
186
 
184
- },
185
- },
186
- };
187
- let downtimetotal;
188
- const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
189
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
190
- if ( streamwiseDowntime.length > 0 ) {
191
- const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
192
- return accumulator + currentValue.down_time;
193
- }, 0 );
194
- const average = sum / streamwiseDowntime.length;
195
- downtimetotal = Math.round( average );
196
- } else {
197
- downtimetotal = 0;
198
- }
199
- let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
200
- const attachments = null;
201
- const subject = `Tango Eye - Infra Ticket Closed for ${getTicket.basicDetails.storeName} `;
202
- const fileContent = readFileSync( join() + '/src/hbs/refreshTicket.hbs', 'utf8' );
203
- const htmlContent = handlebars.compile( fileContent );
204
- let store = await findOneStore( { storeId: getTicket.basicDetails.storeId } );
205
- if ( store.spocDetails && store.spocDetails.length > 0 ) {
206
- let spocEmail = store.spocDetails[0].email;
207
- let spocName = store.spocDetails[0].name;
208
- let Issue = getTicket.ticketActivity.filter( ( a ) => a.actionType == 'issueUpdate' );
209
- let primaryIssue = 'Not Identified';
210
- if ( Issue.length > 0 && Issue[0].reasons.length > 0 ) {
211
- primaryIssue = Issue[0].reasons[0].primaryIssue;
212
- }
213
- let Uidomain = `${JSON.parse( process.env.URL ).domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
214
- let getclient = await findOneClient( { clientId: getTicket.basicDetails.clientId } );
215
- 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: JSON.parse( process.env.URL ).apiDomain } );
216
- if ( getclient.ticketConfigs.emailAlert && spocEmail && isValidEmail( spocEmail ) ) {
217
- await sendEmailWithSES( spocEmail, subject, html, attachments, JSON.parse( process.env.SES ).adminEmail );
187
+ },
188
+ },
189
+ };
190
+ let downtimetotal;
191
+ const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
192
+ let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
193
+ if ( streamwiseDowntime.length > 0 ) {
194
+ const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
195
+ return accumulator + currentValue.down_time;
196
+ }, 0 );
197
+ const average = sum / streamwiseDowntime.length;
198
+ downtimetotal = Math.round( average );
199
+ } else {
200
+ downtimetotal = 0;
201
+ }
202
+ let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
203
+ const attachments = null;
204
+ const subject = `Tango Eye - Infra Ticket Closed for ${getTicket.basicDetails.storeName} `;
205
+ const fileContent = readFileSync( join() + '/src/hbs/refreshTicket.hbs', 'utf8' );
206
+ const htmlContent = handlebars.compile( fileContent );
207
+ let store = await findOneStore( { storeId: getTicket.basicDetails.storeId } );
208
+ if ( store.spocDetails && store.spocDetails.length > 0 ) {
209
+ let spocEmail = store.spocDetails[0].email;
210
+ let spocName = store.spocDetails[0].name;
211
+ let Issue = getTicket.ticketActivity.filter( ( a ) => a.actionType == 'issueUpdate' );
212
+ let primaryIssue = 'Not Identified';
213
+ if ( Issue.length > 0 && Issue[0].reasons.length > 0 ) {
214
+ primaryIssue = Issue[0].reasons[0].primaryIssue;
215
+ }
216
+ let Uidomain = `${JSON.parse( process.env.URL ).domain}/manage/stores/infra-ticket?storeId=${getTicket.basicDetails.storeId}`;
217
+
218
+ 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: JSON.parse( process.env.URL ).apiDomain } );
219
+ if ( spocEmail && isValidEmail( spocEmail ) ) {
220
+ await sendEmailWithSES( spocEmail, subject, html, attachments, JSON.parse( process.env.SES ).adminEmail );
221
+ }
222
+ }
218
223
  }
219
224
  }
220
225
  }
@@ -357,6 +357,9 @@ export async function edgeAppLogTable( req, res ) {
357
357
  const downtimeData = downtimeResult?.body?.hits?.hits ?? [];
358
358
 
359
359
  for ( const obj of timeSlots ) {
360
+ if ( ( obj.hour ).toString().length === 1 ) {
361
+ obj.hour = obj.hour.toString().padStart( 2, '0' );
362
+ }
360
363
  const hour = obj.hour;
361
364
  obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
362
365
  obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
@@ -785,6 +788,10 @@ export async function streamwiseDowntime( req, res ) {
785
788
  const downTimeIndex = parsedOpenSearch.downTimeHourly;
786
789
 
787
790
  const batchRequests = TimeSlots.map( async ( obj ) => {
791
+ if ( ( obj.hour ).toString().length ===1 ) {
792
+ obj.hour = obj.hour.toString().padStart( 2, '0' );
793
+ }
794
+
788
795
  const formattedDate = dayjs( obj.from ).format( 'DD-MM-YYYY' );
789
796
  const downTimeQuery = {
790
797
  size: 1,