ismx-nexo-node-app 0.4.76 → 0.4.78
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/js/business/BusinessProxy.js +4 -6
- package/dist/js/repository/RepositoryDatabasePostgres.js +2 -0
- package/dist/types/business/BusinessProxy.d.ts +2 -0
- package/package.json +1 -1
- package/src/main/node/business/BusinessProxy.ts +8 -6
- package/src/main/node/repository/RepositoryDatabasePostgres.ts +2 -0
|
@@ -44,6 +44,9 @@ class BusinessProxy {
|
|
|
44
44
|
setModules(modules) {
|
|
45
45
|
this.modules = modules;
|
|
46
46
|
}
|
|
47
|
+
setOnError(onError) {
|
|
48
|
+
this.onError = onError;
|
|
49
|
+
}
|
|
47
50
|
call(tag, method, endpoint, request) {
|
|
48
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
52
|
var _a, _b;
|
|
@@ -63,12 +66,7 @@ class BusinessProxy {
|
|
|
63
66
|
body = JSON.stringify(request.body);
|
|
64
67
|
}
|
|
65
68
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
66
|
-
|
|
67
|
-
return (0, node_fetch_1.default)(module.host + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { method, body: method !== "GET" ? body : undefined, headers }));
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw new Error(`Module ${tag} is not responding`);
|
|
71
|
-
}
|
|
69
|
+
return (0, node_fetch_1.default)(module.host + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { method, body: method !== "GET" ? body : undefined, headers })).catch((error) => { var _a, _b; return (_b = (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, error)) !== null && _b !== void 0 ? _b : error; });
|
|
72
70
|
});
|
|
73
71
|
}
|
|
74
72
|
}
|
|
@@ -156,6 +156,8 @@ class RepositoryDatabasePostgres extends RepositoryDatabase_1.default {
|
|
|
156
156
|
const camelKey = PostgresUtils_1.default.snakeToCamel(column);
|
|
157
157
|
return Object.prototype.hasOwnProperty.call(object, camelKey);
|
|
158
158
|
});
|
|
159
|
+
if (columns.length === 0)
|
|
160
|
+
return this.one(tableName, id);
|
|
159
161
|
const params = columns.map((_, index) => `\$${index + 2}`).join(",");
|
|
160
162
|
const values = [id, ...columns.map((column) => object[PostgresUtils_1.default.snakeToCamel(column)])];
|
|
161
163
|
const query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = ROW(${params}) WHERE id = $1 RETURNING *`;
|
|
@@ -7,8 +7,10 @@ export interface Module {
|
|
|
7
7
|
}
|
|
8
8
|
export default class BusinessProxy {
|
|
9
9
|
private modules;
|
|
10
|
+
private onError?;
|
|
10
11
|
setModules(modules: {
|
|
11
12
|
[key: string]: Module;
|
|
12
13
|
}): void;
|
|
14
|
+
setOnError(onError: (error: Error) => Error): void;
|
|
13
15
|
call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response>;
|
|
14
16
|
}
|
package/package.json
CHANGED
|
@@ -12,11 +12,16 @@ export interface Module {
|
|
|
12
12
|
export default class BusinessProxy
|
|
13
13
|
{
|
|
14
14
|
private modules: {[key:string]: Module} = {};
|
|
15
|
+
private onError?: (error: Error) => Error;
|
|
15
16
|
|
|
16
17
|
setModules(modules: {[key:string]: Module}) {
|
|
17
18
|
this.modules = modules
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
setOnError(onError: (error: Error) => Error) {
|
|
22
|
+
this.onError = onError;
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
async call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response> {
|
|
21
26
|
let module = this.modules[tag];
|
|
22
27
|
if (!module) throw new Error(`Module ${tag} does not exist`);
|
|
@@ -36,11 +41,8 @@ export default class BusinessProxy
|
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
} catch (error) { throw new Error(`Module ${tag} is not responding`); }
|
|
44
|
+
return fetch(module.host + endpoint + QueryUtils.map(request.query), {
|
|
45
|
+
...request, method, body: method !== "GET" ? body : undefined, headers
|
|
46
|
+
}).catch((error) => this.onError?.(error) ?? error);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
@@ -131,6 +131,8 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
131
131
|
return Object.prototype.hasOwnProperty.call(object, camelKey);
|
|
132
132
|
});
|
|
133
133
|
|
|
134
|
+
if (columns.length === 0) return this.one(tableName, id);
|
|
135
|
+
|
|
134
136
|
const params = columns.map((_, index) => `\$${index + 2}`).join(",");
|
|
135
137
|
const values = [ id, ...columns.map((column) => object[PostgresUtils.snakeToCamel(column) as keyof T]) ];
|
|
136
138
|
const query = `UPDATE ${schema}.${tableName} SET (${columns.join(",")}) = ROW(${params}) WHERE id = $1 RETURNING *`;
|