tango-app-api-infra 3.0.85-dev → 3.0.87-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
|
@@ -5,7 +5,7 @@ export async function createTicket( req, res ) {
|
|
|
5
5
|
try {
|
|
6
6
|
let ticketExist = await findOneTangoTicket( { 'issueType': req.body.issueType, 'basicDetails.storeId': req.body.storeId } );
|
|
7
7
|
if ( ticketExist ) {
|
|
8
|
-
return res.
|
|
8
|
+
return res.status( 409 ).send( 'DataMismatch Ticket Already Exists for the store' );
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
req.body.issueDate = new Date( req.body.Date );
|
|
@@ -74,9 +74,9 @@ export async function migrateStores() {
|
|
|
74
74
|
}
|
|
75
75
|
export async function clientList( req, res ) {
|
|
76
76
|
try {
|
|
77
|
-
let
|
|
77
|
+
let clientList = await findClient( { status: { $in: [ 'active', 'hold' ] } },
|
|
78
78
|
{ 'clientName': 1, 'clientId': 1, 'ticketConfigs': 1 } );
|
|
79
|
-
res.sendSuccess(
|
|
79
|
+
res.sendSuccess( clientList );
|
|
80
80
|
} catch ( error ) {
|
|
81
81
|
logger.error( { error: error, function: 'basicList' } );
|
|
82
82
|
res.sendError( error, 500 );
|
|
@@ -85,7 +85,12 @@ export async function clientList( req, res ) {
|
|
|
85
85
|
|
|
86
86
|
export async function basicList( req, res ) {
|
|
87
87
|
try {
|
|
88
|
-
let
|
|
88
|
+
let clientList = await findClient( { status: { $in: [ 'active', 'hold' ] } }, { 'clientId': 1 } );
|
|
89
|
+
let clients = [];
|
|
90
|
+
for ( let client of clientList ) {
|
|
91
|
+
clients.push( client.clientId );
|
|
92
|
+
}
|
|
93
|
+
let storeList = await findStore( { 'clientId': { $in: clients }, 'status': 'active', 'edge.firstFile': true },
|
|
89
94
|
{ 'storeName': 1, 'storeId': 1, 'ticketConfigs': 1, 'clientId': 1, 'storeProfile.open': 1, 'storeProfile.close': 1, 'storeProfile.timeZone': 1 } );
|
|
90
95
|
res.sendSuccess( storeList );
|
|
91
96
|
} catch ( error ) {
|
|
@@ -449,7 +454,7 @@ export async function infraReportSent( req, res ) {
|
|
|
449
454
|
// if ( req.body.type == 'start' ) {
|
|
450
455
|
// date = dayjs().subtract( 1, 'day' ).format( 'YYYY-MM-DD' );
|
|
451
456
|
// } else if ( req.body.type == 'end' ) {
|
|
452
|
-
let date = dayjs(
|
|
457
|
+
let date = dayjs().format( 'YYYY-MM-DD' );
|
|
453
458
|
// };
|
|
454
459
|
let query = [ {
|
|
455
460
|
$match: {
|
|
@@ -551,10 +556,10 @@ export async function infraReportSent( req, res ) {
|
|
|
551
556
|
'Responded By': clientuser && clientuser.userName ? clientuser.userName : '-',
|
|
552
557
|
'Resolved By': tangouser && tangouser.userName ? tangouser.userName : '-',
|
|
553
558
|
'Ticket Closed Date & Time': element.issueClosedDate ? dayjs( element.issueClosedDate ).tz( 'Asia/Kolkata' ).format( 'YYYY-MM-DD HH:mm A' ) : '-',
|
|
554
|
-
'Latest Comment': element.otherscomment?element.otherscomment:element.commentText,
|
|
559
|
+
'Latest Comment': element.otherscomment ? element.otherscomment : element.commentText,
|
|
555
560
|
'Activity Log': {
|
|
556
561
|
label: 'Link',
|
|
557
|
-
url: `${appConfig.url.domain+'/manage/stores/infra-ticket?storeId='+element.basicDetails.storeId}`,
|
|
562
|
+
url: `${appConfig.url.domain + '/manage/stores/infra-ticket?storeId=' + element.basicDetails.storeId}`,
|
|
558
563
|
},
|
|
559
564
|
} );
|
|
560
565
|
}
|
|
@@ -725,7 +730,7 @@ export async function download( data ) {
|
|
|
725
730
|
for ( let j = 0; j < headers.length; j++ ) {
|
|
726
731
|
const header = headers[j];
|
|
727
732
|
const value = dataRow[header];
|
|
728
|
-
if ( value&& typeof value === 'object' && value.hasOwnProperty( 'label' ) && value.hasOwnProperty( 'url' ) ) {
|
|
733
|
+
if ( value && typeof value === 'object' && value.hasOwnProperty( 'label' ) && value.hasOwnProperty( 'url' ) ) {
|
|
729
734
|
ws.cell( i + 2, j + 1 ).link( value.url );
|
|
730
735
|
ws.cell( i + 2, j + 1 ).string( value.label );
|
|
731
736
|
} else {
|
|
@@ -737,7 +742,7 @@ export async function download( data ) {
|
|
|
737
742
|
}
|
|
738
743
|
export async function edgeApplogsCheck( req, res ) {
|
|
739
744
|
try {
|
|
740
|
-
let finalresult= [];
|
|
745
|
+
let finalresult = [];
|
|
741
746
|
let ticketList = await findTangoTicket( { 'issueDate': new Date( req.body.issueDate ), 'status': { $ne: 'closed' }, 'ticketDetails.issueStatus': 'notidentified', 'issueType': 'infra' } );
|
|
742
747
|
for ( let ticket of ticketList ) {
|
|
743
748
|
req.body.date = dayjs( ticket.createdAt ).format( 'YYYY-MM-DD' );
|
|
@@ -882,7 +887,7 @@ export async function edgeApplogsCheck( req, res ) {
|
|
|
882
887
|
}
|
|
883
888
|
}
|
|
884
889
|
let findissueEdgeApp = {};
|
|
885
|
-
if ( result.length>0 ) {
|
|
890
|
+
if ( result.length > 0 ) {
|
|
886
891
|
for ( let findissue of result ) {
|
|
887
892
|
const istTimestamp = dayjs.utc( ticket.createdAt ).tz( 'Asia/Kolkata' ).format( 'HH:mm:ss' );
|
|
888
893
|
|
|
@@ -909,7 +914,7 @@ export async function edgeApplogsCheck( req, res ) {
|
|
|
909
914
|
const existsInArray = finalresult.some( ( item ) =>
|
|
910
915
|
item.ticketId === ticket.ticketId,
|
|
911
916
|
);
|
|
912
|
-
if ( isOccurringTimeEarlier
|
|
917
|
+
if ( isOccurringTimeEarlier && !existsInArray ) {
|
|
913
918
|
findissueEdgeApp = {
|
|
914
919
|
ticketId: ticket.ticketId,
|
|
915
920
|
storeId: ticket.basicDetails.storeId,
|
|
@@ -936,7 +941,7 @@ export async function edgeApplogsCheck( req, res ) {
|
|
|
936
941
|
updateIssue( findissueEdgeApp );
|
|
937
942
|
finalresult.push( findissueEdgeApp );
|
|
938
943
|
}
|
|
939
|
-
} else if ( findissue.code ==='1005' ) {
|
|
944
|
+
} else if ( findissue.code === '1005' ) {
|
|
940
945
|
const occurringTimeParsed = dayjs( `${req.body.date} ${findissue.edgelog.occuringTime}` );
|
|
941
946
|
const ticketCreatedParsed = dayjs( `${req.body.date} ${istTimestamp}` );
|
|
942
947
|
const isOccurringTimeEarlier = occurringTimeParsed.isBefore( ticketCreatedParsed );
|
|
@@ -479,7 +479,7 @@ function generateTimeSlots( startHour, endHour, interval, req ) {
|
|
|
479
479
|
return timeSlots;
|
|
480
480
|
} catch ( error ) {
|
|
481
481
|
logger.error( { error: error, function: 'generateTimeSlots' } );
|
|
482
|
-
return
|
|
482
|
+
return error;
|
|
483
483
|
}
|
|
484
484
|
};
|
|
485
485
|
|
|
@@ -893,3 +893,122 @@ export async function cameraAngleChange( req, res ) {
|
|
|
893
893
|
return res.sendError( error, 500 );
|
|
894
894
|
}
|
|
895
895
|
}
|
|
896
|
+
function getDatesArray( fromDate, toDate ) {
|
|
897
|
+
let dates = [];
|
|
898
|
+
let currentDate = new Date( fromDate );
|
|
899
|
+
let endDate = new Date( toDate );
|
|
900
|
+
|
|
901
|
+
while ( currentDate <= endDate ) {
|
|
902
|
+
dates.push( currentDate.toISOString().split( 'T' )[0] ); // Convert Date to string format YYYY-MM-DD
|
|
903
|
+
currentDate.setDate( currentDate.getDate() + 1 );
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
return dates;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
function paginateArray( array, offset, limit ) {
|
|
910
|
+
return array.slice( ( offset - 1 ) * limit, offset*limit );
|
|
911
|
+
}
|
|
912
|
+
export async function datewiseDowntime( req, res ) {
|
|
913
|
+
try {
|
|
914
|
+
const store = await findOneStore( { storeId: req.body.storeId } );
|
|
915
|
+
if ( !store ) {
|
|
916
|
+
return res.sendError( 'Stores Not fond', 204 );
|
|
917
|
+
}
|
|
918
|
+
let startHour = store.storeProfile.open.split( ':' )[0];
|
|
919
|
+
let endHour = store.storeProfile.close.split( ':' )[0];
|
|
920
|
+
|
|
921
|
+
let datesArray = getDatesArray( req.body.fromDate, req.body.toDate );
|
|
922
|
+
let paginatedDates = paginateArray( datesArray, req.body.offset, req.body.limit );
|
|
923
|
+
let result = [];
|
|
924
|
+
for ( const singleDate of paginatedDates ) {
|
|
925
|
+
let inputData = {
|
|
926
|
+
start: startHour,
|
|
927
|
+
end: endHour,
|
|
928
|
+
interval: 60,
|
|
929
|
+
};
|
|
930
|
+
req.body.Date= singleDate;
|
|
931
|
+
let storedata = await livecountCheck( inputData, req );
|
|
932
|
+
result.push( storedata[0] );
|
|
933
|
+
}
|
|
934
|
+
res.sendSuccess( {
|
|
935
|
+
count: datesArray.length,
|
|
936
|
+
data: result,
|
|
937
|
+
} );
|
|
938
|
+
} catch ( error ) {
|
|
939
|
+
logger.error( { error: error, function: 'cameraAngleChange' } );
|
|
940
|
+
return res.sendError( error, 500 );
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
export async function livecountCheck( inputData, req ) {
|
|
946
|
+
return new Promise( async ( Resolve, Reject ) => {
|
|
947
|
+
try {
|
|
948
|
+
let TimeSlots = generateTimeSlots( inputData.start, inputData.end, inputData.interval, req );
|
|
949
|
+
let timewise = [];
|
|
950
|
+
for ( const obj of TimeSlots ) {
|
|
951
|
+
obj.startTime = dayjs( obj.from ).format( 'hh:mm A' );
|
|
952
|
+
obj.endTime = dayjs( obj.to ).format( 'hh:mm A' );
|
|
953
|
+
let downTimeQuery = {
|
|
954
|
+
'size': 1,
|
|
955
|
+
'query': {
|
|
956
|
+
'bool': {
|
|
957
|
+
'must': [
|
|
958
|
+
{
|
|
959
|
+
'term': {
|
|
960
|
+
'doc.date.keyword': dayjs( obj.from ).format( 'DD-MM-YYYY' ),
|
|
961
|
+
},
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
'term': {
|
|
965
|
+
'doc.store_id.keyword': req.body.storeId,
|
|
966
|
+
},
|
|
967
|
+
},
|
|
968
|
+
{
|
|
969
|
+
'terms': {
|
|
970
|
+
'doc.hour.keyword': [ obj.hour ],
|
|
971
|
+
},
|
|
972
|
+
},
|
|
973
|
+
],
|
|
974
|
+
|
|
975
|
+
},
|
|
976
|
+
},
|
|
977
|
+
};
|
|
978
|
+
const downtime = await getOpenSearchData( 'live_downtime_hourly', downTimeQuery );
|
|
979
|
+
let streamwiseDowntime = downtime.body.hits.hits.length > 0 ? downtime.body.hits.hits[0]._source.doc.streamwise_downtime : [];
|
|
980
|
+
if ( streamwiseDowntime.length > 0 ) {
|
|
981
|
+
const sum = streamwiseDowntime.reduce( ( accumulator, currentValue ) => {
|
|
982
|
+
return accumulator + currentValue.down_time;
|
|
983
|
+
}, 0 );
|
|
984
|
+
const average = sum / streamwiseDowntime.length;
|
|
985
|
+
obj[obj.startTime + '-' + obj.endTime] = Math.round( average );
|
|
986
|
+
} else {
|
|
987
|
+
obj[obj.startTime + '-' + obj.endTime] = '';
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
timewise.push( obj );
|
|
991
|
+
}
|
|
992
|
+
const mergedData = {
|
|
993
|
+
Date: dayjs( req.body.Date ).format( 'YYYY-MM-DD' ),
|
|
994
|
+
};
|
|
995
|
+
timewise.forEach( ( obj ) => {
|
|
996
|
+
for ( const key in obj ) {
|
|
997
|
+
if ( key !== 'hour' && key !== 'from' && key !== 'to' && key !== 'startTime' && key !== 'endTime' && key !== 'clientId' ) {
|
|
998
|
+
if ( mergedData[key] ) {
|
|
999
|
+
mergedData[key] += obj[key];
|
|
1000
|
+
} else {
|
|
1001
|
+
mergedData[key] = obj[key];
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
} );
|
|
1006
|
+
|
|
1007
|
+
// Create an array with the merged data.
|
|
1008
|
+
const mergedArray = [ mergedData ];
|
|
1009
|
+
Resolve( mergedArray );
|
|
1010
|
+
} catch ( err ) {
|
|
1011
|
+
Reject( err );
|
|
1012
|
+
}
|
|
1013
|
+
} );
|
|
1014
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { isAllowedSessionHandler, authorize } from 'tango-app-api-middleware';
|
|
4
|
-
import { storeTicketList, storeTicketcard, edgeAppLogTable, viewedgeAppLog, cameraAngleChange } from '../controllers/storeInfra.controlller.js';
|
|
4
|
+
import { storeTicketList, storeTicketcard, edgeAppLogTable, viewedgeAppLog, cameraAngleChange, datewiseDowntime } from '../controllers/storeInfra.controlller.js';
|
|
5
5
|
export const storeInfraRouter = express.Router();
|
|
6
6
|
|
|
7
7
|
storeInfraRouter.post( '/storeTicketList', isAllowedSessionHandler, authorize( {
|
|
@@ -25,3 +25,7 @@ storeInfraRouter.post( '/cameraAngleChange', isAllowedSessionHandler, authorize(
|
|
|
25
25
|
{ featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
|
|
26
26
|
} ), cameraAngleChange );
|
|
27
27
|
|
|
28
|
+
storeInfraRouter.post( '/datewiseDowntime', isAllowedSessionHandler, authorize( {
|
|
29
|
+
userType: [ 'client', 'tango' ], access: [
|
|
30
|
+
{ featureName: 'manage', name: 'tickets', permissions: [ 'isView' ] } ],
|
|
31
|
+
} ), datewiseDowntime );
|