fpavon-ee-shared 1.0.31 → 1.0.33
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.d.ts +9 -0
- package/dist/infrastructure/bd/connection.sql.js +26 -1
- package/dist/infrastructure/middlewares/middleware.auth.js +2 -1
- package/infrastructure/bd/connection.sql.ts +30 -0
- package/infrastructure/middlewares/middleware.auth.ts +4 -4
- package/package.json +1 -1
|
@@ -2,3 +2,12 @@ import sql from 'mssql';
|
|
|
2
2
|
export declare function getConnection(query: string): Promise<any>;
|
|
3
3
|
export declare function executeQuery(query: string, params?: Record<string, any>): Promise<any>;
|
|
4
4
|
export declare function getConnectionForTransaction(): Promise<sql.ConnectionPool>;
|
|
5
|
+
interface SqlParam {
|
|
6
|
+
value: any;
|
|
7
|
+
type: sql.ISqlType | {
|
|
8
|
+
type: sql.ISqlType;
|
|
9
|
+
length?: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export declare function executeQueryWithParams(query: string, params: Record<string, SqlParam>): Promise<any>;
|
|
13
|
+
export {};
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getConnectionForTransaction = exports.executeQuery = exports.getConnection = void 0;
|
|
15
|
+
exports.executeQueryWithParams = exports.getConnectionForTransaction = exports.executeQuery = exports.getConnection = void 0;
|
|
16
16
|
const mssql_1 = __importDefault(require("mssql"));
|
|
17
17
|
function getConfig() {
|
|
18
18
|
return {
|
|
@@ -66,3 +66,28 @@ function getConnectionForTransaction() {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
exports.getConnectionForTransaction = getConnectionForTransaction;
|
|
69
|
+
function executeQueryWithParams(query, params) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const conexion = getConfig();
|
|
72
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
try {
|
|
74
|
+
const pool = yield mssql_1.default.connect(conexion);
|
|
75
|
+
const request = pool.request();
|
|
76
|
+
// Agrega parámetros si se proporcionan
|
|
77
|
+
if (params) {
|
|
78
|
+
Object.entries(params).forEach(([key, param]) => {
|
|
79
|
+
// ¡Corrección clave aquí! -> request.input(nombre, tipo, valor)
|
|
80
|
+
request.input(key, param.type, param.value);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const result = yield request.query(query);
|
|
84
|
+
resolve(result);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error("error BD: ", error);
|
|
88
|
+
reject(error);
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
exports.executeQueryWithParams = executeQueryWithParams;
|
|
@@ -67,7 +67,6 @@ const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, funct
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
let token = bearer[1].replace(/['"]+/g, '');
|
|
70
|
-
console.error("DEBUG: Token extraído:", token);
|
|
71
70
|
const secret = getSecret(); // Asumimos que esta función devuelve el Buffer/String limpio
|
|
72
71
|
// jwt.verify es el principal punto de fallo del token (expiración, firma incorrecta)
|
|
73
72
|
let data;
|
|
@@ -75,11 +74,13 @@ const validarToken = (req, res, next) => __awaiter(void 0, void 0, void 0, funct
|
|
|
75
74
|
data = jwt.verify(token, secret);
|
|
76
75
|
}
|
|
77
76
|
catch (jwtError) {
|
|
77
|
+
console.error("FALLO CRÍTICO: Error de Verificación JWT:", jwtError);
|
|
78
78
|
res.status(401).json({ status: false, mensaje: "token inválido (firma o expiración)" });
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
// Si data.afiliado no existe en el payload
|
|
82
82
|
if (!data || !data.afiliado) {
|
|
83
|
+
console.error("FALLO CRÍTICO: Payload del token incompleto, falta 'afiliado'.");
|
|
83
84
|
res.status(401).json({ status: false, mensaje: "token inválido (datos incompletos)" });
|
|
84
85
|
return;
|
|
85
86
|
}
|
|
@@ -51,3 +51,33 @@ export async function getConnectionForTransaction(): Promise<sql.ConnectionPool>
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
|
|
55
|
+
// Definición de Tipos para los parámetros que recibe la función
|
|
56
|
+
interface SqlParam {
|
|
57
|
+
value: any;
|
|
58
|
+
type: sql.ISqlType | { type: sql.ISqlType, length?: number };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function executeQueryWithParams(query: string, params: Record<string, SqlParam>): Promise<any> {
|
|
62
|
+
const conexion = getConfig();
|
|
63
|
+
return new Promise(async (resolve, reject) => {
|
|
64
|
+
try {
|
|
65
|
+
const pool = await sql.connect(conexion);
|
|
66
|
+
const request = pool.request();
|
|
67
|
+
|
|
68
|
+
// Agrega parámetros si se proporcionan
|
|
69
|
+
if (params) {
|
|
70
|
+
Object.entries(params).forEach(([key, param]) => {
|
|
71
|
+
// ¡Corrección clave aquí! -> request.input(nombre, tipo, valor)
|
|
72
|
+
request.input(key, param.type, param.value);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const result = await request.query(query);
|
|
77
|
+
resolve(result);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error("error BD: ", error);
|
|
80
|
+
reject(error);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
@@ -38,7 +38,7 @@ const validarToken = async (req: Request, res: Response, next: NextFunction): Pr
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
let token = bearer[1].replace(/['"]+/g, '');
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
|
|
43
43
|
const secret = getSecret(); // Asumimos que esta función devuelve el Buffer/String limpio
|
|
44
44
|
|
|
@@ -48,14 +48,14 @@ const validarToken = async (req: Request, res: Response, next: NextFunction): Pr
|
|
|
48
48
|
data = jwt.verify(token, secret);
|
|
49
49
|
|
|
50
50
|
} catch (jwtError) {
|
|
51
|
-
|
|
51
|
+
console.error("FALLO CRÍTICO: Error de Verificación JWT:", jwtError);
|
|
52
52
|
res.status(401).json({ status: false, mensaje: "token inválido (firma o expiración)" });
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// Si data.afiliado no existe en el payload
|
|
57
57
|
if (!data || !data.afiliado) {
|
|
58
|
-
|
|
58
|
+
console.error("FALLO CRÍTICO: Payload del token incompleto, falta 'afiliado'.");
|
|
59
59
|
res.status(401).json({ status: false, mensaje: "token inválido (datos incompletos)" });
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
@@ -66,7 +66,7 @@ const validarToken = async (req: Request, res: Response, next: NextFunction): Pr
|
|
|
66
66
|
|
|
67
67
|
// getConnection es el principal punto de fallo de BD.
|
|
68
68
|
const result = await getConnection(queryVerificar);
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
|
|
71
71
|
if (result.recordset.length === 0) {
|
|
72
72
|
res.status(401).json({ status: false, mensaje: "Usuario no encontrado" });
|