unconventional 0.0.11 → 0.0.13
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/core/base.service.js +2 -0
- package/dist/utils/db.utils.js +10 -6
- package/package.json +1 -1
|
@@ -112,6 +112,7 @@ class BaseService {
|
|
|
112
112
|
throw api_error_1.APIError.errNotFound(`No ${this.model.name} found with id ${identifier}`);
|
|
113
113
|
}
|
|
114
114
|
else if (config?.cache) {
|
|
115
|
+
await base_cache_1.BaseCache.clearPage(config.cache, this.model);
|
|
115
116
|
await base_cache_1.BaseCache.clearModel(config.cache, response);
|
|
116
117
|
await base_cache_1.BaseCache.setModel(config.cache, response, undefined, config.cacheTTL);
|
|
117
118
|
}
|
|
@@ -129,6 +130,7 @@ class BaseService {
|
|
|
129
130
|
}
|
|
130
131
|
else if (config?.cache) {
|
|
131
132
|
const cache = config.cache;
|
|
133
|
+
await base_cache_1.BaseCache.clearPage(cache, this.model);
|
|
132
134
|
await Promise.all(response.map(item => base_cache_1.BaseCache.clearModel(cache, item)));
|
|
133
135
|
await Promise.all(response.map(item => base_cache_1.BaseCache.setModel(cache, item, undefined, config.cacheTTL)));
|
|
134
136
|
}
|
package/dist/utils/db.utils.js
CHANGED
|
@@ -52,13 +52,19 @@ function getWhere(model, filterString) {
|
|
|
52
52
|
filter = filter.substring(unconventional_pg_queries_1.AndOr.Or.length + 1);
|
|
53
53
|
andOr = unconventional_pg_queries_1.AndOr.Or;
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const singleQuoteIndex = filter.indexOf("'");
|
|
56
|
+
const matchingOperators = singleQuoteIndex === -1 ?
|
|
57
|
+
db_types_1.ValidSqlOperators.filter(op => filter.includes(` ${op}`)) :
|
|
58
|
+
db_types_1.ValidSqlOperators.filter(op => filter.includes(` ${op}`) && filter.indexOf(` ${op}`) < singleQuoteIndex);
|
|
59
|
+
if (!matchingOperators.length)
|
|
60
|
+
throw api_error_1.APIError.errInvalidQueryParameter(`No valid operator in filter: '${filter}'`);
|
|
61
|
+
// Handle when multiple operators are present in the filter (e.g. LIKE and NOT LIKE)
|
|
62
|
+
let operator = matchingOperators.sort((a, b) => b.length - a.length)[0];
|
|
63
|
+
let field = filter.substring(0, filter.indexOf(operator)).trim();
|
|
64
|
+
let value = filter.substring(filter.indexOf(operator) + operator.length).trim();
|
|
58
65
|
let jsonPath = [];
|
|
59
66
|
// Handle IS NULL and IS NOT NULL, which don't have values
|
|
60
67
|
if (operator.startsWith('IS')) {
|
|
61
|
-
operator = `${operator} ${value}`;
|
|
62
68
|
value = null;
|
|
63
69
|
}
|
|
64
70
|
// Handle JSON path
|
|
@@ -68,8 +74,6 @@ function getWhere(model, filterString) {
|
|
|
68
74
|
}
|
|
69
75
|
if (!propSummary[field])
|
|
70
76
|
throw api_error_1.APIError.errInvalidQueryParameter(`Invalid filter: '${field}'`);
|
|
71
|
-
if (!db_types_1.ValidSqlOperators.includes(operator))
|
|
72
|
-
throw api_error_1.APIError.errInvalidQueryParameter(`Invalid operator in filter: '${operator}'`);
|
|
73
77
|
if (!value && !db_types_1.NullSqlOperators.includes(operator))
|
|
74
78
|
throw api_error_1.APIError.errInvalidQueryParameter(`Invalid value in filter: '${value}'`);
|
|
75
79
|
wheres.push({ field, jsonPath, operator: operator, value, andOr });
|