rez_core 5.0.43 → 5.0.46
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/dist/module/filter/service/filter.service.js +96 -47
- package/dist/module/filter/service/filter.service.js.map +1 -1
- package/dist/module/workflow/service/populate-workflow.service.js +1 -1
- package/dist/module/workflow/service/populate-workflow.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/filter/service/filter.service.ts +148 -57
- package/src/module/workflow/service/populate-workflow.service.ts +2 -1
package/package.json
CHANGED
|
@@ -46,9 +46,7 @@ export class FilterService {
|
|
|
46
46
|
Object.entries(clause.params).forEach(([key, val]) => {
|
|
47
47
|
if (Array.isArray(val)) {
|
|
48
48
|
// Create ($1,$2,$3)
|
|
49
|
-
const placeholders = val
|
|
50
|
-
.map(() => `$${paramIndex++}`)
|
|
51
|
-
.join(', ');
|
|
49
|
+
const placeholders = val.map(() => `$${paramIndex++}`).join(', ');
|
|
52
50
|
|
|
53
51
|
parsedQuery = parsedQuery.replace(
|
|
54
52
|
new RegExp(`:${key}`, 'g'),
|
|
@@ -328,7 +326,11 @@ export class FilterService {
|
|
|
328
326
|
baseWhere.push({
|
|
329
327
|
query:
|
|
330
328
|
'e.organization_id = :organization_id AND e.level_type = :level_type AND e.level_id = :level_id',
|
|
331
|
-
params: {
|
|
329
|
+
params: {
|
|
330
|
+
organization_id: String(organization_id),
|
|
331
|
+
level_type,
|
|
332
|
+
level_id,
|
|
333
|
+
},
|
|
332
334
|
});
|
|
333
335
|
}
|
|
334
336
|
|
|
@@ -368,8 +370,7 @@ export class FilterService {
|
|
|
368
370
|
query: `e.${attrName} = :${attrName}`,
|
|
369
371
|
params: { [attrName]: attrValue }, // <-- string
|
|
370
372
|
});
|
|
371
|
-
}
|
|
372
|
-
else if (key !== 'attributeValue') {
|
|
373
|
+
} else if (key !== 'attributeValue') {
|
|
373
374
|
baseWhere.push({
|
|
374
375
|
query: `e.${key} = :${key}`,
|
|
375
376
|
params: { [key]: strValue }, // <-- string
|
|
@@ -486,9 +487,9 @@ export class FilterService {
|
|
|
486
487
|
|
|
487
488
|
let query = await qb.getQuery();
|
|
488
489
|
|
|
489
|
-
console.log('------------------------------------------------------\n')
|
|
490
|
+
console.log('------------------------------------------------------\n');
|
|
490
491
|
console.log(query);
|
|
491
|
-
console.log('\n------------------------------------------------------')
|
|
492
|
+
console.log('\n------------------------------------------------------');
|
|
492
493
|
const entity_list = await qb.getRawMany();
|
|
493
494
|
|
|
494
495
|
console.log(`📦 [FilterService] Fetched ${entity_list.length} records`);
|
|
@@ -763,7 +764,10 @@ export class FilterService {
|
|
|
763
764
|
) {
|
|
764
765
|
return filters
|
|
765
766
|
.map((f) => {
|
|
766
|
-
const clause = this.buildCondition(
|
|
767
|
+
const clause = this.buildCondition(
|
|
768
|
+
f,
|
|
769
|
+
attributeMeta[f.filter_attribute],
|
|
770
|
+
);
|
|
767
771
|
|
|
768
772
|
if (!clause) return null;
|
|
769
773
|
|
|
@@ -885,13 +889,16 @@ export class FilterService {
|
|
|
885
889
|
}
|
|
886
890
|
|
|
887
891
|
private buildDateCondition(attr: string, op: string, val: any, key: string) {
|
|
888
|
-
const dateColumn = `e.${attr}
|
|
889
|
-
const monthColumn = `
|
|
892
|
+
const dateColumn = `DATE(e.${attr})`;
|
|
893
|
+
const monthColumn = `DATE_TRUNC('month', e.${attr})`;
|
|
890
894
|
|
|
895
|
+
// convert to number when needed
|
|
891
896
|
const numVal = Number(val);
|
|
892
897
|
|
|
893
898
|
switch (op) {
|
|
894
|
-
//
|
|
899
|
+
// ============================================
|
|
900
|
+
// BASIC COMPARISONS
|
|
901
|
+
// ============================================
|
|
895
902
|
case 'equal':
|
|
896
903
|
case 'is':
|
|
897
904
|
return {
|
|
@@ -925,64 +932,99 @@ export class FilterService {
|
|
|
925
932
|
params: { [key]: val },
|
|
926
933
|
};
|
|
927
934
|
|
|
928
|
-
//
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
.subtract(numVal, 'months')
|
|
933
|
-
.startOf('month')
|
|
934
|
-
.format('YYYY-MM-DD');
|
|
935
|
-
return {
|
|
936
|
-
query: `${monthColumn} < date_trunc('month', :${key})::date`,
|
|
937
|
-
params: { [key]: target },
|
|
938
|
-
};
|
|
939
|
-
}
|
|
935
|
+
// ============================================
|
|
936
|
+
// EMPTY / NOT EMPTY
|
|
937
|
+
// ============================================
|
|
938
|
+
case 'empty':
|
|
940
939
|
return {
|
|
941
|
-
query:
|
|
942
|
-
params: {
|
|
940
|
+
query: `e.${attr} IS NULL OR e.${attr} = ''`,
|
|
941
|
+
params: {},
|
|
943
942
|
};
|
|
944
943
|
|
|
945
|
-
case '
|
|
946
|
-
if (!isNaN(numVal)) {
|
|
947
|
-
const target = moment()
|
|
948
|
-
.add(numVal, 'months')
|
|
949
|
-
.startOf('month')
|
|
950
|
-
.format('YYYY-MM-DD');
|
|
951
|
-
return {
|
|
952
|
-
query: `${monthColumn} > date_trunc('month', :${key})::date`,
|
|
953
|
-
params: { [key]: target },
|
|
954
|
-
};
|
|
955
|
-
}
|
|
944
|
+
case 'not_empty':
|
|
956
945
|
return {
|
|
957
|
-
query:
|
|
958
|
-
params: {
|
|
946
|
+
query: `e.${attr} IS NOT NULL AND e.${attr} <> ''`,
|
|
947
|
+
params: {},
|
|
959
948
|
};
|
|
960
949
|
|
|
961
|
-
//
|
|
950
|
+
// ============================================
|
|
951
|
+
// DAY OFFSET LOGIC (ALWAYS ADJUST -1 DAY)
|
|
952
|
+
// ============================================
|
|
962
953
|
case 'is_day_before':
|
|
963
|
-
if (isNaN(numVal))
|
|
954
|
+
if (isNaN(numVal)) {
|
|
964
955
|
throw new BadRequestException(
|
|
965
956
|
'Value must be a number for is_day_before',
|
|
966
957
|
);
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
const dayBefore = (() => {
|
|
961
|
+
const d = new Date();
|
|
962
|
+
d.setDate(d.getDate() - numVal - 1); // -1 because DB stores previous day
|
|
963
|
+
return d.toISOString().split('T')[0];
|
|
964
|
+
})();
|
|
967
965
|
|
|
968
|
-
const beforeDate = moment()
|
|
969
|
-
.subtract(numVal + 1, 'days')
|
|
970
|
-
.format('YYYY-MM-DD');
|
|
971
966
|
return {
|
|
972
967
|
query: `${dateColumn} < :${key}`,
|
|
973
|
-
params: { [key]:
|
|
968
|
+
params: { [key]: dayBefore },
|
|
974
969
|
};
|
|
975
970
|
|
|
976
971
|
case 'is_day_after':
|
|
977
|
-
if (isNaN(numVal))
|
|
972
|
+
if (isNaN(numVal)) {
|
|
978
973
|
throw new BadRequestException(
|
|
979
974
|
'Value must be a number for is_day_after',
|
|
980
975
|
);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
const dayAfter = (() => {
|
|
979
|
+
const d = new Date();
|
|
980
|
+
d.setDate(d.getDate() - 1 + numVal); // -1 because DB stores previous day
|
|
981
|
+
return d.toISOString().split('T')[0];
|
|
982
|
+
})();
|
|
981
983
|
|
|
982
|
-
const afterDate = moment().add(numVal + 1, 'days').format('YYYY-MM-DD');
|
|
983
984
|
return {
|
|
984
985
|
query: `${dateColumn} > :${key}`,
|
|
985
|
-
params: { [key]:
|
|
986
|
+
params: { [key]: dayAfter },
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
// ============================================
|
|
990
|
+
// MONTH OFFSET LOGIC
|
|
991
|
+
// ============================================
|
|
992
|
+
case 'is_month_before':
|
|
993
|
+
if (isNaN(numVal)) {
|
|
994
|
+
throw new BadRequestException(
|
|
995
|
+
'Value must be a number for is_month_before',
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
const monthBefore = (() => {
|
|
1000
|
+
const d = new Date();
|
|
1001
|
+
d.setMonth(d.getMonth() - numVal);
|
|
1002
|
+
d.setDate(d.getDate() - 1); // adjust -1 day for DB shift
|
|
1003
|
+
return d.toISOString().split('T')[0];
|
|
1004
|
+
})();
|
|
1005
|
+
|
|
1006
|
+
return {
|
|
1007
|
+
query: `${monthColumn} < DATE_TRUNC('month', :${key})`,
|
|
1008
|
+
params: { [key]: monthBefore },
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
case 'is_month_after':
|
|
1012
|
+
if (isNaN(numVal)) {
|
|
1013
|
+
throw new BadRequestException(
|
|
1014
|
+
'Value must be a number for is_month_after',
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
const monthAfter = (() => {
|
|
1019
|
+
const d = new Date();
|
|
1020
|
+
d.setMonth(d.getMonth() + numVal);
|
|
1021
|
+
d.setDate(d.getDate() - 1); // adjust -1 for DB shift
|
|
1022
|
+
return d.toISOString().split('T')[0];
|
|
1023
|
+
})();
|
|
1024
|
+
|
|
1025
|
+
return {
|
|
1026
|
+
query: `${monthColumn} > DATE_TRUNC('month', :${key})`,
|
|
1027
|
+
params: { [key]: monthAfter },
|
|
986
1028
|
};
|
|
987
1029
|
|
|
988
1030
|
// ===== BETWEEN =====
|
|
@@ -1019,19 +1061,68 @@ export class FilterService {
|
|
|
1019
1061
|
};
|
|
1020
1062
|
}
|
|
1021
1063
|
|
|
1022
|
-
//
|
|
1023
|
-
|
|
1024
|
-
|
|
1064
|
+
// ============================================
|
|
1065
|
+
// BUSINESS DAY OFFSET LOGIC (SKIPS WEEKENDS)
|
|
1066
|
+
// ALWAYS ADJUST -1 DAY FOR DB SHIFT
|
|
1067
|
+
// ============================================
|
|
1068
|
+
|
|
1069
|
+
case 'is_before_business_days': {
|
|
1070
|
+
if (isNaN(numVal)) {
|
|
1071
|
+
throw new BadRequestException(
|
|
1072
|
+
'Value must be a number for is_before_business_days',
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
const businessBefore = (() => {
|
|
1077
|
+
let d = new Date();
|
|
1078
|
+
let count = 0;
|
|
1079
|
+
|
|
1080
|
+
while (count < numVal) {
|
|
1081
|
+
d.setDate(d.getDate() - 1);
|
|
1082
|
+
const day = d.getDay(); // 0=Sun, 6=Sat
|
|
1083
|
+
if (day !== 0 && day !== 6) count++;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// DB shift -1 day
|
|
1087
|
+
d.setDate(d.getDate() - 1);
|
|
1088
|
+
|
|
1089
|
+
return d.toISOString().split('T')[0];
|
|
1090
|
+
})();
|
|
1091
|
+
|
|
1025
1092
|
return {
|
|
1026
|
-
query:
|
|
1027
|
-
params: {},
|
|
1093
|
+
query: `${dateColumn} < :${key}`,
|
|
1094
|
+
params: { [key]: businessBefore },
|
|
1028
1095
|
};
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
case 'is_after_business_days': {
|
|
1099
|
+
if (isNaN(numVal)) {
|
|
1100
|
+
throw new BadRequestException(
|
|
1101
|
+
'Value must be a number for is_after_business_days',
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
const businessAfter = (() => {
|
|
1106
|
+
let d = new Date();
|
|
1107
|
+
let count = 0;
|
|
1108
|
+
|
|
1109
|
+
while (count < numVal) {
|
|
1110
|
+
d.setDate(d.getDate() + 1);
|
|
1111
|
+
const day = d.getDay(); // 0=Sun, 6=Sat
|
|
1112
|
+
if (day !== 0 && day !== 6) count++;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// DB shift -1 day
|
|
1116
|
+
d.setDate(d.getDate() - 1);
|
|
1117
|
+
|
|
1118
|
+
return d.toISOString().split('T')[0];
|
|
1119
|
+
})();
|
|
1029
1120
|
|
|
1030
|
-
case 'not_empty':
|
|
1031
1121
|
return {
|
|
1032
|
-
query:
|
|
1033
|
-
params: {},
|
|
1122
|
+
query: `${dateColumn} > :${key}`,
|
|
1123
|
+
params: { [key]: businessAfter },
|
|
1034
1124
|
};
|
|
1125
|
+
}
|
|
1035
1126
|
|
|
1036
1127
|
default:
|
|
1037
1128
|
throw new BadRequestException(`Unsupported operator for date: ${op}`);
|
|
@@ -1135,7 +1226,7 @@ export class FilterService {
|
|
|
1135
1226
|
|
|
1136
1227
|
async queryWithSchema(sql: string, params: any[] = []) {
|
|
1137
1228
|
await this.dataSource.query('BEGIN');
|
|
1138
|
-
const schema = this.configService.get<string>('DB_SCHEMA')
|
|
1229
|
+
const schema = this.configService.get<string>('DB_SCHEMA');
|
|
1139
1230
|
await this.dataSource.query(`SET LOCAL search_path TO ${schema}`);
|
|
1140
1231
|
const result = await this.dataSource.query(sql, params);
|
|
1141
1232
|
await this.dataSource.query('COMMIT');
|
|
@@ -110,7 +110,8 @@ export class PopulateWorkflowService extends EntityServiceImpl {
|
|
|
110
110
|
const workflowLevelMappingRepo = this.reflectionHelper.getRepoService(
|
|
111
111
|
'WorkflowLevelMappingEntity',
|
|
112
112
|
);
|
|
113
|
-
const listMasterRepo =
|
|
113
|
+
const listMasterRepo =
|
|
114
|
+
this.reflectionHelper.getRepoService('ListMasterData');
|
|
114
115
|
const actionCategoryRepo =
|
|
115
116
|
this.reflectionHelper.getRepoService('ActionCategory');
|
|
116
117
|
const viewMasterRepo = this.reflectionHelper.getRepoService('ViewMaster');
|