namirasoft-node 1.4.45 → 1.4.47
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/BaseDatabase.d.ts +31 -49
- package/dist/BaseDatabase.js +100 -111
- package/dist/BaseDatabase.js.map +1 -1
- package/dist/BaseTable.d.ts +1 -0
- package/dist/BaseTable.js +8 -2
- package/dist/BaseTable.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseDatabase.ts +69 -101
- package/src/BaseTable.ts +10 -3
package/dist/BaseDatabase.d.ts
CHANGED
|
@@ -1,93 +1,77 @@
|
|
|
1
1
|
import * as express from "express";
|
|
2
2
|
import { FilterItem, SortItem } from "namirasoft-core";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
overrideColumnName?: (column: string) => string;
|
|
6
|
-
}
|
|
7
|
-
export interface BaseDatabase_FilterTable_JoinConditions {
|
|
3
|
+
import { BaseTable } from "./BaseTable";
|
|
4
|
+
export interface BaseDatabase_FilterTable<WhereOptions> {
|
|
8
5
|
main: {
|
|
9
|
-
table: string;
|
|
10
6
|
column: string;
|
|
11
7
|
};
|
|
12
8
|
secondary: {
|
|
13
|
-
table: string;
|
|
14
9
|
column: string;
|
|
15
10
|
};
|
|
16
|
-
getExtraConditions?: (column: string) =>
|
|
11
|
+
getExtraConditions?: (column: string) => WhereOptions[];
|
|
17
12
|
}
|
|
18
13
|
export interface IFilterableDatabase<WhereOptions> {
|
|
19
|
-
getIn: (
|
|
20
|
-
condition: WhereOptions;
|
|
21
|
-
partial: boolean;
|
|
22
|
-
};
|
|
23
|
-
getNotIn: (filter: FilterItem, column_name: string, values: string[]) => {
|
|
24
|
-
condition: WhereOptions;
|
|
25
|
-
partial: boolean;
|
|
26
|
-
};
|
|
27
|
-
getLike: (filter: FilterItem, column_name: string, value: string) => {
|
|
28
|
-
condition: WhereOptions;
|
|
29
|
-
partial: boolean;
|
|
30
|
-
};
|
|
31
|
-
getNotLike: (filter: FilterItem, column_name: string, value: string) => {
|
|
14
|
+
getIn: (column_name: string, not: boolean, values: string[]) => {
|
|
32
15
|
condition: WhereOptions;
|
|
33
16
|
partial: boolean;
|
|
17
|
+
required: boolean;
|
|
34
18
|
};
|
|
35
|
-
|
|
19
|
+
getLike: (column_name: string, not: boolean, value: string) => {
|
|
36
20
|
condition: WhereOptions;
|
|
37
21
|
partial: boolean;
|
|
22
|
+
required: boolean;
|
|
38
23
|
};
|
|
39
|
-
|
|
24
|
+
getRegex: (column_name: string, not: boolean, value: string) => {
|
|
40
25
|
condition: WhereOptions;
|
|
41
26
|
partial: boolean;
|
|
27
|
+
required: boolean;
|
|
42
28
|
};
|
|
43
|
-
getEmpty: (
|
|
29
|
+
getEmpty: (column_name: string, not: boolean) => {
|
|
44
30
|
condition: WhereOptions;
|
|
45
31
|
partial: boolean;
|
|
32
|
+
required: boolean;
|
|
46
33
|
};
|
|
47
|
-
|
|
34
|
+
getExists: (column_name: string, not: boolean) => {
|
|
48
35
|
condition: WhereOptions;
|
|
49
36
|
partial: boolean;
|
|
37
|
+
required: boolean;
|
|
50
38
|
};
|
|
51
|
-
|
|
39
|
+
getIncludes: (column_name: string, not: boolean, value: string[]) => {
|
|
52
40
|
condition: WhereOptions;
|
|
53
41
|
partial: boolean;
|
|
42
|
+
required: boolean;
|
|
54
43
|
};
|
|
55
|
-
|
|
44
|
+
getStartsWith: (column_name: string, not: boolean, value: string) => {
|
|
56
45
|
condition: WhereOptions;
|
|
57
46
|
partial: boolean;
|
|
47
|
+
required: boolean;
|
|
58
48
|
};
|
|
59
|
-
|
|
49
|
+
getEndsWith: (column_name: string, not: boolean, value: string) => {
|
|
60
50
|
condition: WhereOptions;
|
|
61
51
|
partial: boolean;
|
|
52
|
+
required: boolean;
|
|
62
53
|
};
|
|
63
|
-
|
|
54
|
+
getLT: (column_name: string, value: any) => {
|
|
64
55
|
condition: WhereOptions;
|
|
65
56
|
partial: boolean;
|
|
57
|
+
required: boolean;
|
|
66
58
|
};
|
|
67
|
-
|
|
59
|
+
getLTE: (column_name: string, value: any) => {
|
|
68
60
|
condition: WhereOptions;
|
|
69
61
|
partial: boolean;
|
|
62
|
+
required: boolean;
|
|
70
63
|
};
|
|
71
|
-
|
|
64
|
+
getGT: (column_name: string, value: any) => {
|
|
72
65
|
condition: WhereOptions;
|
|
73
66
|
partial: boolean;
|
|
67
|
+
required: boolean;
|
|
74
68
|
};
|
|
75
|
-
|
|
76
|
-
condition: WhereOptions;
|
|
77
|
-
partial: boolean;
|
|
78
|
-
};
|
|
79
|
-
getLTE: (filter: FilterItem, column_name: string, value: any) => {
|
|
80
|
-
condition: WhereOptions;
|
|
81
|
-
partial: boolean;
|
|
82
|
-
};
|
|
83
|
-
getGT: (filter: FilterItem, column_name: string, value: any) => {
|
|
84
|
-
condition: WhereOptions;
|
|
85
|
-
partial: boolean;
|
|
86
|
-
};
|
|
87
|
-
getGTE: (filter: FilterItem, column_name: string, value: any) => {
|
|
69
|
+
getGTE: (column_name: string, value: any) => {
|
|
88
70
|
condition: WhereOptions;
|
|
89
71
|
partial: boolean;
|
|
72
|
+
required: boolean;
|
|
90
73
|
};
|
|
74
|
+
getInSelect: (t: BaseTable<BaseDatabase, any>, not: boolean, join: BaseDatabase_FilterTable<WhereOptions>, conditions: WhereOptions[]) => WhereOptions;
|
|
91
75
|
}
|
|
92
76
|
export declare abstract class BaseDatabase {
|
|
93
77
|
private tables;
|
|
@@ -104,10 +88,8 @@ export declare abstract class BaseDatabase {
|
|
|
104
88
|
offset: number;
|
|
105
89
|
limit: number;
|
|
106
90
|
};
|
|
107
|
-
protected _getFiltersConditions<WhereOptions>(
|
|
108
|
-
[table: string]: BaseDatabase_FilterTable
|
|
109
|
-
}, idatabase: IFilterableDatabase<WhereOptions>, filters?: FilterItem[] | undefined):
|
|
110
|
-
[table: string]: WhereOptions[];
|
|
111
|
-
};
|
|
91
|
+
protected _getFiltersConditions<WhereOptions>(table_main: BaseTable<BaseDatabase, any>, table_joins: {
|
|
92
|
+
[table: string]: BaseDatabase_FilterTable<WhereOptions>;
|
|
93
|
+
}, idatabase: IFilterableDatabase<WhereOptions>, filters?: FilterItem[] | undefined): Promise<WhereOptions[]>;
|
|
112
94
|
abstract getSortOptions(sorts?: SortItem[] | undefined): any;
|
|
113
95
|
}
|
package/dist/BaseDatabase.js
CHANGED
|
@@ -44,127 +44,116 @@ class BaseDatabase {
|
|
|
44
44
|
let limit = page_size;
|
|
45
45
|
return { offset, limit };
|
|
46
46
|
}
|
|
47
|
-
_getFiltersConditions(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
let
|
|
57
|
-
let t = this.getTable(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
values.forEach(value => {
|
|
95
|
-
if (filter.not)
|
|
96
|
-
addCondition(idatabase.getNotLike(filter, column_name, value));
|
|
47
|
+
_getFiltersConditions(table_main, table_joins, idatabase, filters) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a;
|
|
50
|
+
let ans = [];
|
|
51
|
+
if (filters) {
|
|
52
|
+
let conditions_in_select_main = {};
|
|
53
|
+
Object.keys(table_joins).forEach(table => { conditions_in_select_main[table] = []; });
|
|
54
|
+
let processed = {};
|
|
55
|
+
let getCondition_IDInSelect = (table, not, conditions) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
let join = table_joins[table];
|
|
57
|
+
let t = this.getTable(table);
|
|
58
|
+
return idatabase.getInSelect(t, not, join, conditions);
|
|
59
|
+
});
|
|
60
|
+
for (let i = 0; i < filters.length; i++)
|
|
61
|
+
if (!processed[i]) {
|
|
62
|
+
const filter = filters[i];
|
|
63
|
+
let t = this.getTable(filter.table.name);
|
|
64
|
+
t.checkColumn(filter.column.name, false, null);
|
|
65
|
+
let join = table_joins[filter.table.name];
|
|
66
|
+
let is_table_main = table_main.getName() === filter.table.name;
|
|
67
|
+
let column_name = (_a = t.getRealColumnName(filter.column.name)) !== null && _a !== void 0 ? _a : filter.column.name;
|
|
68
|
+
let values = filter.values;
|
|
69
|
+
if (filter.operator.count > 0)
|
|
70
|
+
for (let j = i + 1; j < filters.length; j++) {
|
|
71
|
+
const f = filters[j];
|
|
72
|
+
if (filter.table.name == f.table.name)
|
|
73
|
+
if (filter.column.name == f.column.name)
|
|
74
|
+
if (filter.not == f.not)
|
|
75
|
+
if (filter.operator.sign == f.operator.sign) {
|
|
76
|
+
processed[j] = true;
|
|
77
|
+
values.push(...f.values);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let getNumbers = () => {
|
|
81
|
+
let nums = values.map(x => parseFloat(x));
|
|
82
|
+
if (nums.filter(x => isNaN(x)).length > 0)
|
|
83
|
+
namirasoft_core_1.ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
|
|
84
|
+
return nums;
|
|
85
|
+
};
|
|
86
|
+
let addCondition = (res) => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
let condition;
|
|
89
|
+
if (res.partial) {
|
|
90
|
+
let wh = {};
|
|
91
|
+
wh[column_name] = res.condition;
|
|
92
|
+
condition = wh;
|
|
93
|
+
}
|
|
97
94
|
else
|
|
98
|
-
|
|
95
|
+
condition = res.condition;
|
|
96
|
+
if (is_table_main)
|
|
97
|
+
ans.push(condition);
|
|
98
|
+
else {
|
|
99
|
+
if (!res.independant)
|
|
100
|
+
conditions_in_select_main[filter.table.name].push(condition);
|
|
101
|
+
else
|
|
102
|
+
ans.push(yield getCondition_IDInSelect(filter.table.name, res.independant.not, [condition, ...((_b = (_a = join.getExtraConditions) === null || _a === void 0 ? void 0 : _a.call(join, column_name)) !== null && _b !== void 0 ? _b : [])]));
|
|
103
|
+
}
|
|
99
104
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
if (filter.operator == namirasoft_core_1.FilterItemOperator.all.equals)
|
|
106
|
+
yield addCondition(idatabase.getIn(column_name, filter.not, values));
|
|
107
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.contains)
|
|
108
|
+
for (const value of values)
|
|
109
|
+
yield addCondition(idatabase.getLike(column_name, filter.not, value));
|
|
110
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.regex)
|
|
111
|
+
for (const value of values)
|
|
112
|
+
yield addCondition(idatabase.getRegex(column_name, filter.not, value));
|
|
113
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.empty)
|
|
114
|
+
yield addCondition(idatabase.getEmpty(column_name, filter.not));
|
|
115
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.exists)
|
|
116
|
+
yield addCondition(idatabase.getExists(column_name, filter.not));
|
|
117
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.includes)
|
|
118
|
+
yield addCondition(idatabase.getIncludes(column_name, filter.not, values));
|
|
119
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.startswith)
|
|
120
|
+
for (const value of values)
|
|
121
|
+
yield addCondition(idatabase.getStartsWith(column_name, filter.not, value));
|
|
122
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.endswith)
|
|
123
|
+
for (const value of values)
|
|
124
|
+
yield addCondition(idatabase.getEndsWith(column_name, filter.not, value));
|
|
125
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.lessthan) {
|
|
103
126
|
if (filter.not)
|
|
104
|
-
addCondition(idatabase.
|
|
127
|
+
yield addCondition(idatabase.getGTE(column_name, Math.max(...getNumbers())));
|
|
105
128
|
else
|
|
106
|
-
addCondition(idatabase.
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.empty) {
|
|
110
|
-
if (filter.not)
|
|
111
|
-
addCondition(idatabase.getNotEmpty(filter, column_name));
|
|
112
|
-
else
|
|
113
|
-
addCondition(idatabase.getEmpty(filter, column_name));
|
|
114
|
-
}
|
|
115
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.exists) {
|
|
116
|
-
if (!table.join_conditions)
|
|
117
|
-
throw namirasoft_core_1.ErrorOperation.getHTTP(500, `Table ${filter.table.name} does not have join conditions.`);
|
|
118
|
-
addCondition(idatabase.getExists(filter, column_name, filter.not, table.join_conditions));
|
|
119
|
-
}
|
|
120
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.includes) {
|
|
121
|
-
if (!table.join_conditions)
|
|
122
|
-
throw namirasoft_core_1.ErrorOperation.getHTTP(500, `Table ${filter.table.name} does not have join conditions.`);
|
|
123
|
-
addCondition(idatabase.getIncludes(filter, column_name, filter.not, table.join_conditions, values));
|
|
124
|
-
}
|
|
125
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.startswith) {
|
|
126
|
-
values.forEach(value => {
|
|
129
|
+
yield addCondition(idatabase.getLT(column_name, Math.max(...getNumbers())));
|
|
130
|
+
}
|
|
131
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.lessthanequal) {
|
|
127
132
|
if (filter.not)
|
|
128
|
-
addCondition(idatabase.
|
|
133
|
+
yield addCondition(idatabase.getGT(column_name, Math.max(...getNumbers())));
|
|
129
134
|
else
|
|
130
|
-
addCondition(idatabase.
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.endswith) {
|
|
134
|
-
values.forEach(value => {
|
|
135
|
+
yield addCondition(idatabase.getLTE(column_name, Math.max(...getNumbers())));
|
|
136
|
+
}
|
|
137
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.morethan) {
|
|
135
138
|
if (filter.not)
|
|
136
|
-
addCondition(idatabase.
|
|
139
|
+
yield addCondition(idatabase.getLTE(column_name, Math.max(...getNumbers())));
|
|
137
140
|
else
|
|
138
|
-
addCondition(idatabase.
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.lessthanequal) {
|
|
148
|
-
if (filter.not)
|
|
149
|
-
addCondition(idatabase.getGT(filter, column_name, Math.max(...getNumbers())));
|
|
150
|
-
else
|
|
151
|
-
addCondition(idatabase.getLTE(filter, column_name, Math.max(...getNumbers())));
|
|
152
|
-
}
|
|
153
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.morethan) {
|
|
154
|
-
if (filter.not)
|
|
155
|
-
addCondition(idatabase.getLTE(filter, column_name, Math.max(...getNumbers())));
|
|
156
|
-
else
|
|
157
|
-
addCondition(idatabase.getGT(filter, column_name, Math.max(...getNumbers())));
|
|
158
|
-
}
|
|
159
|
-
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.morethanequal) {
|
|
160
|
-
if (filter.not)
|
|
161
|
-
addCondition(idatabase.getLT(filter, column_name, Math.max(...getNumbers())));
|
|
162
|
-
else
|
|
163
|
-
addCondition(idatabase.getGTE(filter, column_name, Math.max(...getNumbers())));
|
|
141
|
+
yield addCondition(idatabase.getGT(column_name, Math.max(...getNumbers())));
|
|
142
|
+
}
|
|
143
|
+
else if (filter.operator == namirasoft_core_1.FilterItemOperator.all.morethanequal) {
|
|
144
|
+
if (filter.not)
|
|
145
|
+
yield addCondition(idatabase.getLT(column_name, Math.max(...getNumbers())));
|
|
146
|
+
else
|
|
147
|
+
yield addCondition(idatabase.getGTE(column_name, Math.max(...getNumbers())));
|
|
148
|
+
}
|
|
164
149
|
}
|
|
150
|
+
for (let table of Object.keys(conditions_in_select_main)) {
|
|
151
|
+
let conditions = conditions_in_select_main[table];
|
|
152
|
+
ans.push(yield getCondition_IDInSelect(table, false, conditions));
|
|
165
153
|
}
|
|
166
|
-
|
|
167
|
-
|
|
154
|
+
}
|
|
155
|
+
return ans;
|
|
156
|
+
});
|
|
168
157
|
}
|
|
169
158
|
}
|
|
170
159
|
exports.BaseDatabase = BaseDatabase;
|
package/dist/BaseDatabase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseDatabase.js","sourceRoot":"","sources":["../src/BaseDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAA2F;
|
|
1
|
+
{"version":3,"file":"BaseDatabase.js","sourceRoot":"","sources":["../src/BaseDatabase.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAA2F;AA+B3F,MAAsB,YAAY;IAAlC;QAEY,WAAM,GAA4B,EAAE,CAAC;IAsKjD,CAAC;IAhKS,UAAU;;QAEhB,CAAC;KAAA;IACK,SAAS;;QAEf,CAAC;KAAA;IACD,QAAQ,CAAC,IAAY,EAAE,KAAU;QAE7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IAC9B,CAAC;IACD,QAAQ,CAAI,IAAY;QAEpB,IAAI,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAM,CAAC;QACjC,IAAI,CAAC,GAAG;YACJ,gCAAc,CAAC,SAAS,CAAC,GAAG,EAAE,UAAU,IAAI,aAAa,CAAC,CAAC;QAC/D,OAAO,GAAG,CAAC;IACf,CAAC;IACD,QAAQ,CAAC,WAAmB,EAAE,SAAiB,EAAE,iBAA0B;QAGvE,IAAI,KAA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CAAC;4BACG,IAAI,MAAM,CAAC,GAAG;gCACV,MAAM,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;;gCAE7E,MAAM,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;wBACpF,CAAC;6BACI,IAAI,MAAM,CAAC,QAAQ,IAAI,oCAAkB,CAAC,GAAG,CAAC,aAAa,EAChE,CAAC;4BACG,IAAI,MAAM,CAAC,GAAG;gCACV,MAAM,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;;gCAE5E,MAAM,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;wBACrF,CAAC;oBACL,CAAC;gBACL,KAAK,IAAI,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,EACxD,CAAC;oBACG,IAAI,UAAU,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;oBAClD,GAAG,CAAC,IAAI,CAAC,MAAM,uBAAuB,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;gBACtE,CAAC;YACL,CAAC;YACD,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;CAEJ;AAxKD,oCAwKC"}
|
package/dist/BaseTable.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare abstract class BaseTable<D extends BaseDatabase, ModelColumnOptio
|
|
|
14
14
|
abstract forEachColumn(handler: (name: string, column: ModelColumnOption) => void): void;
|
|
15
15
|
getColumns(secure?: boolean | null, read_only?: boolean | null): string[];
|
|
16
16
|
checkColumn(column: string, secure: boolean | null, read_only: boolean | null): void;
|
|
17
|
+
getRealColumnName(column: string): string;
|
|
17
18
|
secure(obj: any): any;
|
|
18
19
|
getArraySchema(require: boolean, name?: string): ArraySchema;
|
|
19
20
|
getSchema(require: boolean, name?: string): ObjectSchema;
|
package/dist/BaseTable.js
CHANGED
|
@@ -38,6 +38,9 @@ class BaseTable {
|
|
|
38
38
|
if (!columns.includes(column))
|
|
39
39
|
namirasoft_core_1.ErrorOperation.throwHTTP(404, `Column '${column}' not found`);
|
|
40
40
|
}
|
|
41
|
+
getRealColumnName(column) {
|
|
42
|
+
return column;
|
|
43
|
+
}
|
|
41
44
|
secure(obj) {
|
|
42
45
|
if (obj.dataValues)
|
|
43
46
|
obj = obj.dataValues;
|
|
@@ -50,9 +53,11 @@ class BaseTable {
|
|
|
50
53
|
return new namirasoft_schema_1.ArraySchema(require, [ans]);
|
|
51
54
|
}
|
|
52
55
|
getSchema(require, name) {
|
|
56
|
+
if (!name)
|
|
57
|
+
name = namirasoft_core_1.NamingConvention.lower_case_underscore.convert(this.getName(), namirasoft_core_1.NamingConvention.Pascal_Case);
|
|
53
58
|
let columns_secure = this.getSecureColumns();
|
|
54
59
|
let columns_read_only = this.getReadOnlyColumns();
|
|
55
|
-
let ans = new namirasoft_schema_1.ObjectSchema(name
|
|
60
|
+
let ans = new namirasoft_schema_1.ObjectSchema(name, require, null);
|
|
56
61
|
this.forEachColumn((name, element) => {
|
|
57
62
|
if (!columns_secure.includes(name))
|
|
58
63
|
ans.addField(this.getVariableSchema(name, element, columns_read_only.includes(name)));
|
|
@@ -90,7 +95,8 @@ class BaseTable {
|
|
|
90
95
|
setSchemaByName(_) {
|
|
91
96
|
}
|
|
92
97
|
getNotFoundError(conditions) {
|
|
93
|
-
|
|
98
|
+
let name = namirasoft_core_1.NamingConvention.lower_case_underscore.convert(this.getName(), namirasoft_core_1.NamingConvention.Pascal_Case);
|
|
99
|
+
return namirasoft_core_1.ErrorOperation.getHTTP(404, "Could not find " + name + " for " + JSON.stringify(conditions));
|
|
94
100
|
}
|
|
95
101
|
}
|
|
96
102
|
exports.BaseTable = BaseTable;
|
package/dist/BaseTable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTable.js","sourceRoot":"","sources":["../src/BaseTable.ts"],"names":[],"mappings":";;;AAAA,yDAAkG;AAElG,
|
|
1
|
+
{"version":3,"file":"BaseTable.js","sourceRoot":"","sources":["../src/BaseTable.ts"],"names":[],"mappings":";;;AAAA,yDAAkG;AAElG,qDAA6E;AAE7E,MAAsB,SAAS;IAI3B,YAAY,QAAW;QAEnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,0BAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IAClD,CAAC;IAGS,gBAAgB,CAAC,OAAiB;QAExC,OAAO,OAAO,CAAC;IACnB,CAAC;IACS,kBAAkB,CAAC,OAAiB;QAE1C,OAAO,OAAO,CAAC;IACnB,CAAC;IACM,gBAAgB;QAEnB,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IACM,kBAAkB;QAErB,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAEM,UAAU,CAAC,SAAyB,KAAK,EAAE,YAA4B,IAAI;QAE9E,IAAI,cAAc,GAAa,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACvD,IAAI,iBAAiB,GAAa,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC5D,IAAI,OAAO,GAAa,EAAE,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACp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AAI,IAAI,EACR,CAAC;YACG,IAAI,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAClC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,IAAI,CAAC,CAAC;YAC/D,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IACM,oBAAoB,CAAC,OAAgB,EAAE,IAAa;QAEvD,IAAI,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC9C,OAAO,IAAI,+BAAW,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC;IACS,eAAe,CAAC,CAAe;IAEzC,CAAC;IACM,gBAAgB,CAAC,UAAsB;QAE1C,IAAI,IAAI,GAAG,kCAAgB,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,kCAAgB,CAAC,WAAW,CAAC,CAAC;QACxG,OAAO,gCAAc,CAAC,OAAO,CAAC,GAAG,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACxG,CAAC;CACJ;AAzHD,8BAyHC"}
|
package/package.json
CHANGED
package/src/BaseDatabase.ts
CHANGED
|
@@ -2,44 +2,32 @@ import * as express from "express";
|
|
|
2
2
|
import { ErrorOperation, FilterItem, FilterItemOperator, SortItem } from "namirasoft-core";
|
|
3
3
|
import { BaseTable } from "./BaseTable";
|
|
4
4
|
|
|
5
|
-
export interface BaseDatabase_FilterTable
|
|
6
|
-
{
|
|
7
|
-
join_conditions?: BaseDatabase_FilterTable_JoinConditions;
|
|
8
|
-
overrideColumnName?: (column: string) => string;
|
|
9
|
-
}
|
|
10
|
-
export interface BaseDatabase_FilterTable_JoinConditions
|
|
5
|
+
export interface BaseDatabase_FilterTable<WhereOptions>
|
|
11
6
|
{
|
|
12
7
|
main: {
|
|
13
|
-
table: string;
|
|
14
8
|
column: string;
|
|
15
9
|
};
|
|
16
10
|
secondary: {
|
|
17
|
-
table: string;
|
|
18
11
|
column: string;
|
|
19
12
|
};
|
|
20
|
-
getExtraConditions?: (column: string) =>
|
|
13
|
+
getExtraConditions?: (column: string) => WhereOptions[];
|
|
21
14
|
}
|
|
22
15
|
|
|
23
16
|
export interface IFilterableDatabase<WhereOptions>
|
|
24
17
|
{
|
|
25
|
-
getIn: (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
getNotEndsWith: (filter: FilterItem, column_name: string, value: string) => { condition: WhereOptions, partial: boolean };
|
|
39
|
-
getLT: (filter: FilterItem, column_name: string, value: any) => { condition: WhereOptions, partial: boolean };
|
|
40
|
-
getLTE: (filter: FilterItem, column_name: string, value: any) => { condition: WhereOptions, partial: boolean };
|
|
41
|
-
getGT: (filter: FilterItem, column_name: string, value: any) => { condition: WhereOptions, partial: boolean };
|
|
42
|
-
getGTE: (filter: FilterItem, column_name: string, value: any) => { condition: WhereOptions, partial: boolean };
|
|
18
|
+
getIn: (column_name: string, not: boolean, values: string[]) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
19
|
+
getLike: (column_name: string, not: boolean, value: string) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
20
|
+
getRegex: (column_name: string, not: boolean, value: string) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
21
|
+
getEmpty: (column_name: string, not: boolean) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
22
|
+
getExists: (column_name: string, not: boolean) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
23
|
+
getIncludes: (column_name: string, not: boolean, value: string[]) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
24
|
+
getStartsWith: (column_name: string, not: boolean, value: string) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
25
|
+
getEndsWith: (column_name: string, not: boolean, value: string) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
26
|
+
getLT: (column_name: string, value: any) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
27
|
+
getLTE: (column_name: string, value: any) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
28
|
+
getGT: (column_name: string, value: any) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
29
|
+
getGTE: (column_name: string, value: any) => { condition: WhereOptions, partial: boolean, required: boolean };
|
|
30
|
+
getInSelect: (t: BaseTable<BaseDatabase, any>, not: boolean, join: BaseDatabase_FilterTable<WhereOptions>, conditions: WhereOptions[]) => WhereOptions;
|
|
43
31
|
}
|
|
44
32
|
|
|
45
33
|
export abstract class BaseDatabase
|
|
@@ -83,21 +71,32 @@ export abstract class BaseDatabase
|
|
|
83
71
|
let limit = page_size;
|
|
84
72
|
return { offset, limit };
|
|
85
73
|
}
|
|
86
|
-
protected _getFiltersConditions<WhereOptions>(
|
|
74
|
+
protected async _getFiltersConditions<WhereOptions>(table_main: BaseTable<BaseDatabase, any>, table_joins: { [table: string]: BaseDatabase_FilterTable<WhereOptions> }, idatabase: IFilterableDatabase<WhereOptions>, filters?: FilterItem[] | undefined): Promise<WhereOptions[]>
|
|
87
75
|
{
|
|
88
|
-
let ans:
|
|
89
|
-
Object.keys(tables).forEach(table => ans[table] = []);
|
|
76
|
+
let ans: WhereOptions[] = [];
|
|
90
77
|
if (filters)
|
|
91
78
|
{
|
|
79
|
+
let conditions_in_select_main: { [table: string]: WhereOptions[] } = {};
|
|
80
|
+
Object.keys(table_joins).forEach(table => { conditions_in_select_main[table] = []; });
|
|
92
81
|
let processed: { [index: number]: boolean } = {};
|
|
82
|
+
|
|
83
|
+
let getCondition_IDInSelect = async (table: string, not: boolean, conditions: WhereOptions[]): Promise<WhereOptions> =>
|
|
84
|
+
{
|
|
85
|
+
let join = table_joins[table];
|
|
86
|
+
let t: BaseTable<BaseDatabase, any> = this.getTable<BaseTable<BaseDatabase, any>>(table);
|
|
87
|
+
return idatabase.getInSelect(t, not, join, conditions);
|
|
88
|
+
}
|
|
89
|
+
|
|
93
90
|
for (let i = 0; i < filters.length; i++)
|
|
94
91
|
if (!processed[i])
|
|
95
92
|
{
|
|
96
93
|
const filter = filters[i];
|
|
97
|
-
let table = tables[filter.table.name];
|
|
98
94
|
let t = this.getTable<BaseTable<BaseDatabase, any>>(filter.table.name);
|
|
99
|
-
let column_name = table?.overrideColumnName?.(filter.column.name) ?? filter.column.name;
|
|
100
95
|
t.checkColumn(filter.column.name, false, null);
|
|
96
|
+
let join = table_joins[filter.table.name];
|
|
97
|
+
let is_table_main = table_main.getName() === filter.table.name;
|
|
98
|
+
let column_name = t.getRealColumnName(filter.column.name) ?? filter.column.name;
|
|
99
|
+
|
|
101
100
|
let values = filter.values;
|
|
102
101
|
if (filter.operator.count > 0)
|
|
103
102
|
for (let j = i + 1; j < filters.length; j++)
|
|
@@ -120,112 +119,81 @@ export abstract class BaseDatabase
|
|
|
120
119
|
ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
|
|
121
120
|
return nums;
|
|
122
121
|
};
|
|
123
|
-
let addCondition = (res: { condition: WhereOptions, partial: boolean }) =>
|
|
122
|
+
let addCondition = async (res: { condition: WhereOptions, partial: boolean, independant?: { not: boolean } }) =>
|
|
124
123
|
{
|
|
124
|
+
let condition: WhereOptions;
|
|
125
125
|
if (res.partial)
|
|
126
126
|
{
|
|
127
127
|
let wh: any = {};
|
|
128
128
|
wh[column_name] = res.condition;
|
|
129
|
-
|
|
129
|
+
condition = wh;
|
|
130
130
|
}
|
|
131
131
|
else
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
{
|
|
136
|
-
if (filter.not)
|
|
137
|
-
addCondition(idatabase.getNotIn(filter, column_name, values));
|
|
132
|
+
condition = res.condition;
|
|
133
|
+
if (is_table_main)
|
|
134
|
+
ans.push(condition);
|
|
138
135
|
else
|
|
139
|
-
addCondition(idatabase.getIn(filter, column_name, values));
|
|
140
|
-
}
|
|
141
|
-
else if (filter.operator == FilterItemOperator.all.contains)
|
|
142
|
-
{
|
|
143
|
-
values.forEach(value =>
|
|
144
136
|
{
|
|
145
|
-
if (
|
|
146
|
-
|
|
137
|
+
if (!res.independant)
|
|
138
|
+
conditions_in_select_main[filter.table.name].push(condition);
|
|
147
139
|
else
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
}
|
|
140
|
+
ans.push(await getCondition_IDInSelect(filter.table.name, res.independant.not, [condition, ...(join.getExtraConditions?.(column_name) ?? [])]));
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
if (filter.operator == FilterItemOperator.all.equals)
|
|
144
|
+
await addCondition(idatabase.getIn(column_name, filter.not, values));
|
|
145
|
+
else if (filter.operator == FilterItemOperator.all.contains)
|
|
146
|
+
for (const value of values)
|
|
147
|
+
await addCondition(idatabase.getLike(column_name, filter.not, value));
|
|
151
148
|
else if (filter.operator == FilterItemOperator.all.regex)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
{
|
|
155
|
-
if (filter.not)
|
|
156
|
-
addCondition(idatabase.getNotRegex(filter, column_name, value));
|
|
157
|
-
else
|
|
158
|
-
addCondition(idatabase.getRegex(filter, column_name, value));
|
|
159
|
-
});
|
|
160
|
-
}
|
|
149
|
+
for (const value of values)
|
|
150
|
+
await addCondition(idatabase.getRegex(column_name, filter.not, value));
|
|
161
151
|
else if (filter.operator == FilterItemOperator.all.empty)
|
|
162
|
-
|
|
163
|
-
if (filter.not)
|
|
164
|
-
addCondition(idatabase.getNotEmpty(filter, column_name));
|
|
165
|
-
else
|
|
166
|
-
addCondition(idatabase.getEmpty(filter, column_name));
|
|
167
|
-
}
|
|
152
|
+
await addCondition(idatabase.getEmpty(column_name, filter.not));
|
|
168
153
|
else if (filter.operator == FilterItemOperator.all.exists)
|
|
169
|
-
|
|
170
|
-
if (!table.join_conditions)
|
|
171
|
-
throw ErrorOperation.getHTTP(500, `Table ${filter.table.name} does not have join conditions.`);
|
|
172
|
-
addCondition(idatabase.getExists(filter, column_name, filter.not, table.join_conditions));
|
|
173
|
-
}
|
|
154
|
+
await addCondition(idatabase.getExists(column_name, filter.not));
|
|
174
155
|
else if (filter.operator == FilterItemOperator.all.includes)
|
|
175
|
-
|
|
176
|
-
if (!table.join_conditions)
|
|
177
|
-
throw ErrorOperation.getHTTP(500, `Table ${filter.table.name} does not have join conditions.`);
|
|
178
|
-
addCondition(idatabase.getIncludes(filter, column_name, filter.not, table.join_conditions, values));
|
|
179
|
-
}
|
|
156
|
+
await addCondition(idatabase.getIncludes(column_name, filter.not, values));
|
|
180
157
|
else if (filter.operator == FilterItemOperator.all.startswith)
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{
|
|
184
|
-
if (filter.not)
|
|
185
|
-
addCondition(idatabase.getNotStartsWith(filter, column_name, value));
|
|
186
|
-
else
|
|
187
|
-
addCondition(idatabase.getStartsWith(filter, column_name, value));
|
|
188
|
-
});
|
|
189
|
-
}
|
|
158
|
+
for (const value of values)
|
|
159
|
+
await addCondition(idatabase.getStartsWith(column_name, filter.not, value));
|
|
190
160
|
else if (filter.operator == FilterItemOperator.all.endswith)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
{
|
|
194
|
-
if (filter.not)
|
|
195
|
-
addCondition(idatabase.getNotEndsWith(filter, column_name, value));
|
|
196
|
-
else
|
|
197
|
-
addCondition(idatabase.getEndsWith(filter, column_name, value));
|
|
198
|
-
});
|
|
199
|
-
}
|
|
161
|
+
for (const value of values)
|
|
162
|
+
await addCondition(idatabase.getEndsWith(column_name, filter.not, value));
|
|
200
163
|
else if (filter.operator == FilterItemOperator.all.lessthan)
|
|
201
164
|
{
|
|
202
165
|
if (filter.not)
|
|
203
|
-
addCondition(idatabase.getGTE(
|
|
166
|
+
await addCondition(idatabase.getGTE(column_name, Math.max(...getNumbers())));
|
|
204
167
|
else
|
|
205
|
-
addCondition(idatabase.getLT(
|
|
168
|
+
await addCondition(idatabase.getLT(column_name, Math.max(...getNumbers())));
|
|
206
169
|
}
|
|
207
170
|
else if (filter.operator == FilterItemOperator.all.lessthanequal)
|
|
208
171
|
{
|
|
209
172
|
if (filter.not)
|
|
210
|
-
addCondition(idatabase.getGT(
|
|
173
|
+
await addCondition(idatabase.getGT(column_name, Math.max(...getNumbers())));
|
|
211
174
|
else
|
|
212
|
-
addCondition(idatabase.getLTE(
|
|
175
|
+
await addCondition(idatabase.getLTE(column_name, Math.max(...getNumbers())));
|
|
213
176
|
}
|
|
214
177
|
else if (filter.operator == FilterItemOperator.all.morethan)
|
|
215
178
|
{
|
|
216
179
|
if (filter.not)
|
|
217
|
-
addCondition(idatabase.getLTE(
|
|
180
|
+
await addCondition(idatabase.getLTE(column_name, Math.max(...getNumbers())));
|
|
218
181
|
else
|
|
219
|
-
addCondition(idatabase.getGT(
|
|
182
|
+
await addCondition(idatabase.getGT(column_name, Math.max(...getNumbers())));
|
|
220
183
|
}
|
|
221
184
|
else if (filter.operator == FilterItemOperator.all.morethanequal)
|
|
222
185
|
{
|
|
223
186
|
if (filter.not)
|
|
224
|
-
addCondition(idatabase.getLT(
|
|
187
|
+
await addCondition(idatabase.getLT(column_name, Math.max(...getNumbers())));
|
|
225
188
|
else
|
|
226
|
-
addCondition(idatabase.getGTE(
|
|
189
|
+
await addCondition(idatabase.getGTE(column_name, Math.max(...getNumbers())));
|
|
227
190
|
}
|
|
228
191
|
}
|
|
192
|
+
for (let table of Object.keys(conditions_in_select_main))
|
|
193
|
+
{
|
|
194
|
+
let conditions = conditions_in_select_main[table];
|
|
195
|
+
ans.push(await getCondition_IDInSelect(table, false, conditions));
|
|
196
|
+
}
|
|
229
197
|
}
|
|
230
198
|
return ans;
|
|
231
199
|
}
|
package/src/BaseTable.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ArraySchema, BaseTypeSchema, BaseVariableSchema, ObjectSchema } from "namirasoft-schema";
|
|
2
2
|
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
-
import { ErrorOperation, BaseUUID } from "namirasoft-core";
|
|
3
|
+
import { ErrorOperation, BaseUUID, NamingConvention } from "namirasoft-core";
|
|
4
4
|
|
|
5
5
|
export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption>
|
|
6
6
|
{
|
|
@@ -50,6 +50,10 @@ export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption>
|
|
|
50
50
|
if (!columns.includes(column))
|
|
51
51
|
ErrorOperation.throwHTTP(404, `Column '${column}' not found`);
|
|
52
52
|
}
|
|
53
|
+
public getRealColumnName(column: string): string
|
|
54
|
+
{
|
|
55
|
+
return column;
|
|
56
|
+
}
|
|
53
57
|
public secure(obj: any)
|
|
54
58
|
{
|
|
55
59
|
if (obj.dataValues)
|
|
@@ -65,9 +69,11 @@ export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption>
|
|
|
65
69
|
}
|
|
66
70
|
public getSchema(require: boolean, name?: string): ObjectSchema
|
|
67
71
|
{
|
|
72
|
+
if (!name)
|
|
73
|
+
name = NamingConvention.lower_case_underscore.convert(this.getName(), NamingConvention.Pascal_Case);
|
|
68
74
|
let columns_secure: string[] = this.getSecureColumns();
|
|
69
75
|
let columns_read_only: string[] = this.getReadOnlyColumns();
|
|
70
|
-
let ans = new ObjectSchema(name
|
|
76
|
+
let ans = new ObjectSchema(name, require, null);
|
|
71
77
|
this.forEachColumn((name, element) =>
|
|
72
78
|
{
|
|
73
79
|
if (!columns_secure.includes(name))
|
|
@@ -114,6 +120,7 @@ export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption>
|
|
|
114
120
|
}
|
|
115
121
|
public getNotFoundError(conditions: any | null)
|
|
116
122
|
{
|
|
117
|
-
|
|
123
|
+
let name = NamingConvention.lower_case_underscore.convert(this.getName(), NamingConvention.Pascal_Case);
|
|
124
|
+
return ErrorOperation.getHTTP(404, "Could not find " + name + " for " + JSON.stringify(conditions));
|
|
118
125
|
}
|
|
119
126
|
}
|