tango-app-api-infra 3.9.5-vms.61 → 3.9.5-vms.62
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
|
@@ -6,9 +6,9 @@ import { findOneRevopDownload, upsertRevopDownload } from '../services/revopDown
|
|
|
6
6
|
import dayjs from 'dayjs';
|
|
7
7
|
import utc from 'dayjs/plugin/utc.js';
|
|
8
8
|
import timezone from 'dayjs/plugin/timezone.js';
|
|
9
|
-
import { findUser } from '../services/user.service.js';
|
|
10
9
|
import { findOneClient } from '../services/client.service.js';
|
|
11
|
-
|
|
10
|
+
import { findUser, findOneUser } from '../services/user.service.js';
|
|
11
|
+
import { sendPushNotification } from 'tango-app-api-middleware';
|
|
12
12
|
dayjs.extend( utc );
|
|
13
13
|
dayjs.extend( timezone );
|
|
14
14
|
|
|
@@ -157,6 +157,7 @@ export async function tangoReviewTicket( req, res ) {
|
|
|
157
157
|
};
|
|
158
158
|
let findTicket = await getOpenSearchData( openSearch.footfallDirectory, findQuery );
|
|
159
159
|
let Ticket = findTicket.body?.hits?.hits;
|
|
160
|
+
console.log( '🚀 ~ tangoReviewTicket ~ Ticket:', Ticket );
|
|
160
161
|
if ( Ticket.length === 0 ) {
|
|
161
162
|
return res.sendError( 'Ticket not found', 400 );
|
|
162
163
|
}
|
|
@@ -391,6 +392,28 @@ export async function tangoReviewTicket( req, res ) {
|
|
|
391
392
|
);
|
|
392
393
|
}
|
|
393
394
|
|
|
395
|
+
if ( Ticket[0]?._source?.type==='store' ) {
|
|
396
|
+
let userData = await findOneUser( { email: Ticket[0]?._source?.createdByEmail } );
|
|
397
|
+
let title = `Received response for the Footfall ticket raised.`;
|
|
398
|
+
let createdOn = dayjs( Ticket[0]?._source?.dateString ).format( 'DD MMM YYYY' );
|
|
399
|
+
let description = `Raised on ${createdOn}`;
|
|
400
|
+
console.log( '🚀 ~ ticketCreation ~ userData.role:', userData.email );
|
|
401
|
+
let Data = {
|
|
402
|
+
'title': title,
|
|
403
|
+
'body': description,
|
|
404
|
+
'type': 'closed',
|
|
405
|
+
'date': Ticket[0]?._source?.dateString,
|
|
406
|
+
'storeId': Ticket[0]?._source?.storeId,
|
|
407
|
+
'clientId': Ticket[0]?._source?.clientId,
|
|
408
|
+
'ticketId': Ticket[0]?._source?.ticketId,
|
|
409
|
+
};
|
|
410
|
+
if ( userData && userData.fcmToken ) {
|
|
411
|
+
const fcmToken = userData.fcmToken;
|
|
412
|
+
await sendPushNotification( title, description, fcmToken, Data );
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
// return;
|
|
416
|
+
|
|
394
417
|
let id = `${inputData.storeId}_${inputData.dateString}_footfall-directory-tagging`;
|
|
395
418
|
if ( inputData.ticketType === 'internal' ) {
|
|
396
419
|
id = `${inputData.storeId}_${inputData.dateString}_internal_footfall-directory-tagging`;
|
|
@@ -883,14 +906,14 @@ export async function ticketList( req, res ) {
|
|
|
883
906
|
};
|
|
884
907
|
|
|
885
908
|
if ( inputData.sortBy ) {
|
|
886
|
-
let sortOrder = inputData.sortOrder === 1? 'asc': 'desc';
|
|
909
|
+
let sortOrder = inputData.sortOrder === 1 ? 'asc' : 'desc';
|
|
887
910
|
|
|
888
911
|
// Remove default sort so we don't duplicate/conflict
|
|
889
912
|
// INSERT_YOUR_CODE
|
|
890
913
|
// If sortBy is present, check if the field needs ".keyword" (for string fields like storeName, storeId, ticketId)
|
|
891
914
|
// This avoids OpenSearch errors about sorting on text fields.
|
|
892
915
|
const stringKeywordFields = [ 'storeName', 'storeId', 'ticketId', 'status', 'type', 'clientId' ];
|
|
893
|
-
let sortField = inputData.sortBy == 'footfall'? 'footfallCount' :inputData.sortBy == 'issueDate'?'dateString':inputData.sortBy;
|
|
916
|
+
let sortField = inputData.sortBy == 'footfall' ? 'footfallCount' : inputData.sortBy == 'issueDate' ? 'dateString' : inputData.sortBy;
|
|
894
917
|
if ( stringKeywordFields.includes( sortField ) ) {
|
|
895
918
|
sortField = `${sortField}.keyword`;
|
|
896
919
|
}
|
|
@@ -930,7 +953,7 @@ export async function ticketList( req, res ) {
|
|
|
930
953
|
searchQuery.query.bool.must.push( {
|
|
931
954
|
term: {
|
|
932
955
|
'mappingInfo.type': ticketsFeature ? 'review' : ticketsApproveFeature ?
|
|
933
|
-
'approve' :'tagging',
|
|
956
|
+
'approve' : 'tagging',
|
|
934
957
|
},
|
|
935
958
|
},
|
|
936
959
|
{
|
|
@@ -944,14 +967,14 @@ export async function ticketList( req, res ) {
|
|
|
944
967
|
searchQuery.query.bool.must.push( {
|
|
945
968
|
term: {
|
|
946
969
|
'mappingInfo.type': inputData?.permissionType == 'review' ? 'review' :
|
|
947
|
-
|
|
970
|
+
'approve',
|
|
948
971
|
},
|
|
949
972
|
} );
|
|
950
973
|
}
|
|
951
974
|
|
|
952
975
|
if ( inputData.searchValue && inputData.searchValue !== '' ) {
|
|
953
|
-
searchQuery.query.bool['should'] =[];
|
|
954
|
-
searchQuery.query.bool.should=[
|
|
976
|
+
searchQuery.query.bool['should'] = [];
|
|
977
|
+
searchQuery.query.bool.should = [
|
|
955
978
|
|
|
956
979
|
{
|
|
957
980
|
'wildcard': {
|
|
@@ -1034,7 +1057,7 @@ export async function ticketList( req, res ) {
|
|
|
1034
1057
|
}
|
|
1035
1058
|
}
|
|
1036
1059
|
} else {
|
|
1037
|
-
if ( inputData?.permissionType ==='approve' ) {
|
|
1060
|
+
if ( inputData?.permissionType === 'approve' ) {
|
|
1038
1061
|
for ( let item of ticketListData ) {
|
|
1039
1062
|
temp.push( {
|
|
1040
1063
|
|
|
@@ -1058,7 +1081,7 @@ export async function ticketList( req, res ) {
|
|
|
1058
1081
|
|
|
1059
1082
|
} );
|
|
1060
1083
|
}
|
|
1061
|
-
} else if ( inputData?.permissionType ==='review' ) {
|
|
1084
|
+
} else if ( inputData?.permissionType === 'review' ) {
|
|
1062
1085
|
for ( let item of ticketListData ) {
|
|
1063
1086
|
temp.push( {
|
|
1064
1087
|
|
|
@@ -2365,7 +2388,7 @@ export async function openTicketList( req, res ) {
|
|
|
2365
2388
|
// INSERT_YOUR_CODE
|
|
2366
2389
|
// Add sorting by revicedPerc descending (highest revised accuracy first)
|
|
2367
2390
|
openSearchQuery.sort = [
|
|
2368
|
-
{ 'revicedPerc.keyword': { order: inputData?.sortOrder === 1? 'asc':'desc' } },
|
|
2391
|
+
{ 'revicedPerc.keyword': { order: inputData?.sortOrder === 1 ? 'asc' : 'desc' } },
|
|
2369
2392
|
];
|
|
2370
2393
|
|
|
2371
2394
|
|
|
@@ -2587,7 +2610,7 @@ export async function updateTempStatus( req, res ) {
|
|
|
2587
2610
|
);
|
|
2588
2611
|
|
|
2589
2612
|
|
|
2590
|
-
const taggedImages = getSearchResp?.body?.hits?.hits?.length > 0? getSearchResp?.body?.hits?.hits : [];
|
|
2613
|
+
const taggedImages = getSearchResp?.body?.hits?.hits?.length > 0 ? getSearchResp?.body?.hits?.hits : [];
|
|
2591
2614
|
const logs = {
|
|
2592
2615
|
type: inputData.type,
|
|
2593
2616
|
storeId: taggedImages?.[0]?._source?.storeId,
|
|
@@ -549,11 +549,17 @@ export async function ticketCreation( req, res, next ) {
|
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
551
|
|
|
552
|
-
|
|
553
|
-
let checkapprove = getConfig.footfallDirectoryConfigs.revision.filter( ( data ) => data.actionType === 'approver' && data.isChecked === true );
|
|
552
|
+
const revision = getConfig.footfallDirectoryConfigs?.revision ?? [];
|
|
554
553
|
|
|
555
|
-
|
|
556
|
-
|
|
554
|
+
const hasReviewer = revision.some(
|
|
555
|
+
( data ) => data.actionType === 'reviewer' && data.isChecked === true,
|
|
556
|
+
);
|
|
557
|
+
const hasApprover = revision.some(
|
|
558
|
+
( data ) => data.actionType === 'approver' && data.isChecked === true,
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
if ( hasReviewer || hasApprover ) {
|
|
562
|
+
const userQuery = [
|
|
557
563
|
{
|
|
558
564
|
$match: {
|
|
559
565
|
clientId: getstoreName.clientId,
|
|
@@ -561,40 +567,49 @@ export async function ticketCreation( req, res, next ) {
|
|
|
561
567
|
},
|
|
562
568
|
},
|
|
563
569
|
];
|
|
564
|
-
let finduserList = await aggregateUser( userQuery );
|
|
565
570
|
|
|
571
|
+
const finduserList = await aggregateUser( userQuery );
|
|
566
572
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
let description = `Created on ${createdOn}`;
|
|
571
|
-
let Data = {
|
|
572
|
-
'title': title,
|
|
573
|
-
'body': description,
|
|
574
|
-
'type': 'create',
|
|
575
|
-
'date': record.dateString,
|
|
576
|
-
'storeId': record.storeId,
|
|
577
|
-
'clientId': record.clientId,
|
|
578
|
-
'ticketId': record.ticketId,
|
|
579
|
-
};
|
|
573
|
+
const createdOn = dayjs().format( 'DD MMM YYYY' );
|
|
574
|
+
const title = `${getstoreName?.storeName} Have raised a ticket for a Footfall Mismatch`;
|
|
575
|
+
const description = `Created on ${createdOn}`;
|
|
580
576
|
|
|
581
|
-
|
|
577
|
+
const Data = {
|
|
578
|
+
title,
|
|
579
|
+
body: description,
|
|
580
|
+
type: 'create',
|
|
581
|
+
date: record.dateString,
|
|
582
|
+
storeId: record.storeId,
|
|
583
|
+
clientId: record.clientId,
|
|
584
|
+
ticketId: record.ticketId,
|
|
585
|
+
};
|
|
582
586
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
587
|
+
await Promise.all(
|
|
588
|
+
( finduserList || [] ).map( async ( userData ) => {
|
|
589
|
+
const ticketsFeature = userData?.rolespermission?.some(
|
|
590
|
+
( f ) =>
|
|
591
|
+
f.featureName === 'FootfallDirectory' &&
|
|
592
|
+
f.modules?.some(
|
|
593
|
+
( m ) =>
|
|
594
|
+
m.name === 'reviewer' && ( m.isAdd === true || m.isEdit === true ),
|
|
595
|
+
),
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
if ( !ticketsFeature ) return;
|
|
599
|
+
|
|
600
|
+
const notifyUser = await getAssinedStore( userData, req.body.storeId );
|
|
601
|
+
if ( !notifyUser || !userData?.fcmToken ) return;
|
|
602
|
+
|
|
603
|
+
await sendPushNotification( title, description, userData.fcmToken, Data );
|
|
604
|
+
} ),
|
|
605
|
+
);
|
|
591
606
|
}
|
|
592
607
|
|
|
593
608
|
|
|
594
609
|
const id = `${inputData.storeId}_${inputData.dateString}_footfall-directory-tagging`;
|
|
595
610
|
const insertResult = await insertWithId( openSearch.footfallDirectory, id, record );
|
|
596
611
|
if ( insertResult && insertResult.statusCode === 201 ) {
|
|
597
|
-
|
|
612
|
+
// After successful ticket creation, update status to "submitted" in revop index for the relevant records
|
|
598
613
|
|
|
599
614
|
|
|
600
615
|
const bulkUpdateBody = taggingImages.map( ( img ) => [
|
|
@@ -718,14 +733,14 @@ export async function ticketCreation( req, res, next ) {
|
|
|
718
733
|
const startDateObj = new Date( currentDateObj );
|
|
719
734
|
|
|
720
735
|
if ( breachDays === 30 ) {
|
|
721
|
-
|
|
736
|
+
// Consider within this month
|
|
722
737
|
startDateObj.setDate( 1 ); // First day of current month
|
|
723
738
|
} else if ( breachDays === 60 ) {
|
|
724
|
-
|
|
739
|
+
// Consider this month and last month
|
|
725
740
|
startDateObj.setMonth( startDateObj.getMonth() - 1 );
|
|
726
741
|
startDateObj.setDate( 1 ); // First day of last month
|
|
727
742
|
} else {
|
|
728
|
-
|
|
743
|
+
// For other values, calculate months from days
|
|
729
744
|
const breachMonths = Math.ceil( breachDays / 30 );
|
|
730
745
|
startDateObj.setMonth( startDateObj.getMonth() - breachMonths + 1 );
|
|
731
746
|
startDateObj.setDate( 1 );
|
|
@@ -773,21 +788,21 @@ export async function ticketCreation( req, res, next ) {
|
|
|
773
788
|
}
|
|
774
789
|
|
|
775
790
|
if ( breachTicketsCount >= breachCount ) {
|
|
776
|
-
|
|
791
|
+
// Calculate remaining future days in the config period
|
|
777
792
|
const futureDates = [];
|
|
778
793
|
|
|
779
794
|
// Calculate end date of config period
|
|
780
795
|
const configEndDateObj = new Date( currentDateObj );
|
|
781
796
|
if ( breachDays === 30 ) {
|
|
782
|
-
|
|
797
|
+
// End of current month
|
|
783
798
|
configEndDateObj.setMonth( configEndDateObj.getMonth() + 1 );
|
|
784
799
|
configEndDateObj.setDate( 0 ); // Last day of current month
|
|
785
800
|
} else if ( breachDays === 60 ) {
|
|
786
|
-
|
|
801
|
+
// End of next month
|
|
787
802
|
configEndDateObj.setMonth( configEndDateObj.getMonth() + 2 );
|
|
788
803
|
configEndDateObj.setDate( 0 ); // Last day of next month
|
|
789
804
|
} else {
|
|
790
|
-
|
|
805
|
+
// For other values, add the remaining days
|
|
791
806
|
const remainingDays = breachDays - ( Math.floor( ( currentDateObj - startDateObj ) / ( 1000 * 60 * 60 * 24 ) ) );
|
|
792
807
|
configEndDateObj.setDate( configEndDateObj.getDate() + remainingDays );
|
|
793
808
|
}
|