@pxp-nd/core 1.2.77 → 1.2.79
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.
|
@@ -36,12 +36,13 @@ export declare class Controller implements ControllerInterface {
|
|
|
36
36
|
private basicReadOnly;
|
|
37
37
|
constructor(module: string, Entity?: any, config?: IConfigPxpApp, io?: any);
|
|
38
38
|
private initializeRoutes;
|
|
39
|
-
genericMethodWrapper(params: Record<string, unknown>, req: Request, next: NextFunction, res: Response, methodName: string, dbsettings: string, readonly: boolean, permission
|
|
40
|
-
ormMethodWrapper(params: Record<string, unknown>, req: Request | any, next: NextFunction, res: Response, methodName: string, readonly: boolean, permission?: boolean, log?: boolean, logConfig?: {}): Promise<void>;
|
|
39
|
+
genericMethodWrapper(params: Record<string, unknown>, req: Request, next: NextFunction, res: Response, methodName: string, dbsettings: string, readonly: boolean, permission: boolean, log: boolean, logConfig: {}, isHtml: boolean): Promise<void>;
|
|
40
|
+
ormMethodWrapper(params: Record<string, unknown>, req: Request | any, next: NextFunction, res: Response, methodName: string, readonly: boolean, permission?: boolean, log?: boolean, logConfig?: {}, isHtml?: boolean): Promise<void>;
|
|
41
41
|
list(params: Record<string, unknown>): Promise<unknown>;
|
|
42
42
|
add(params: Record<string, unknown>, manager: EntityManager): Promise<unknown>;
|
|
43
43
|
edit(params: Record<string, unknown>, manager: EntityManager): Promise<unknown>;
|
|
44
44
|
delete(params: Record<string, unknown>, manager: EntityManager): Promise<unknown>;
|
|
45
|
+
getWhereOwnColumns(params: Record<string, unknown>, model: any): Record<any, any>;
|
|
45
46
|
getListParams(params: Record<string, unknown>, where: Record<string, unknown>): ListParam;
|
|
46
47
|
procedureMethodWrapper(params: Record<string, unknown>, next: NextFunction, res: Response, methodName: string, readonly: boolean, permission?: boolean, log?: boolean, logConfig?: {}): Promise<void>;
|
|
47
48
|
sqlMethodWrapper(params: Record<string, unknown>, next: NextFunction, res: Response, methodName: string, readonly: boolean, permission?: boolean, log?: boolean, logConfig?: {}): Promise<void>;
|
|
@@ -125,6 +125,8 @@ class Controller {
|
|
|
125
125
|
const dbsettings = Reflect.getMetadata('dbsettings', this.constructor) || {};
|
|
126
126
|
// get logConfig
|
|
127
127
|
const logConfig = Reflect.getMetadata('logConfig', this.constructor) || {};
|
|
128
|
+
// get type return
|
|
129
|
+
let ishtml = Reflect.getMetadata('ishtml', this.constructor) || {};
|
|
128
130
|
const defaultConfig = Reflect.getMetadata('optionsRoute', this.constructor) || {};
|
|
129
131
|
// define basic routes
|
|
130
132
|
if (this.modelString !== '') {
|
|
@@ -139,6 +141,8 @@ class Controller {
|
|
|
139
141
|
const logMethod = log[route.methodName] !== undefined ? log[route.methodName] : (defaultConfig[route.methodName] ? defaultConfig[route.methodName].log : true);
|
|
140
142
|
const logValue = typeof logMethod == 'object' ? logMethod : logConfig[route.methodName];
|
|
141
143
|
const logKey = typeof logMethod == 'object' ? true : logMethod;
|
|
144
|
+
// is html
|
|
145
|
+
const isHtmlMethod = ishtml[route.methodName] !== undefined ? ishtml[route.methodName] : (defaultConfig[route.methodName] ? defaultConfig[route.methodName].ishtml : false);
|
|
142
146
|
if (readOnlyMethod === null || readOnlyMethod === undefined) {
|
|
143
147
|
throw new index_1.PxpError(500, 'ReadOnly decorator was not defined for ' +
|
|
144
148
|
route.methodName +
|
|
@@ -164,7 +168,7 @@ class Controller {
|
|
|
164
168
|
.toLowerCase();
|
|
165
169
|
this.validated = false;
|
|
166
170
|
try {
|
|
167
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, false, logKey, logValue));
|
|
171
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, false, logKey, logValue, isHtmlMethod));
|
|
168
172
|
}
|
|
169
173
|
catch (ex) {
|
|
170
174
|
const now = new Date();
|
|
@@ -198,7 +202,7 @@ class Controller {
|
|
|
198
202
|
.toLowerCase();
|
|
199
203
|
this.validated = false;
|
|
200
204
|
try {
|
|
201
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, permission[route.methodName], logKey, logValue));
|
|
205
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, permission[route.methodName], logKey, logValue, isHtmlMethod));
|
|
202
206
|
}
|
|
203
207
|
catch (ex) {
|
|
204
208
|
const now = new Date();
|
|
@@ -212,9 +216,9 @@ class Controller {
|
|
|
212
216
|
}
|
|
213
217
|
});
|
|
214
218
|
}
|
|
215
|
-
async genericMethodWrapper(params, req, next, res, methodName, dbsettings, readonly, permission = true, log = true, logConfig = {}) {
|
|
219
|
+
async genericMethodWrapper(params, req, next, res, methodName, dbsettings, readonly, permission = true, log = true, logConfig = {}, isHtml) {
|
|
216
220
|
if (dbsettings === 'Orm') {
|
|
217
|
-
await index_1.__(this.ormMethodWrapper(params, req, next, res, methodName, readonly, permission, log, logConfig));
|
|
221
|
+
await index_1.__(this.ormMethodWrapper(params, req, next, res, methodName, readonly, permission, log, logConfig, isHtml));
|
|
218
222
|
}
|
|
219
223
|
else if (dbsettings === 'Procedure') {
|
|
220
224
|
await index_1.__(this.procedureMethodWrapper(params, next, res, methodName, readonly, permission, log, logConfig));
|
|
@@ -223,7 +227,7 @@ class Controller {
|
|
|
223
227
|
await this.sqlMethodWrapper(params, next, res, methodName, readonly, permission, log, logConfig);
|
|
224
228
|
}
|
|
225
229
|
}
|
|
226
|
-
async ormMethodWrapper(params, req, next, res, methodName, readonly, permission = true, log = true, logConfig = {}) {
|
|
230
|
+
async ormMethodWrapper(params, req, next, res, methodName, readonly, permission = true, log = true, logConfig = {}, isHtml = false) {
|
|
227
231
|
let metResponse;
|
|
228
232
|
if (permission) {
|
|
229
233
|
if (this.user && this.user.roles && this.user.roles.length === 0) {
|
|
@@ -270,7 +274,12 @@ class Controller {
|
|
|
270
274
|
xlsx_1.makeXlsx(req, res);
|
|
271
275
|
}
|
|
272
276
|
else {
|
|
273
|
-
|
|
277
|
+
if (isHtml) {
|
|
278
|
+
res.send(metResponse);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
res.json(metResponse);
|
|
282
|
+
}
|
|
274
283
|
}
|
|
275
284
|
}
|
|
276
285
|
async list(params) {
|
|
@@ -327,6 +336,21 @@ class Controller {
|
|
|
327
336
|
await manager.remove(modelInstance);
|
|
328
337
|
return modelInstance;
|
|
329
338
|
}
|
|
339
|
+
getWhereOwnColumns(params, model) {
|
|
340
|
+
const connection = typeorm_1.getConnection(process.env.DB_WRITE_CONNECTION_NAME);
|
|
341
|
+
let ownColumnsForSchema = {};
|
|
342
|
+
const whereOwnColumns = connection.getMetadata(model).ownColumns.reduce((t, column) => {
|
|
343
|
+
if (`_${column.propertyName}` in params) {
|
|
344
|
+
ownColumnsForSchema = Object.assign(Object.assign({}, ownColumnsForSchema), { [`_${column.propertyName}`]: joi_1.default.string() });
|
|
345
|
+
t = Object.assign(Object.assign({}, t), { [column.propertyName]: params[`_${column.propertyName}`] });
|
|
346
|
+
}
|
|
347
|
+
return t;
|
|
348
|
+
}, {});
|
|
349
|
+
return {
|
|
350
|
+
whereOwnColumns,
|
|
351
|
+
ownColumnsForSchema,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
330
354
|
getListParams(params, where) {
|
|
331
355
|
const whereGenericFilter = [];
|
|
332
356
|
if (params.genericFilterFields) {
|
|
@@ -3,6 +3,7 @@ export declare interface ILog {
|
|
|
3
3
|
}
|
|
4
4
|
export declare interface IOptionsRoute {
|
|
5
5
|
readOnly?: boolean;
|
|
6
|
+
isHtml?: boolean;
|
|
6
7
|
dbSettings?: 'Procedure' | 'Orm' | 'Query';
|
|
7
8
|
authentication?: boolean;
|
|
8
9
|
log?: boolean | ILog;
|
|
@@ -17,7 +18,8 @@ declare const Model: (model: string) => ClassDecorator;
|
|
|
17
18
|
declare const StoredProcedure: (storedProcedure: string) => ClassDecorator;
|
|
18
19
|
declare const Authentication: (authentication?: boolean) => (target: any, propertyKey: string) => void;
|
|
19
20
|
declare const ReadOnly: (ronly?: boolean) => (target: any, propertyKey: string) => void;
|
|
21
|
+
declare const IsHtml: (ishtml?: boolean) => (target: any, propertyKey: string) => void;
|
|
20
22
|
declare const DbSettings: (modelType: 'Procedure' | 'Orm' | 'Query') => (target: any, propertyKey: string) => void;
|
|
21
23
|
declare const Permission: (permission?: boolean) => (target: any, propertyKey: string) => void;
|
|
22
24
|
declare const Log: (log?: boolean, config?: Record<string, unknown>) => (target: any, propertyKey: string) => void;
|
|
23
|
-
export { Get, Post, Put, Delete, Patch, Route, Authentication, Log, Permission, DbSettings, ReadOnly, Model, StoredProcedure };
|
|
25
|
+
export { Get, Post, Put, Delete, Patch, Route, Authentication, Log, Permission, DbSettings, ReadOnly, IsHtml, Model, StoredProcedure };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StoredProcedure = exports.Model = exports.ReadOnly = exports.DbSettings = exports.Permission = exports.Log = exports.Authentication = exports.Route = exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
|
3
|
+
exports.StoredProcedure = exports.Model = exports.IsHtml = exports.ReadOnly = exports.DbSettings = exports.Permission = exports.Log = exports.Authentication = exports.Route = exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Kplian Ltda 2020
|
|
6
6
|
*
|
|
@@ -33,6 +33,7 @@ const setProperty = (target, propertyKey) => (value, name, overwrite = true) =>
|
|
|
33
33
|
const createOptions = (options) => (target, propertyKey) => {
|
|
34
34
|
options = Object.assign({
|
|
35
35
|
readOnly: true,
|
|
36
|
+
isHtml: false,
|
|
36
37
|
dbSettings: 'Orm',
|
|
37
38
|
authentication: true,
|
|
38
39
|
log: true
|
|
@@ -100,6 +101,8 @@ const Authentication = (authentication = true) => (target, propertyKey) => setPr
|
|
|
100
101
|
exports.Authentication = Authentication;
|
|
101
102
|
const ReadOnly = (ronly = true) => (target, propertyKey) => setProperty(target, propertyKey)(ronly, 'readonly');
|
|
102
103
|
exports.ReadOnly = ReadOnly;
|
|
104
|
+
const IsHtml = (ishtml = false) => (target, propertyKey) => setProperty(target, propertyKey)(ishtml, 'ishtml');
|
|
105
|
+
exports.IsHtml = IsHtml;
|
|
103
106
|
const DbSettings = (modelType) => (target, propertyKey) => setProperty(target, propertyKey)(modelType, 'dbsettings');
|
|
104
107
|
exports.DbSettings = DbSettings;
|
|
105
108
|
const Permission = (permission = true) => (target, propertyKey) => setProperty(target, propertyKey)(permission, 'permission');
|