tango-app-api-infra 3.0.107-dev → 3.0.108-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.107-dev",
3
+ "version": "3.0.108-dev",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -30,7 +30,7 @@ export async function createTicket( req, res ) {
30
30
  } ];
31
31
  let ticketExists= await findOneTangoTicket( { ticketId: req.body.ticketId } );
32
32
  if ( ticketExists ) {
33
- res.status( 200 ).send( { storeId: req.body.storeId } );
33
+ return res.status( 200 ).send( { message: 'ticketId Exists', storeId: req.body.storeId } );
34
34
  }
35
35
  }
36
36
  if ( req.body.issueType == 'installation' ) {
@@ -72,7 +72,7 @@ export async function createTicket( req, res ) {
72
72
  downtimetotal = 0;
73
73
  }
74
74
 
75
-
75
+ console.log( req.body );
76
76
  let create = await createTangoTicket( req.body );
77
77
  let Timestamp = dayjs().format( 'YYYY-MM-DD HH:mm' );
78
78
  const attachments = null;
@@ -239,14 +239,16 @@ export async function updateTicketIssue( req, res ) {
239
239
  'status': 'inprogress',
240
240
  };
241
241
  }
242
- let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, query );
243
242
  if ( req.body.issueType === 'infra' ) {
244
243
  let client = await findOneClient( { clientId: req.body.basicDetails.clientId } );
245
244
  let refreshdate = dayjs().add( client.ticketConfigs.refreshAlert, 'days' );
246
- req.body.ticketDetails = {
247
- ticketRefreshTime: new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ),
245
+ console.log( new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ) );
246
+ query = { ...query, 'ticketDetails.ticketRefreshTime': new Date( dayjs( refreshdate ).format( 'YYYY-MM-DD' ) ),
248
247
  };
249
248
  }
249
+ console.log( query );
250
+ let updateTicket = await updateOneTangoTicket( { ticketId: req.body.ticketId }, query );
251
+
250
252
  if ( req.body.ticketDetails.ticketType === 'refreshticket' ) {
251
253
  await updateOneTangoTicket( { ticketId: req.body.ticketId }, { 'ticketDetails.refreshTicketStatus': 'identified' } );
252
254
  }
@@ -817,27 +817,30 @@ export async function datewiseDowntime( req, res ) {
817
817
  try {
818
818
  const store = await findOneStore( { storeId: req.body.storeId } );
819
819
  if ( !store ) {
820
- return res.sendError( 'Stores Not fond', 204 );
820
+ return res.sendError( 'Store Not Found', 204 );
821
821
  }
822
- let startHour = store.storeProfile.open.split( ':' )[0];
823
- let endHour = store.storeProfile.close.split( ':' )[0];
824
-
825
- let datesArray = getDatesArray( req.body.fromDate, req.body.toDate );
826
- let paginatedDates = paginateArray( datesArray, req.body.offset, req.body.limit );
827
- let result = [];
828
- for ( const singleDate of paginatedDates ) {
829
- let inputData = {
822
+
823
+ const startHour = parseInt( store.storeProfile.open.split( ':' )[0], 10 );
824
+ const endHour = parseInt( store.storeProfile.close.split( ':' )[0], 10 );
825
+
826
+ const datesArray = getDatesArray( req.body.fromDate, req.body.toDate );
827
+ const paginatedDates = paginateArray( datesArray, req.body.offset, req.body.limit );
828
+
829
+ const resultPromises = paginatedDates.map( ( singleDate ) => {
830
+ const inputData = {
830
831
  start: startHour,
831
832
  end: endHour,
832
833
  interval: 60,
833
834
  };
834
835
  req.body.Date = singleDate;
835
- let storedata = await livecountCheck( inputData, req );
836
- result.push( storedata[0] );
837
- }
836
+ return livecountCheck( inputData, singleDate, req );
837
+ } );
838
+
839
+ const result = await Promise.all( resultPromises );
840
+
838
841
  res.sendSuccess( {
839
842
  count: datesArray.length,
840
- data: result,
843
+ data: result.flat(), // Flatten the array of arrays
841
844
  } );
842
845
  } catch ( error ) {
843
846
  logger.error( { error: error, function: 'datewiseDowntime' } );
@@ -897,73 +900,60 @@ export async function streamwiseDowntime( req, res ) {
897
900
  }
898
901
 
899
902
 
900
- export async function livecountCheck( inputData, req ) {
901
- return new Promise( async ( Resolve, Reject ) => {
902
- try {
903
- let TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
904
- let timewise = [];
905
- for ( const obj of TimeSlots ) {
906
- obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
907
- obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
908
- let downTimeQuery = {
909
- 'size': 1,
910
- 'query': {
911
- 'bool': {
912
- 'must': [
913
- {
914
- 'term': {
915
- 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
916
- },
917
- },
918
- {
919
- 'term': {
920
- 'doc.store_id.keyword': req.body.storeId,
921
- },
922
- },
923
- {
924
- 'terms': {
925
- 'doc.hour.keyword': [ obj.hour ],
926
- },
927
- },
928
- ],
903
+ export async function livecountCheck( inputData, singleDate, req ) {
904
+ try {
905
+ const TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
929
906
 
930
- },
907
+ const queryPromises = TimeSlots.map( async ( obj ) => {
908
+ obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
909
+ obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
910
+
911
+ const downTimeQuery = {
912
+ size: 1,
913
+ query: {
914
+ bool: {
915
+ must: [
916
+ { term: { 'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ) } },
917
+ { term: { 'doc.store_id.keyword': req.body.storeId } },
918
+ { terms: { 'doc.hour.keyword': [ obj.hour ] } },
919
+ ],
931
920
  },
932
- };
933
- const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
934
- let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
935
- if ( streamwiseDowntime.length > 0 ) {
936
- const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
937
- return accumulator + currentValue.down_time;
938
- }, 0 );
939
- const average = sum / streamwiseDowntime.length;
940
- obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
941
- } else {
942
- obj[obj.startTime + '-' + obj.endTime] = '';
943
- }
921
+ },
922
+ };
944
923
 
945
- timewise.push( obj );
924
+ const downtime = await getOpenSearchData( JSON.parse( process.env.OPENSEARCH ).downTimeHourly, downTimeQuery );
925
+ const streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
926
+ if ( streamwiseDowntime.length > 0 ) {
927
+ const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => accumulator + currentValue.down_time, 0 );
928
+ const average = sum / streamwiseDowntime.length;
929
+ obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
930
+ } else {
931
+ obj[obj.startTime + '-' + obj.endTime] = '';
946
932
  }
947
- const mergedData = {
948
- Date: dayjs( req.body.Date ).format( 'YYYY-MM-DD' ),
949
- };
950
- timewise.forEach( ( obj ) => {
951
- for ( const key in obj ) {
952
- if ( key !== 'hour' && key !== 'from' && key !== 'to' && key !== 'startTime' && key !== 'endTime' && key !== 'clientId' ) {
953
- if ( mergedData[key] ) {
954
- mergedData[key] += obj[key];
955
- } else {
956
- mergedData[key] = obj[key];
957
- }
933
+ return obj;
934
+ } );
935
+
936
+ const timewise = await Promise.all( queryPromises );
937
+
938
+
939
+ const mergedData = {
940
+ Date: dayjs( singleDate ).format( 'YYYY-MM-DD' ),
941
+ };
942
+
943
+ timewise.forEach( ( obj ) => {
944
+ for ( const key in obj ) {
945
+ if ( key !== 'hour' && key !== 'from' && key !== 'to' && key !== 'startTime' && key !== 'endTime' && key !== 'clientId' ) {
946
+ if ( mergedData[key] ) {
947
+ mergedData[key] += obj[key];
948
+ } else {
949
+ mergedData[key] = obj[key];
958
950
  }
959
951
  }
960
- } );
952
+ }
953
+ } );
961
954
 
962
- // Create an array with the merged data.
963
- const mergedArray = [ mergedData ];
964
- Resolve( mergedArray );
965
- } catch ( err ) {
966
- Reject( err );
967
- }
968
- } );
955
+ return [ mergedData ];
956
+ } catch ( err ) {
957
+ throw err;
958
+ }
969
959
  }
@@ -24,7 +24,8 @@ export async function userTakeTicket( req, res ) {
24
24
  if ( req.body.issueType == 'infra' ) {
25
25
  let query = {
26
26
  'status': { $ne: 'closed' },
27
- 'issueType': 'infra', 'ticketDetails.assigntoUser': true,
27
+ 'issueType': 'infra',
28
+ 'ticketDetails.assigntoUser': true,
28
29
  'ticketDetails.addressingUser': { $exists: false },
29
30
  'ticketDetails.issueStatus': 'notidentified',
30
31
  'ticketDetails.addressingClient': { $exists: false },
@@ -37,11 +38,12 @@ export async function userTakeTicket( req, res ) {
37
38
  if ( !userTicket ) {
38
39
  let query = {
39
40
  'status': { $ne: 'closed' },
40
- 'basicDetails.clientId': { $in: assignedClients },
41
41
  'issueType': 'infra',
42
- 'ticketType': 'refreshticket',
42
+ 'ticketDetails.ticketType': 'refreshticket',
43
43
  'ticketDetails.refreshTicketStatus': 'notidentified',
44
44
  };
45
+ console.log( query, assignedClients );
46
+
45
47
  if ( assignedClients.length > 0 ) {
46
48
  query = ( { ...query, ...{ 'basicDetails.clientId': { $in: assignedClients } } } );
47
49
  }
@@ -352,7 +354,6 @@ export async function workHistory( req, res ) {
352
354
  $match: {
353
355
  $and: [
354
356
  { 'basicDetails.clientId': { $in: req.body.clientId } },
355
- { 'status': 'closed' },
356
357
  { issueType: req.body.issueType },
357
358
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
358
359
  ],
@@ -363,7 +364,6 @@ export async function workHistory( req, res ) {
363
364
  $match: {
364
365
  $and: [
365
366
  { 'basicDetails.clientId': { $in: req.body.clientId } },
366
- { 'status': 'closed' },
367
367
  { issueType: { $in: [ 'highcount', 'lowcount' ] } },
368
368
  { 'ticketDetails.addressingUser': new mongoose.Types.ObjectId( req.body.userId ) },
369
369
  ],
@@ -420,6 +420,18 @@ export async function workHistory( req, res ) {
420
420
  },
421
421
  );
422
422
  }
423
+ } else {
424
+ query.push(
425
+ {
426
+ $match: {
427
+ $and: [
428
+ { createdAt: { $gte: date.start } },
429
+ { createdAt: { $lte: date.end } },
430
+ ],
431
+
432
+ },
433
+ },
434
+ );
423
435
  }
424
436
 
425
437
  if ( req.body.storeFilter && req.body.storeFilter.length > 0 ) {
@@ -537,6 +549,8 @@ export async function workHistory( req, res ) {
537
549
  'Closed on': element.issueClosedDate,
538
550
  'Issue Identified on': element.issueIdentifiedDate,
539
551
  'Issue Type': element.infraIssue ? element.infraIssue : '-',
552
+ 'Status': element.status,
553
+
540
554
  };
541
555
  }
542
556
  if ( req.body.issueType === 'dataMismatch' ) {
@@ -550,6 +564,7 @@ export async function workHistory( req, res ) {
550
564
  'Issue date': dayjs( element.issueDate ).format( 'DD MMM, YYYY' ),
551
565
  'Closed on': element.issueClosedDate,
552
566
  'Issue Type': element.issueType ? element.issueType : '-',
567
+ 'Status': element.status,
553
568
  };
554
569
  }
555
570
  exportdata.push( data );