Comparing version 1.0.26 to 1.0.27
@@ -7,4 +7,4 @@ import { getMessage, initializei18n } from "./i18n"; | ||
import { ICrudControllerOptions } from "./model/ICrudControllerOptions"; | ||
import { Server, IServerConfig } from "./model/Server"; | ||
import { IServerConfig, Server } from "./model/Server"; | ||
export declare const convertErrorToHttpError: (error: any) => HttpError; | ||
export { Controller, CrudController, IControllerOptions, ICrudControllerOptions, Server, IServerConfig, HttpDispatchDownload, HttpDispatchHandling, getMessage, initializei18n }; | ||
export { Controller, CrudController, HttpDispatchDownload, HttpDispatchHandling, IControllerOptions, ICrudControllerOptions, IServerConfig, Server, getMessage, initializei18n }; |
@@ -6,3 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.initializei18n = exports.getMessage = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.Server = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0; | ||
exports.initializei18n = exports.getMessage = exports.Server = exports.HttpDispatchHandling = exports.HttpDispatchDownload = exports.CrudController = exports.Controller = exports.convertErrorToHttpError = void 0; | ||
const axios_1 = __importDefault(require("axios")); | ||
const express_http_context_1 = __importDefault(require("express-http-context")); | ||
@@ -24,3 +25,2 @@ const http_status_1 = require("http-status"); | ||
Object.defineProperty(exports, "Server", { enumerable: true, get: function () { return Server_1.Server; } }); | ||
const axios_1 = __importDefault(require("axios")); | ||
const convertErrorToHttpError = (error) => { | ||
@@ -27,0 +27,0 @@ if (error instanceof mongodb_1.MongoServerError) { |
@@ -5,6 +5,9 @@ import { Router } from "express"; | ||
routers: Router; | ||
documentation: any; | ||
protected options: IControllerOptions; | ||
constructor(_options: Partial<IControllerOptions>); | ||
BuildDocumentation(): any; | ||
private getMethodsUsed; | ||
} | ||
export declare function HttpDispatchHandling(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor; | ||
export declare function HttpDispatchDownload(target: any, methodName: string, descriptor: PropertyDescriptor): PropertyDescriptor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HttpDispatchDownload = exports.HttpDispatchHandling = exports.Controller = void 0; | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
const c2_util_1 = require("c2-util"); | ||
@@ -9,2 +10,3 @@ const express_1 = require("express"); | ||
routers = (0, express_1.Router)(); | ||
documentation; | ||
options; | ||
@@ -31,2 +33,30 @@ constructor(_options) { | ||
} | ||
// Método para extrair as definições de rota para o OpenApi | ||
BuildDocumentation() { | ||
const paths = {}; | ||
this.routers.stack.forEach((route) => { | ||
if (route.route && route.route.path) { | ||
const methodsUsed = this.getMethodsUsed(route.route.methods); | ||
const methods = {}; | ||
methodsUsed.forEach((method) => { | ||
methods[method] = {}; | ||
}); | ||
paths[route.route.path] = { | ||
...paths[route.route.path], | ||
...methods | ||
}; | ||
} | ||
}); | ||
return paths; | ||
} | ||
; | ||
getMethodsUsed(obj) { | ||
const trueProperties = []; | ||
for (const key in obj) { | ||
if (obj[key] === true) { | ||
trueProperties.push(key); | ||
} | ||
} | ||
return trueProperties; | ||
} | ||
} | ||
@@ -74,1 +104,50 @@ exports.Controller = Controller; | ||
exports.HttpDispatchDownload = HttpDispatchDownload; | ||
// export function CustomDecorator<Controller extends { new (...args: any[]): {} }>(target: Controller) { | ||
// return class extends target { | ||
// constructor(...args: any[]) { | ||
// super(...args); // Chama o construtor da classe original | ||
// // this.initProperty(); // Executa o método que inicializa a propriedade | ||
// this.anotherProperty = "valor da outra propriedade"; // Define outra propriedade | ||
// } | ||
// // initProperty() { | ||
// // if (typeof this.exampleProperty === 'undefined') { | ||
// // this.exampleProperty = "valor inicial da propriedade"; // Inicializa a propriedade | ||
// // } | ||
// // } | ||
// }; | ||
// } | ||
// // Método para extrair as definições de rota para o OpenApi | ||
// export function OpenApi( | ||
// target: any, | ||
// methodName: string, | ||
// descriptor: PropertyDescriptor): any { | ||
// const originalMethod = descriptor.value; | ||
// const getMethodsUsed = (obj: { [key: string]: boolean }): string[] => { | ||
// const trueProperties: string[] = []; | ||
// for (const key in obj) { | ||
// if (obj[key] === true) { | ||
// trueProperties.push(key); | ||
// } | ||
// } | ||
// return trueProperties; | ||
// } | ||
// descriptor.value = async function (...args: any) { | ||
// const controller = args as Controller; | ||
// const paths: { [key: string]: any } = {} | ||
// controller.routers.stack.forEach((route: any) => { | ||
// if (route.route && route.route.path) { | ||
// const methodsUsed = getMethodsUsed(route.route.methods) | ||
// const methods: { [key: string]: any } = {} | ||
// methodsUsed.forEach((method: string) => { | ||
// methods[method] = {} | ||
// }); | ||
// paths[route.route.path] = { | ||
// ...paths[route.route.path], | ||
// ...methods | ||
// } | ||
// } | ||
// }); | ||
// return paths; | ||
// }; | ||
// return descriptor; | ||
// }; |
{ | ||
"name": "c2-http", | ||
"version": "1.0.26", | ||
"version": "1.0.27", | ||
"description": "Biblioteca Typescript para API NodeJS", | ||
@@ -5,0 +5,0 @@ "repository": "https://cabralsilva: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@github.com/cabralsilva/c2-http.git", |
107420
537