tango-app-api-infra 3.9.9 → 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.9",
3
+ "version": "3.9.10",
4
4
  "description": "infra",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -2604,6 +2604,12 @@ export async function ticketList( req, res ) {
2604
2604
  } else if ( inputData.sortBy === 'status' ) {
2605
2605
  sortKey = 'status';
2606
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';
2607
2613
  } else {
2608
2614
  searchQuery.sort = [
2609
2615
  { [sortField]: { order: sortOrder } },
@@ -2861,20 +2867,100 @@ export async function ticketList( req, res ) {
2861
2867
  },
2862
2868
  ];
2863
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;
2864
2962
  }
2865
2963
  }
2866
-
2867
-
2868
- // else {
2869
- // if ( stringKeywordFields.includes( sortField ) ) {
2870
- // sortField = `${sortField}.keyword`;
2871
- // }
2872
- // }
2873
-
2874
- logger.info( { requestedSortType, msg: '......1' } );
2875
- // Remove default sort so we don't duplicate/conflict
2876
-
2877
- logger.info( { searchQuery, msg: '......2' } );
2878
2964
  }
2879
2965
 
2880
2966
  // Example: Filtering by storeId if present in the query