fpavon-ee-shared 1.0.9 → 1.0.11
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/infrastructure/bd/connection.sql.js +14 -10
- package/dist/infrastructure/middlewares/middleware.auth.d.ts +3 -1
- package/dist/infrastructure/middlewares/middleware.auth.js +10 -1
- package/infrastructure/bd/connection.sql.ts +13 -9
- package/infrastructure/middlewares/middleware.auth.ts +16 -2
- package/package.json +1 -1
|
@@ -14,21 +14,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.getConnectionForTransaction = exports.executeQuery = exports.getConnection = void 0;
|
|
16
16
|
const mssql_1 = __importDefault(require("mssql"));
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
17
|
+
function getConfig() {
|
|
18
|
+
return {
|
|
19
|
+
user: process.env.DBUSER,
|
|
20
|
+
password: process.env.DBPASSWORD,
|
|
21
|
+
server: process.env.DBSERVER || "",
|
|
22
|
+
database: process.env.DBNAME,
|
|
23
|
+
options: {
|
|
24
|
+
encrypt: true,
|
|
25
|
+
trustServerCertificate: true
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
27
29
|
function getConnection(query) {
|
|
28
30
|
return executeQuery(query);
|
|
29
31
|
}
|
|
30
32
|
exports.getConnection = getConnection;
|
|
31
33
|
function executeQuery(query, params) {
|
|
34
|
+
const conexion = getConfig();
|
|
32
35
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
33
36
|
try {
|
|
34
37
|
const pool = yield mssql_1.default.connect(conexion);
|
|
@@ -51,6 +54,7 @@ function executeQuery(query, params) {
|
|
|
51
54
|
exports.executeQuery = executeQuery;
|
|
52
55
|
function getConnectionForTransaction() {
|
|
53
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const conexion = getConfig();
|
|
54
58
|
try {
|
|
55
59
|
const pool = yield mssql_1.default.connect(conexion);
|
|
56
60
|
return pool;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { RequestHandler } from 'express';
|
|
2
|
+
declare const asyncHandlerWrapper: RequestHandler;
|
|
3
|
+
export { asyncHandlerWrapper as validarToken };
|
|
2
4
|
export declare const extraerNivel: (data: any) => number;
|
|
3
5
|
export declare const cifrado: (usuario: any) => Promise<unknown>;
|
|
4
6
|
export declare const descifrarToken: (token: string) => any;
|
|
@@ -16,6 +16,16 @@ exports.obtenerUnidadPadre = exports.unidadesJoinFuncion = exports.getChildrenUn
|
|
|
16
16
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
17
17
|
const connection_sql_1 = require("../bd/connection.sql"); // Asegúrate de ajustar la ruta a tu configuración de base de datos
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
|
+
const asyncHandlerWrapper = (req, res, next) => {
|
|
20
|
+
// Asume que 'fn' es tu función asíncrona original (la que tiene el Promise<void>)
|
|
21
|
+
// Si 'fn' ya está definida en algún lugar, asegúrate de llamarla aquí.
|
|
22
|
+
// Ejemplo si 'fn' fuera el middleware asíncrono original:
|
|
23
|
+
Promise.resolve(validarToken(req, res, next)).catch(next);
|
|
24
|
+
// **Importante**: Si el error persiste, el problema es que la firma de
|
|
25
|
+
// la función envuelta (fn) no es compatible con el RequestHandler que espera Express.
|
|
26
|
+
// La solución más segura es usar una librería conocida de tipos compatibles si es posible.
|
|
27
|
+
};
|
|
28
|
+
exports.validarToken = asyncHandlerWrapper;
|
|
19
29
|
const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
30
|
try {
|
|
21
31
|
const bearerHeader = req.header('Authorization') || "";
|
|
@@ -92,7 +102,6 @@ const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, funct
|
|
|
92
102
|
return; // Terminar ejecución pero sin retornar res
|
|
93
103
|
}
|
|
94
104
|
});
|
|
95
|
-
exports.validarToken = validarToken;
|
|
96
105
|
const extraerNivel = (data) => {
|
|
97
106
|
let nivel = 0;
|
|
98
107
|
data.forEach(element => {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import sql from 'mssql';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
function getConfig(): sql.config {
|
|
4
|
+
return {
|
|
5
|
+
user: process.env.DBUSER,
|
|
6
|
+
password: process.env.DBPASSWORD,
|
|
7
|
+
server: process.env.DBSERVER || "",
|
|
8
|
+
database: process.env.DBNAME,
|
|
9
|
+
options: {
|
|
10
|
+
encrypt: true,
|
|
11
|
+
trustServerCertificate: true
|
|
12
|
+
}
|
|
13
|
+
};
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
export function getConnection(query: string): Promise<any> {
|
|
@@ -16,6 +18,7 @@ export function getConnection(query: string): Promise<any> {
|
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export function executeQuery(query: string, params?: Record<string, any>): Promise<any> {
|
|
21
|
+
const conexion = getConfig();
|
|
19
22
|
return new Promise(async (resolve, reject) => {
|
|
20
23
|
try {
|
|
21
24
|
const pool = await sql.connect(conexion);
|
|
@@ -38,6 +41,7 @@ export function executeQuery(query: string, params?: Record<string, any>): Promi
|
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
export async function getConnectionForTransaction(): Promise<sql.ConnectionPool> {
|
|
44
|
+
const conexion = getConfig();
|
|
41
45
|
try {
|
|
42
46
|
const pool = await sql.connect(conexion);
|
|
43
47
|
return pool;
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from 'express';
|
|
1
|
+
import { Request, Response, NextFunction, RequestHandler } from 'express';
|
|
2
2
|
import jwt from 'jsonwebtoken';
|
|
3
3
|
import { getConnection } from '../bd/connection.sql'; // Asegúrate de ajustar la ruta a tu configuración de base de datos
|
|
4
4
|
import axios from 'axios';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const asyncHandlerWrapper: RequestHandler = (req: Request, res: Response, next: NextFunction) => {
|
|
7
|
+
// Asume que 'fn' es tu función asíncrona original (la que tiene el Promise<void>)
|
|
8
|
+
// Si 'fn' ya está definida en algún lugar, asegúrate de llamarla aquí.
|
|
9
|
+
|
|
10
|
+
// Ejemplo si 'fn' fuera el middleware asíncrono original:
|
|
11
|
+
Promise.resolve(validarToken(req, res, next)).catch(next);
|
|
12
|
+
|
|
13
|
+
// **Importante**: Si el error persiste, el problema es que la firma de
|
|
14
|
+
// la función envuelta (fn) no es compatible con el RequestHandler que espera Express.
|
|
15
|
+
// La solución más segura es usar una librería conocida de tipos compatibles si es posible.
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const validarToken = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
|
|
7
19
|
try {
|
|
8
20
|
const bearerHeader = req.header('Authorization') || "";
|
|
9
21
|
|
|
@@ -90,6 +102,8 @@ export const validarToken = async (req: Request, res: Response, next: NextFuncti
|
|
|
90
102
|
};
|
|
91
103
|
|
|
92
104
|
|
|
105
|
+
export { asyncHandlerWrapper as validarToken };
|
|
106
|
+
|
|
93
107
|
export const extraerNivel = (data)=>{
|
|
94
108
|
let nivel=0;
|
|
95
109
|
data.forEach(element=>{
|