rez_core 5.0.197 → 5.0.198

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": "rez_core",
3
- "version": "5.0.197",
3
+ "version": "5.0.198",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -899,18 +899,32 @@ export class FilterService {
899
899
  // convert to number when needed
900
900
  const numVal = Number(val);
901
901
 
902
- const subtractBusinessDays = (days: number): string => {
903
- let d = new Date();
904
- let count = 0;
902
+ // const subtractBusinessDays = (days: number): string => {
903
+ // let d = new Date();
904
+ // let count = 0;
905
905
 
906
- while (count < days) {
907
- d.setDate(d.getDate() - 1);
906
+ // while (count < days) {
907
+ // d.setDate(d.getDate() - 1);
908
908
 
909
- const day = d.getDay(); // 0 = Sunday, 6 = Saturday
909
+ // const day = d.getDay(); // 0 = Sunday, 6 = Saturday
910
910
 
911
- if (day !== 0 && day !== 6) {
912
- count++;
913
- }
911
+ // if (day !== 0 && day !== 6) {
912
+ // count++;
913
+ // }
914
+ // }
915
+
916
+ // return d.toISOString().split('T')[0];
917
+ // };
918
+
919
+ const moveBusinessDays = (offset: number): string => {
920
+ let d = new Date();
921
+ const abs = Math.abs(offset);
922
+ let count = 0;
923
+
924
+ while (count < abs) {
925
+ d.setDate(d.getDate() + (offset > 0 ? 1 : -1)); // forward for +ve / backward for -ve
926
+ const day = d.getDay(); // 0=Sun, 6=Sat
927
+ if (day !== 0 && day !== 6) count++; // skip weekends
914
928
  }
915
929
 
916
930
  return d.toISOString().split('T')[0];
@@ -918,7 +932,6 @@ export class FilterService {
918
932
 
919
933
  switch (op) {
920
934
  // BASIC COMPARISONS
921
-
922
935
  case 'equal':
923
936
  case 'is':
924
937
  return {
@@ -1098,14 +1111,12 @@ export class FilterService {
1098
1111
  };
1099
1112
  }
1100
1113
 
1101
- // BUSINESS DAY OFFSET LOGIC (SKIPS WEEKENDS)
1102
- // ALWAYS ADJUST -1 DAY FOR DB SHIFT
1103
1114
  case 'is_before_business_days': {
1104
1115
  if (isNaN(numVal)) {
1105
1116
  throw new BadRequestException('Value must be a number');
1106
1117
  }
1107
1118
 
1108
- const targetDate = subtractBusinessDays(numVal);
1119
+ const targetDate = moveBusinessDays(numVal);
1109
1120
 
1110
1121
  return {
1111
1122
  query: `${dateColumn} < :${key} AND EXTRACT(DOW FROM ${dateColumn}) NOT IN (0, 6)`,
@@ -1115,33 +1126,56 @@ export class FilterService {
1115
1126
 
1116
1127
  case 'is_after_business_days': {
1117
1128
  if (isNaN(numVal)) {
1118
- throw new BadRequestException(
1119
- 'Value must be a number for is_after_business_days',
1120
- );
1129
+ throw new BadRequestException('Value must be a number');
1121
1130
  }
1122
1131
 
1123
- const businessAfter = (() => {
1124
- let d = new Date();
1125
- let count = 0;
1126
-
1127
- while (count < numVal) {
1128
- d.setDate(d.getDate() + 1);
1129
- const day = d.getDay(); // 0=Sun, 6=Sat
1130
- if (day !== 0 && day !== 6) count++;
1131
- }
1132
-
1133
- // DB shift -1 day
1134
- // d.setDate(d.getDate() - 1);
1135
-
1136
- return d.toISOString().split('T')[0];
1137
- })();
1132
+ const targetDate = moveBusinessDays(numVal);
1138
1133
 
1139
1134
  return {
1140
1135
  query: `${dateColumn} > :${key}`,
1141
- params: { [key]: businessAfter },
1136
+ params: { [key]: targetDate },
1142
1137
  };
1143
1138
  }
1144
1139
 
1140
+ // case 'is_before_business_days': {
1141
+ // if (isNaN(numVal)) {
1142
+ // throw new BadRequestException('Value must be a number');
1143
+ // }
1144
+
1145
+ // const targetDate = subtractBusinessDays(numVal);
1146
+
1147
+ // return {
1148
+ // query: `${dateColumn} < :${key} AND EXTRACT(DOW FROM ${dateColumn}) NOT IN (0, 6)`,
1149
+ // params: { [key]: targetDate },
1150
+ // };
1151
+ // }
1152
+
1153
+ // case 'is_after_business_days': {
1154
+ // if (isNaN(numVal)) {
1155
+ // throw new BadRequestException(
1156
+ // 'Value must be a number for is_after_business_days',
1157
+ // );
1158
+ // }
1159
+
1160
+ // const businessAfter = (() => {
1161
+ // let d = new Date();
1162
+ // let count = 0;
1163
+
1164
+ // while (count < numVal) {
1165
+ // d.setDate(d.getDate() + 1);
1166
+ // const day = d.getDay(); // 0=Sun, 6=Sat
1167
+ // if (day !== 0 && day !== 6) count++;
1168
+ // }
1169
+
1170
+ // return d.toISOString().split('T')[0];
1171
+ // })();
1172
+
1173
+ // return {
1174
+ // query: `${dateColumn} > :${key}`,
1175
+ // params: { [key]: businessAfter },
1176
+ // };
1177
+ // }
1178
+
1145
1179
  // IN LAST DAY (range: today to N days before)
1146
1180
  case 'in_last_day': {
1147
1181
  if (isNaN(numVal)) {