@pxp-nd/core 1.2.80 → 1.2.81
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,8 +36,8 @@ 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: 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>;
|
|
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, isFile: 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, isFile?: 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>;
|
|
@@ -127,6 +127,7 @@ class Controller {
|
|
|
127
127
|
const logConfig = Reflect.getMetadata('logConfig', this.constructor) || {};
|
|
128
128
|
// get type return
|
|
129
129
|
let ishtml = Reflect.getMetadata('ishtml', this.constructor) || {};
|
|
130
|
+
let isfile = Reflect.getMetadata('isfile', this.constructor) || {};
|
|
130
131
|
const defaultConfig = Reflect.getMetadata('optionsRoute', this.constructor) || {};
|
|
131
132
|
// define basic routes
|
|
132
133
|
if (this.modelString !== '') {
|
|
@@ -143,6 +144,8 @@ class Controller {
|
|
|
143
144
|
const logKey = typeof logMethod == 'object' ? true : logMethod;
|
|
144
145
|
// is html
|
|
145
146
|
const isHtmlMethod = ishtml[route.methodName] !== undefined ? ishtml[route.methodName] : (defaultConfig[route.methodName] ? defaultConfig[route.methodName].ishtml : false);
|
|
147
|
+
// is file
|
|
148
|
+
const isFileMethod = isfile[route.methodName] !== undefined ? isfile[route.methodName] : (defaultConfig[route.methodName] ? defaultConfig[route.methodName].isfile : false);
|
|
146
149
|
if (readOnlyMethod === null || readOnlyMethod === undefined) {
|
|
147
150
|
throw new index_1.PxpError(500, 'ReadOnly decorator was not defined for ' +
|
|
148
151
|
route.methodName +
|
|
@@ -168,7 +171,7 @@ class Controller {
|
|
|
168
171
|
.toLowerCase();
|
|
169
172
|
this.validated = false;
|
|
170
173
|
try {
|
|
171
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, false, logKey, logValue, isHtmlMethod));
|
|
174
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, false, logKey, logValue, isHtmlMethod, isFileMethod));
|
|
172
175
|
}
|
|
173
176
|
catch (ex) {
|
|
174
177
|
const now = new Date();
|
|
@@ -202,7 +205,7 @@ class Controller {
|
|
|
202
205
|
.toLowerCase();
|
|
203
206
|
this.validated = false;
|
|
204
207
|
try {
|
|
205
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, permission[route.methodName], logKey, logValue, isHtmlMethod));
|
|
208
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, permission[route.methodName], logKey, logValue, isHtmlMethod, isFileMethod));
|
|
206
209
|
}
|
|
207
210
|
catch (ex) {
|
|
208
211
|
const now = new Date();
|
|
@@ -216,9 +219,9 @@ class Controller {
|
|
|
216
219
|
}
|
|
217
220
|
});
|
|
218
221
|
}
|
|
219
|
-
async genericMethodWrapper(params, req, next, res, methodName, dbsettings, readonly, permission = true, log = true, logConfig = {}, isHtml) {
|
|
222
|
+
async genericMethodWrapper(params, req, next, res, methodName, dbsettings, readonly, permission = true, log = true, logConfig = {}, isHtml, isFile) {
|
|
220
223
|
if (dbsettings === 'Orm') {
|
|
221
|
-
await index_1.__(this.ormMethodWrapper(params, req, next, res, methodName, readonly, permission, log, logConfig, isHtml));
|
|
224
|
+
await index_1.__(this.ormMethodWrapper(params, req, next, res, methodName, readonly, permission, log, logConfig, isHtml, isFile));
|
|
222
225
|
}
|
|
223
226
|
else if (dbsettings === 'Procedure') {
|
|
224
227
|
await index_1.__(this.procedureMethodWrapper(params, next, res, methodName, readonly, permission, log, logConfig));
|
|
@@ -227,7 +230,7 @@ class Controller {
|
|
|
227
230
|
await this.sqlMethodWrapper(params, next, res, methodName, readonly, permission, log, logConfig);
|
|
228
231
|
}
|
|
229
232
|
}
|
|
230
|
-
async ormMethodWrapper(params, req, next, res, methodName, readonly, permission = true, log = true, logConfig = {}, isHtml = false) {
|
|
233
|
+
async ormMethodWrapper(params, req, next, res, methodName, readonly, permission = true, log = true, logConfig = {}, isHtml = false, isFile = false) {
|
|
231
234
|
let metResponse;
|
|
232
235
|
if (permission) {
|
|
233
236
|
if (this.user && this.user.roles && this.user.roles.length === 0) {
|
|
@@ -274,9 +277,14 @@ class Controller {
|
|
|
274
277
|
xlsx_1.makeXlsx(req, res);
|
|
275
278
|
}
|
|
276
279
|
else {
|
|
277
|
-
if (isHtml) {
|
|
280
|
+
if (isHtml && !isFile) {
|
|
278
281
|
res.send(metResponse);
|
|
279
282
|
}
|
|
283
|
+
else if (isFile && !isHtml) {
|
|
284
|
+
if (typeof metResponse === "string") {
|
|
285
|
+
res.sendFile(metResponse);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
280
288
|
else {
|
|
281
289
|
res.json(metResponse);
|
|
282
290
|
}
|
|
@@ -301,6 +309,9 @@ class Controller {
|
|
|
301
309
|
}
|
|
302
310
|
return t;
|
|
303
311
|
}, {});
|
|
312
|
+
if (params.fetchOptions) {
|
|
313
|
+
ownColumnsForSchema = Object.assign(Object.assign({}, ownColumnsForSchema), { fetchOptions: joi_1.default.any() });
|
|
314
|
+
}
|
|
304
315
|
const schema = this.getListSchema(ownColumnsForSchema);
|
|
305
316
|
const resParams = await index_1.__(this.schemaValidate(schema, params));
|
|
306
317
|
const listParam = this.getListParams(resParams, whereOwnColumns);
|
|
@@ -360,14 +371,10 @@ class Controller {
|
|
|
360
371
|
whereGenericFilter.push(Object.assign({ [field]: typeorm_1.Like('%' + params.genericFilterValue + '%') }, where));
|
|
361
372
|
});
|
|
362
373
|
}
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
skip: params.start,
|
|
366
|
-
take: params.limit,
|
|
367
|
-
order: {
|
|
374
|
+
const fetchOptions = params.fetchOptions ? JSON.parse(params.fetchOptions) : {};
|
|
375
|
+
const res = Object.assign({ where: whereGenericFilter.length > 0 ? whereGenericFilter : [where], skip: params.start, take: params.limit, order: {
|
|
368
376
|
[params.sort]: String(params.dir).toUpperCase()
|
|
369
|
-
}
|
|
370
|
-
};
|
|
377
|
+
} }, fetchOptions);
|
|
371
378
|
// ffp search if in this request is sending the id
|
|
372
379
|
return res;
|
|
373
380
|
}
|
|
@@ -4,6 +4,7 @@ export declare interface ILog {
|
|
|
4
4
|
export declare interface IOptionsRoute {
|
|
5
5
|
readOnly?: boolean;
|
|
6
6
|
isHtml?: boolean;
|
|
7
|
+
isFile?: boolean;
|
|
7
8
|
dbSettings?: 'Procedure' | 'Orm' | 'Query';
|
|
8
9
|
authentication?: boolean;
|
|
9
10
|
log?: boolean | ILog;
|
|
@@ -19,7 +20,8 @@ declare const StoredProcedure: (storedProcedure: string) => ClassDecorator;
|
|
|
19
20
|
declare const Authentication: (authentication?: boolean) => (target: any, propertyKey: string) => void;
|
|
20
21
|
declare const ReadOnly: (ronly?: boolean) => (target: any, propertyKey: string) => void;
|
|
21
22
|
declare const IsHtml: (ishtml?: boolean) => (target: any, propertyKey: string) => void;
|
|
23
|
+
declare const IsFile: (isFile?: boolean) => (target: any, propertyKey: string) => void;
|
|
22
24
|
declare const DbSettings: (modelType: 'Procedure' | 'Orm' | 'Query') => (target: any, propertyKey: string) => void;
|
|
23
25
|
declare const Permission: (permission?: boolean) => (target: any, propertyKey: string) => void;
|
|
24
26
|
declare const Log: (log?: boolean, config?: Record<string, unknown>) => (target: any, propertyKey: string) => void;
|
|
25
|
-
export { Get, Post, Put, Delete, Patch, Route, Authentication, Log, Permission, DbSettings, ReadOnly, IsHtml, Model, StoredProcedure };
|
|
27
|
+
export { Get, Post, Put, Delete, Patch, Route, Authentication, Log, Permission, DbSettings, ReadOnly, IsHtml, IsFile, Model, StoredProcedure };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.StoredProcedure = exports.Model = exports.IsFile = 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
|
*
|
|
@@ -34,6 +34,7 @@ const createOptions = (options) => (target, propertyKey) => {
|
|
|
34
34
|
options = Object.assign({
|
|
35
35
|
readOnly: true,
|
|
36
36
|
isHtml: false,
|
|
37
|
+
isFile: false,
|
|
37
38
|
dbSettings: 'Orm',
|
|
38
39
|
authentication: true,
|
|
39
40
|
log: true
|
|
@@ -103,6 +104,8 @@ const ReadOnly = (ronly = true) => (target, propertyKey) => setProperty(target,
|
|
|
103
104
|
exports.ReadOnly = ReadOnly;
|
|
104
105
|
const IsHtml = (ishtml = false) => (target, propertyKey) => setProperty(target, propertyKey)(ishtml, 'ishtml');
|
|
105
106
|
exports.IsHtml = IsHtml;
|
|
107
|
+
const IsFile = (isFile = false) => (target, propertyKey) => setProperty(target, propertyKey)(isFile, 'isfile');
|
|
108
|
+
exports.IsFile = IsFile;
|
|
106
109
|
const DbSettings = (modelType) => (target, propertyKey) => setProperty(target, propertyKey)(modelType, 'dbsettings');
|
|
107
110
|
exports.DbSettings = DbSettings;
|
|
108
111
|
const Permission = (permission = true) => (target, propertyKey) => setProperty(target, propertyKey)(permission, 'permission');
|