tango-app-api-infra 3.9.8 → 3.9.10

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.9.8",
3
+ "version": "3.9.10",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2570,13 +2570,11 @@ export async function ticketList( req, res ) {
2570
2570
  if ( inputData.sortBy ) {
2571
2571
  let sortOrder = inputData.sortOrder === 1 ? 'asc' : 'desc';
2572
2572
  const stringKeywordFields = [ 'storeName', 'storeId', 'ticketId', 'status', 'type', 'clientId' ];
2573
- let sortField = inputData.sortBy == 'footfall' ? 'footfallCount' : inputData.sortBy == 'issueDate' ? 'dateString' : inputData.sortBy;
2573
+ let sortField = inputData.sortBy == 'footfall' ? 'footfallCount' : inputData.sortBy == 'issueDate' ? 'dateString': inputData.sortBy == 'tangoStatus'? 'status' : inputData.sortBy;
2574
2574
  if ( stringKeywordFields.includes( sortField ) ) {
2575
2575
  sortField = `${sortField}.keyword`;
2576
2576
  }
2577
- // sortBy mappingInfo.createdAt for types "review", "approve", "tagging" based on user permission
2578
- // If sortBy is 'reviewedOn', 'approvedOn', or 'taggedOn', sort by mappingInfo[?].createdAt where type matches the right value
2579
- // fallback: newest item with correct mappingInfo.type for each ticket
2577
+
2580
2578
  let requestedSortType = null;
2581
2579
  let sortKey = null;
2582
2580
  if ( inputData.sortBy === 'ticketRaised' ) {
@@ -2606,6 +2604,12 @@ export async function ticketList( req, res ) {
2606
2604
  } else if ( inputData.sortBy === 'status' ) {
2607
2605
  sortKey = 'status';
2608
2606
  requestedSortType =( req.user.userType === 'tango' && inputData.tangoType === 'store' )? 'tangorevirew' : inputData?.permissionType === 'review' ? 'review' : ( ticketsFeature && !ticketsApproveFeature )? 'review':'approve';
2607
+ } else if ( inputData.sortBy === 'comments' ) {
2608
+ sortKey = 'comments';
2609
+ requestedSortType = 'finalRevision';
2610
+ } else if ( inputData.sortBy === 'subComments' ) {
2611
+ sortKey = 'subComments';
2612
+ requestedSortType ='finalRevision';
2609
2613
  } else {
2610
2614
  searchQuery.sort = [
2611
2615
  { [sortField]: { order: sortOrder } },
@@ -2863,20 +2867,100 @@ export async function ticketList( req, res ) {
2863
2867
  },
2864
2868
  ];
2865
2869
  break;
2870
+ case 'comments':
2871
+ searchQuery.sort = [
2872
+ {
2873
+ _script: {
2874
+ type: 'string',
2875
+ script: {
2876
+ lang: 'painless',
2877
+ source: `
2878
+ try {
2879
+ if (params._source != null && params._source.mappingInfo != null) {
2880
+ String found = null;
2881
+
2882
+ for (def item : params._source.mappingInfo) {
2883
+ if (item != null && item.type == params.miType && item.comments != null) {
2884
+ String value = item.comments.toString();
2885
+
2886
+ if (found == null || value.compareTo(found) > 0) {
2887
+ found = value;
2888
+ }
2889
+ }
2890
+ }
2891
+
2892
+ if (found != null) {
2893
+ return found;
2894
+ }
2895
+ }
2896
+ } catch (Exception e) {
2897
+ // ignore and fallback
2898
+ }
2899
+
2900
+ // fallback to root-level comments
2901
+ if (params._source != null && params._source.comments != null) {
2902
+ return params._source.comments.toString();
2903
+ }
2904
+
2905
+ return "";
2906
+ `,
2907
+ params: {
2908
+ miType: requestedSortType,
2909
+ },
2910
+ },
2911
+ order: sortOrder,
2912
+ },
2913
+ },
2914
+ ];
2915
+ break;
2916
+ case 'subComments':
2917
+ searchQuery.sort = [
2918
+ {
2919
+ _script: {
2920
+ type: 'string',
2921
+ script: {
2922
+ lang: 'painless',
2923
+ source: `
2924
+ try {
2925
+ if (params._source != null && params._source.mappingInfo != null) {
2926
+ String found = null;
2927
+
2928
+ for (def item : params._source.mappingInfo) {
2929
+ if (item != null && item.type == params.miType && item.subComments != null) {
2930
+ String value = item.subComments.toString();
2931
+
2932
+ if (found == null || value.compareTo(found) > 0) {
2933
+ found = value;
2934
+ }
2935
+ }
2936
+ }
2937
+
2938
+ if (found != null) {
2939
+ return found;
2940
+ }
2941
+ }
2942
+ } catch (Exception e) {
2943
+ // ignore and fallback
2944
+ }
2945
+
2946
+ // fallback to root-level subComments
2947
+ if (params._source != null && params._source.subComments != null) {
2948
+ return params._source.subComments.toString();
2949
+ }
2950
+
2951
+ return "";
2952
+ `,
2953
+ params: {
2954
+ miType: requestedSortType,
2955
+ },
2956
+ },
2957
+ order: sortOrder,
2958
+ },
2959
+ },
2960
+ ];
2961
+ break;
2866
2962
  }
2867
2963
  }
2868
-
2869
-
2870
- // else {
2871
- // if ( stringKeywordFields.includes( sortField ) ) {
2872
- // sortField = `${sortField}.keyword`;
2873
- // }
2874
- // }
2875
-
2876
- logger.info( { requestedSortType, msg: '......1' } );
2877
- // Remove default sort so we don't duplicate/conflict
2878
-
2879
- logger.info( { searchQuery, msg: '......2' } );
2880
2964
  }
2881
2965
 
2882
2966
  // Example: Filtering by storeId if present in the query