fpavon-ee-shared 1.0.37 → 1.0.39
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/documentos/application/documentos.useCase.d.ts +1 -0
- package/dist/documentos/application/documentos.useCase.js +19 -0
- package/dist/documentos/domain/documento.repository.d.ts +2 -0
- package/dist/documentos/infrastructure/repository/documentos.ftp.repository.d.ts +9 -0
- package/dist/documentos/infrastructure/repository/documentos.ftp.repository.js +96 -0
- package/dist/expediente-electronico/infrastructure/repositories/expediente-electronico.sql.repository.js +55 -31
- package/documentos/application/documentos.useCase.ts +26 -0
- package/documentos/domain/documento.repository.ts +4 -1
- package/documentos/infrastructure/repository/documentos.ftp.repository.ts +107 -0
- package/expediente-electronico/infrastructure/repositories/expediente-electronico.sql.repository.ts +66 -38
- package/package.json +1 -1
|
@@ -8,4 +8,5 @@ export declare class DocumentosUseCase {
|
|
|
8
8
|
crearDocumentoByBuffer: (file: any) => Promise<import("../domain/documentoFTP").IDocumentoFTP>;
|
|
9
9
|
getDocumentoAdjunto: (uuid: string) => Promise<DocumentoFTP>;
|
|
10
10
|
deleteDocumento: (uuid: any) => Promise<Boolean>;
|
|
11
|
+
generarPinDeFirmaUseCase: (usuarioFirmante: string) => Promise<string>;
|
|
11
12
|
}
|
|
@@ -36,6 +36,25 @@ class DocumentosUseCase {
|
|
|
36
36
|
this.deleteDocumento = (uuid) => __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
return yield this.documentosRepository.deleteDocumento(uuid);
|
|
38
38
|
});
|
|
39
|
+
this.generarPinDeFirmaUseCase = (usuarioFirmante) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
// 1. Obtener la lista de PINs que ya están ocupados por el usuario
|
|
41
|
+
const pinsOcupados = yield this.documentosRepository.buscarPinesActivosPorUsuario(usuarioFirmante);
|
|
42
|
+
// 2. Crear una lista de todos los PINs posibles (00 a 99)
|
|
43
|
+
const todosLosPins = [];
|
|
44
|
+
for (let i = 0; i < 100; i++) {
|
|
45
|
+
todosLosPins.push(i.toString().padStart(2, '0'));
|
|
46
|
+
}
|
|
47
|
+
// 3. Determinar los PINs libres (Conjunto de Todos - Conjunto de Ocupados)
|
|
48
|
+
const setOcupados = new Set(pinsOcupados);
|
|
49
|
+
const pinsLibres = todosLosPins.filter(pin => !setOcupados.has(pin));
|
|
50
|
+
// 4. Verificar si hay PINs libres disponibles
|
|
51
|
+
if (pinsLibres.length === 0) {
|
|
52
|
+
throw new Error("El usuario ha ocupado todos los 100 PINs posibles. Debe finalizar una firma para liberar un PIN.");
|
|
53
|
+
}
|
|
54
|
+
// 5. Seleccionar un PIN al azar de la lista de pines libres
|
|
55
|
+
const indiceAleatorio = Math.floor(Math.random() * pinsLibres.length);
|
|
56
|
+
return pinsLibres[indiceAleatorio];
|
|
57
|
+
});
|
|
39
58
|
}
|
|
40
59
|
bufferToStream(buffer) {
|
|
41
60
|
return new stream_1.Readable({
|
|
@@ -8,4 +8,6 @@ export interface IDocumentosRepository {
|
|
|
8
8
|
deleteDocumento(id: any): Promise<Boolean>;
|
|
9
9
|
modifyDocumento(documentoModificado: IDocumentoFTP): Promise<IDocumentoFTP>;
|
|
10
10
|
ver(params: any): any;
|
|
11
|
+
buscarPinesActivosPorUsuario(firmanteUid: string): Promise<any>;
|
|
12
|
+
insertPinDeFirma(pin: any): Promise<IDocumentoFTP>;
|
|
11
13
|
}
|
|
@@ -11,4 +11,13 @@ export declare class DocumentosFTPRepository implements IDocumentosRepository {
|
|
|
11
11
|
deleteDocumento(uuid: any): Promise<Boolean>;
|
|
12
12
|
modifyDocumento(documentoModificado: IDocumentoFTP): Promise<IDocumentoFTP>;
|
|
13
13
|
ver(params: any): Promise<void>;
|
|
14
|
+
insertPinDeFirma(pin: any): Promise<IDocumentoFTP>;
|
|
15
|
+
/**
|
|
16
|
+
* Verifica si un PIN específico ya está activo (DocumentoUuidFirmado IS NULL)
|
|
17
|
+
* para el usuario dado.
|
|
18
|
+
* @param firmanteUid UID del usuario.
|
|
19
|
+
* @param pinGenerado El PIN a verificar (ej. '05').
|
|
20
|
+
* @returns {Promise<IRegistroDeFirma | undefined>} El registro si existe un conflicto, o undefined.
|
|
21
|
+
*/
|
|
22
|
+
buscarPinesActivosPorUsuario(firmanteUid: string): Promise<any>;
|
|
14
23
|
}
|
|
@@ -8,11 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.DocumentosFTPRepository = void 0;
|
|
13
16
|
const fileServer_basic_ftp_1 = require("../../../infrastructure/fileServer/fileServer.basic-ftp");
|
|
14
17
|
const documentoFTP_1 = require("../../domain/documentoFTP");
|
|
15
18
|
const fs_1 = require("fs");
|
|
19
|
+
const connection_sql_1 = require("../../../infrastructure/bd/connection.sql");
|
|
20
|
+
const mssql_1 = __importDefault(require("mssql"));
|
|
16
21
|
class DocumentosFTPRepository {
|
|
17
22
|
constructor(fptClient) {
|
|
18
23
|
this.fptClient = fptClient;
|
|
@@ -168,5 +173,96 @@ class DocumentosFTPRepository {
|
|
|
168
173
|
}
|
|
169
174
|
});
|
|
170
175
|
}
|
|
176
|
+
insertPinDeFirma(pin) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
let started = false;
|
|
179
|
+
const pool = yield (0, connection_sql_1.getConnectionForTransaction)();
|
|
180
|
+
const transaction = new mssql_1.default.Transaction(pool);
|
|
181
|
+
try {
|
|
182
|
+
yield transaction.begin();
|
|
183
|
+
started = true;
|
|
184
|
+
const insertResult = yield transaction
|
|
185
|
+
.request()
|
|
186
|
+
.input("titulo", mssql_1.default.NVarChar, pin.titulo)
|
|
187
|
+
.input("descripcion", mssql_1.default.NVarChar, pin.descripcion)
|
|
188
|
+
.input("tipo", mssql_1.default.NVarChar, pin.tipo)
|
|
189
|
+
.input("bitacora", mssql_1.default.NVarChar, JSON.stringify(pin.bitacora))
|
|
190
|
+
.query(`
|
|
191
|
+
INSERT INTO dbo.RegistrosDeFirma (
|
|
192
|
+
ExpedienteId,
|
|
193
|
+
DocumentoUuidOriginal,
|
|
194
|
+
DocumentoUuidFirmado,
|
|
195
|
+
FirmanteUid,
|
|
196
|
+
FirmanteNombreCompleto,
|
|
197
|
+
FirmanteCargo,
|
|
198
|
+
DatosCertificado,
|
|
199
|
+
FechaFirma,
|
|
200
|
+
EsValida,
|
|
201
|
+
Decision,
|
|
202
|
+
Comentario
|
|
203
|
+
)
|
|
204
|
+
VALUES (
|
|
205
|
+
@ExpedienteId,
|
|
206
|
+
@DocumentoUuidOriginal,
|
|
207
|
+
@DocumentoUuidFirmado,
|
|
208
|
+
@FirmanteUid,
|
|
209
|
+
@FirmanteNombreCompleto,
|
|
210
|
+
@FirmanteCargo,
|
|
211
|
+
@DatosCertificado,
|
|
212
|
+
@FechaFirma,
|
|
213
|
+
@EsValida,
|
|
214
|
+
@Decision,
|
|
215
|
+
@Comentario
|
|
216
|
+
)`);
|
|
217
|
+
yield transaction.commit();
|
|
218
|
+
return pin;
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (started) {
|
|
222
|
+
try {
|
|
223
|
+
yield transaction.rollback();
|
|
224
|
+
}
|
|
225
|
+
catch (rollbackError) {
|
|
226
|
+
console.error("Error DocumentosSqlRepository.insertPinDeFirma durante rollback:", rollbackError);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
console.error(`Error DocumentosSqlRepository.insertPinDeFirma al crear pin: ${error.message}`);
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Verifica si un PIN específico ya está activo (DocumentoUuidFirmado IS NULL)
|
|
236
|
+
* para el usuario dado.
|
|
237
|
+
* @param firmanteUid UID del usuario.
|
|
238
|
+
* @param pinGenerado El PIN a verificar (ej. '05').
|
|
239
|
+
* @returns {Promise<IRegistroDeFirma | undefined>} El registro si existe un conflicto, o undefined.
|
|
240
|
+
*/
|
|
241
|
+
buscarPinesActivosPorUsuario(firmanteUid) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
const pool = yield (0, connection_sql_1.getConnectionForTransaction)();
|
|
244
|
+
const transaction = new mssql_1.default.Transaction(pool);
|
|
245
|
+
let started = false;
|
|
246
|
+
try {
|
|
247
|
+
yield transaction.begin();
|
|
248
|
+
started = true;
|
|
249
|
+
const result = yield pool
|
|
250
|
+
.request()
|
|
251
|
+
.input("FirmanteUid", mssql_1.default.NVarChar(100), firmanteUid)
|
|
252
|
+
.query(`
|
|
253
|
+
SELECT Pin
|
|
254
|
+
FROM dbo.RegistrosDeFirma
|
|
255
|
+
WHERE FirmanteUid = @FirmanteUid
|
|
256
|
+
AND DocumentoUuidFirmado IS NULL;
|
|
257
|
+
`);
|
|
258
|
+
yield transaction.commit();
|
|
259
|
+
return result.recordset[0];
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
console.error("Error DocumentosSqlRepository.buscarPinActivoPorUsuario:", error);
|
|
263
|
+
throw new Error("Error al consultar la unicidad del PIN.");
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
171
267
|
}
|
|
172
268
|
exports.DocumentosFTPRepository = DocumentosFTPRepository;
|
|
@@ -8,12 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.ExpedienteElectronicoSqlRepository = void 0;
|
|
13
16
|
const connection_sql_1 = require("../../../infrastructure/bd/connection.sql");
|
|
14
17
|
const estado_class_1 = require("../../../estados/domain/estado.class");
|
|
15
18
|
const expediente_electronico_class_1 = require("../../domain/expediente-electronico.class");
|
|
16
19
|
const documento_class_1 = require("../../../documentos/domain/documento.class");
|
|
20
|
+
const mssql_1 = __importDefault(require("mssql"));
|
|
17
21
|
class ExpedienteElectronicoSqlRepository {
|
|
18
22
|
getExpedienteById(id) {
|
|
19
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -87,39 +91,59 @@ class ExpedienteElectronicoSqlRepository {
|
|
|
87
91
|
}
|
|
88
92
|
updateEstado(id, expediente) {
|
|
89
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
// Definición de parámetros para el UPDATE
|
|
95
|
+
const paramsUpdate = {
|
|
96
|
+
'id': { value: id, type: mssql_1.default.Int },
|
|
97
|
+
'estado': { value: JSON.stringify(expediente.getEstado()), type: mssql_1.default.NVarChar(mssql_1.default.MAX) },
|
|
98
|
+
'bitacora': { value: JSON.stringify(expediente.bitacora), type: mssql_1.default.NVarChar(mssql_1.default.MAX) },
|
|
99
|
+
'notas': { value: JSON.stringify(expediente.notas), type: mssql_1.default.NVarChar(mssql_1.default.MAX) },
|
|
100
|
+
'extras': { value: JSON.stringify(expediente.getAtributos()), type: mssql_1.default.NVarChar(mssql_1.default.MAX) },
|
|
101
|
+
'destino': { value: expediente.destino, type: mssql_1.default.NVarChar(100) }
|
|
102
|
+
};
|
|
103
|
+
const queryUpdate = `
|
|
104
|
+
UPDATE ExpedienteElectronico
|
|
105
|
+
SET
|
|
106
|
+
estado = @estado,
|
|
107
|
+
bitacora = @bitacora,
|
|
108
|
+
notas = @notas,
|
|
109
|
+
extras = @extras,
|
|
110
|
+
destino = @destino,
|
|
111
|
+
fechaModificacion = SYSDATETIME()
|
|
112
|
+
WHERE id = @id;
|
|
113
|
+
`;
|
|
114
|
+
// Ejecutar el UPDATE
|
|
115
|
+
yield (0, connection_sql_1.executeQueryWithParams)(queryUpdate, paramsUpdate);
|
|
116
|
+
// Definición de parámetros para el SELECT
|
|
117
|
+
const paramsSelect = {
|
|
118
|
+
'id': { value: id, type: mssql_1.default.Int }
|
|
119
|
+
};
|
|
120
|
+
const querySelect = `SELECT * FROM ExpedienteElectronico WHERE id = @id`;
|
|
96
121
|
// Ejecuta la consulta de selección y devuelve el expediente actualizado
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return expedienteActualizado;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
console.error(e);
|
|
120
|
-
throw new Error("Expediente no encontrado después de la actualización");
|
|
122
|
+
const response = yield (0, connection_sql_1.executeQueryWithParams)(querySelect, paramsSelect);
|
|
123
|
+
try {
|
|
124
|
+
if (response && response.recordset.length > 0) {
|
|
125
|
+
const ee = response.recordset[0];
|
|
126
|
+
ee.documentos = JSON.parse(ee.documentos);
|
|
127
|
+
ee.documentos.forEach((doc, index) => {
|
|
128
|
+
const estadoWorkflow = doc.estadoWorkflow;
|
|
129
|
+
const documento = new documento_class_1.Documento(doc.uuid, doc.nombre, doc.descripcion, doc.size, { extras: doc.extras }, doc.firmado, estadoWorkflow);
|
|
130
|
+
ee.documentos[index] = documento;
|
|
131
|
+
});
|
|
132
|
+
ee.extras = JSON.parse(ee.extras);
|
|
133
|
+
ee.usuarioResponsable = JSON.parse(ee.usuarioResponsable);
|
|
134
|
+
ee.estado = JSON.parse(ee.estado);
|
|
135
|
+
ee.estado = new estado_class_1.Estado(ee.estado);
|
|
136
|
+
ee.bitacora = JSON.parse(ee.bitacora);
|
|
137
|
+
ee.notas = JSON.parse(ee.notas);
|
|
138
|
+
Object.assign(ee, ee.extras);
|
|
139
|
+
return new expediente_electronico_class_1.ExpedienteElectronico(ee);
|
|
121
140
|
}
|
|
122
|
-
|
|
141
|
+
throw new Error("Expediente no encontrado después de la actualización");
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
console.error(e);
|
|
145
|
+
throw new Error("Expediente no encontrado después de la actualización");
|
|
146
|
+
}
|
|
123
147
|
});
|
|
124
148
|
}
|
|
125
149
|
updateExpediente(id, expediente) {
|
|
@@ -38,4 +38,30 @@ export class DocumentosUseCase{
|
|
|
38
38
|
return await this.documentosRepository.deleteDocumento(uuid)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
generarPinDeFirmaUseCase = async (usuarioFirmante:string)=>{
|
|
42
|
+
|
|
43
|
+
// 1. Obtener la lista de PINs que ya están ocupados por el usuario
|
|
44
|
+
const pinsOcupados: string[] = await this.documentosRepository.buscarPinesActivosPorUsuario(usuarioFirmante);
|
|
45
|
+
|
|
46
|
+
// 2. Crear una lista de todos los PINs posibles (00 a 99)
|
|
47
|
+
const todosLosPins: string[] = [];
|
|
48
|
+
for (let i = 0; i < 100; i++) {
|
|
49
|
+
todosLosPins.push(i.toString().padStart(2, '0'));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 3. Determinar los PINs libres (Conjunto de Todos - Conjunto de Ocupados)
|
|
53
|
+
const setOcupados = new Set(pinsOcupados);
|
|
54
|
+
const pinsLibres = todosLosPins.filter(pin => !setOcupados.has(pin));
|
|
55
|
+
|
|
56
|
+
// 4. Verificar si hay PINs libres disponibles
|
|
57
|
+
if (pinsLibres.length === 0) {
|
|
58
|
+
throw new Error("El usuario ha ocupado todos los 100 PINs posibles. Debe finalizar una firma para liberar un PIN.");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 5. Seleccionar un PIN al azar de la lista de pines libres
|
|
62
|
+
const indiceAleatorio = Math.floor(Math.random() * pinsLibres.length);
|
|
63
|
+
|
|
64
|
+
return pinsLibres[indiceAleatorio];
|
|
65
|
+
}
|
|
66
|
+
|
|
41
67
|
}
|
|
@@ -8,5 +8,8 @@ export interface IDocumentosRepository {
|
|
|
8
8
|
getDocumentoById(id):Promise<IDocumentoFTP>;
|
|
9
9
|
deleteDocumento(id):Promise<Boolean>;
|
|
10
10
|
modifyDocumento(documentoModificado: IDocumentoFTP):Promise<IDocumentoFTP>;
|
|
11
|
-
ver(params):any
|
|
11
|
+
ver(params):any;
|
|
12
|
+
buscarPinesActivosPorUsuario(firmanteUid: string): Promise<any>;
|
|
13
|
+
insertPinDeFirma(pin:any): Promise<IDocumentoFTP>;
|
|
14
|
+
|
|
12
15
|
}
|
|
@@ -4,6 +4,9 @@ import { FtpConnection } from "../../../infrastructure/fileServer/fileServer.bas
|
|
|
4
4
|
import { IDocumentosRepository } from "../../domain/documento.repository";
|
|
5
5
|
import { DocumentoFTP, IDocumentoFTP } from "../../domain/documentoFTP";
|
|
6
6
|
import { createReadStream } from "fs";
|
|
7
|
+
import { getConnectionForTransaction } from "../../../infrastructure/bd/connection.sql";
|
|
8
|
+
import sql from "mssql";
|
|
9
|
+
|
|
7
10
|
|
|
8
11
|
export class DocumentosFTPRepository implements IDocumentosRepository{
|
|
9
12
|
constructor(private fptClient:FtpConnection){}
|
|
@@ -166,4 +169,108 @@ export class DocumentosFTPRepository implements IDocumentosRepository{
|
|
|
166
169
|
}
|
|
167
170
|
}
|
|
168
171
|
|
|
172
|
+
async insertPinDeFirma(pin:any): Promise<IDocumentoFTP>{
|
|
173
|
+
let started = false;
|
|
174
|
+
const pool = await getConnectionForTransaction();
|
|
175
|
+
|
|
176
|
+
const transaction = new sql.Transaction(pool);
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
await transaction.begin();
|
|
180
|
+
started = true;
|
|
181
|
+
|
|
182
|
+
const insertResult = await transaction
|
|
183
|
+
.request()
|
|
184
|
+
.input("titulo", sql.NVarChar, pin.titulo)
|
|
185
|
+
.input("descripcion", sql.NVarChar, pin.descripcion)
|
|
186
|
+
.input("tipo", sql.NVarChar, pin.tipo)
|
|
187
|
+
.input("bitacora", sql.NVarChar, JSON.stringify(pin.bitacora))
|
|
188
|
+
.query(`
|
|
189
|
+
INSERT INTO dbo.RegistrosDeFirma (
|
|
190
|
+
ExpedienteId,
|
|
191
|
+
DocumentoUuidOriginal,
|
|
192
|
+
DocumentoUuidFirmado,
|
|
193
|
+
FirmanteUid,
|
|
194
|
+
FirmanteNombreCompleto,
|
|
195
|
+
FirmanteCargo,
|
|
196
|
+
DatosCertificado,
|
|
197
|
+
FechaFirma,
|
|
198
|
+
EsValida,
|
|
199
|
+
Decision,
|
|
200
|
+
Comentario
|
|
201
|
+
)
|
|
202
|
+
VALUES (
|
|
203
|
+
@ExpedienteId,
|
|
204
|
+
@DocumentoUuidOriginal,
|
|
205
|
+
@DocumentoUuidFirmado,
|
|
206
|
+
@FirmanteUid,
|
|
207
|
+
@FirmanteNombreCompleto,
|
|
208
|
+
@FirmanteCargo,
|
|
209
|
+
@DatosCertificado,
|
|
210
|
+
@FechaFirma,
|
|
211
|
+
@EsValida,
|
|
212
|
+
@Decision,
|
|
213
|
+
@Comentario
|
|
214
|
+
)`
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
await transaction.commit();
|
|
219
|
+
return pin;
|
|
220
|
+
} catch (error: any) {
|
|
221
|
+
if (started) {
|
|
222
|
+
try {
|
|
223
|
+
await transaction.rollback();
|
|
224
|
+
} catch (rollbackError) {
|
|
225
|
+
console.error(
|
|
226
|
+
"Error DocumentosSqlRepository.insertPinDeFirma durante rollback:",
|
|
227
|
+
rollbackError
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
console.error(
|
|
232
|
+
`Error DocumentosSqlRepository.insertPinDeFirma al crear pin: ${error.message}`
|
|
233
|
+
);
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Verifica si un PIN específico ya está activo (DocumentoUuidFirmado IS NULL)
|
|
240
|
+
* para el usuario dado.
|
|
241
|
+
* @param firmanteUid UID del usuario.
|
|
242
|
+
* @param pinGenerado El PIN a verificar (ej. '05').
|
|
243
|
+
* @returns {Promise<IRegistroDeFirma | undefined>} El registro si existe un conflicto, o undefined.
|
|
244
|
+
*/
|
|
245
|
+
public async buscarPinesActivosPorUsuario(
|
|
246
|
+
firmanteUid: string
|
|
247
|
+
): Promise<any> {
|
|
248
|
+
const pool = await getConnectionForTransaction();
|
|
249
|
+
const transaction = new sql.Transaction(pool);
|
|
250
|
+
let started = false;
|
|
251
|
+
try {
|
|
252
|
+
await transaction.begin();
|
|
253
|
+
started = true;
|
|
254
|
+
const result = await pool
|
|
255
|
+
.request()
|
|
256
|
+
.input("FirmanteUid", sql.NVarChar(100), firmanteUid)
|
|
257
|
+
.query(`
|
|
258
|
+
SELECT Pin
|
|
259
|
+
FROM dbo.RegistrosDeFirma
|
|
260
|
+
WHERE FirmanteUid = @FirmanteUid
|
|
261
|
+
AND DocumentoUuidFirmado IS NULL;
|
|
262
|
+
`);
|
|
263
|
+
await transaction.commit();
|
|
264
|
+
|
|
265
|
+
return result.recordset[0];
|
|
266
|
+
|
|
267
|
+
} catch (error: any) {
|
|
268
|
+
console.error(
|
|
269
|
+
"Error DocumentosSqlRepository.buscarPinActivoPorUsuario:",
|
|
270
|
+
error
|
|
271
|
+
);
|
|
272
|
+
throw new Error("Error al consultar la unicidad del PIN.");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
169
276
|
}
|
package/expediente-electronico/infrastructure/repositories/expediente-electronico.sql.repository.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { getConnection } from "../../../infrastructure/bd/connection.sql"
|
|
1
|
+
import { executeQueryWithParams, getConnection } from "../../../infrastructure/bd/connection.sql"
|
|
2
2
|
import { Estado } from "../../../estados/domain/estado.class";
|
|
3
3
|
import { ExpedienteElectronico } from "../../domain/expediente-electronico.class";
|
|
4
4
|
import { IExpedienteElectronicoRepository } from "../../domain/expediente-electronico.repository";
|
|
5
5
|
import { IExpedienteElectronico } from "../../domain/expediente-electronico.interface";
|
|
6
6
|
import { Documento, ImplementacionWorkflow } from "../../../documentos/domain/documento.class";
|
|
7
|
-
|
|
7
|
+
import sql from 'mssql';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
export class ExpedienteElectronicoSqlRepository implements IExpedienteElectronicoRepository{
|
|
@@ -93,45 +93,73 @@ export class ExpedienteElectronicoSqlRepository implements IExpedienteElectronic
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async updateEstado(id: any, expediente:ExpedienteElectronico): Promise<ExpedienteElectronico> {
|
|
97
|
-
let queryUpdate = `UPDATE ExpedienteElectronico SET estado = '${JSON.stringify(expediente.getEstado())}', bitacora = '${JSON.stringify(expediente.bitacora)}',
|
|
98
|
-
notas = '${JSON.stringify(expediente.notas)}', extras= '${JSON.stringify(expediente.getAtributos())}', destino= '${expediente.destino}'`
|
|
99
|
-
|
|
100
|
-
queryUpdate += `WHERE id = '${id}'`
|
|
101
|
-
// console.log("QUERY UPDATE ESTADO: ", queryUpdate)
|
|
102
|
-
await getConnection(queryUpdate);
|
|
103
|
-
|
|
104
|
-
let querySelect = `SELECT * FROM ExpedienteElectronico WHERE id=${id}`;
|
|
96
|
+
async updateEstado(id: any, expediente: ExpedienteElectronico): Promise<ExpedienteElectronico> {
|
|
105
97
|
|
|
98
|
+
// Definición de parámetros para el UPDATE
|
|
99
|
+
const paramsUpdate = {
|
|
100
|
+
'id': { value: id, type: sql.Int },
|
|
101
|
+
'estado': { value: JSON.stringify(expediente.getEstado()), type: sql.NVarChar(sql.MAX) },
|
|
102
|
+
'bitacora': { value: JSON.stringify(expediente.bitacora), type: sql.NVarChar(sql.MAX) },
|
|
103
|
+
'notas': { value: JSON.stringify(expediente.notas), type: sql.NVarChar(sql.MAX) },
|
|
104
|
+
'extras': { value: JSON.stringify(expediente.getAtributos()), type: sql.NVarChar(sql.MAX) },
|
|
105
|
+
'destino': { value: expediente.destino, type: sql.NVarChar(100) }
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const queryUpdate = `
|
|
109
|
+
UPDATE ExpedienteElectronico
|
|
110
|
+
SET
|
|
111
|
+
estado = @estado,
|
|
112
|
+
bitacora = @bitacora,
|
|
113
|
+
notas = @notas,
|
|
114
|
+
extras = @extras,
|
|
115
|
+
destino = @destino,
|
|
116
|
+
fechaModificacion = SYSDATETIME()
|
|
117
|
+
WHERE id = @id;
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
// Ejecutar el UPDATE
|
|
121
|
+
await executeQueryWithParams(queryUpdate, paramsUpdate);
|
|
122
|
+
|
|
123
|
+
// Definición de parámetros para el SELECT
|
|
124
|
+
const paramsSelect = {
|
|
125
|
+
'id': { value: id, type: sql.Int }
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const querySelect = `SELECT * FROM ExpedienteElectronico WHERE id = @id`;
|
|
129
|
+
|
|
106
130
|
// Ejecuta la consulta de selección y devuelve el expediente actualizado
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
ee.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
const response = await executeQueryWithParams(querySelect, paramsSelect);
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
if (response && response.recordset.length > 0) {
|
|
135
|
+
const ee = response.recordset[0];
|
|
136
|
+
ee.documentos = JSON.parse(ee.documentos);
|
|
137
|
+
|
|
138
|
+
ee.documentos.forEach((doc, index) => {
|
|
139
|
+
const estadoWorkflow = doc.estadoWorkflow;
|
|
140
|
+
const documento = new Documento(
|
|
141
|
+
doc.uuid, doc.nombre, doc.descripcion, doc.size,
|
|
142
|
+
{ extras: doc.extras }, doc.firmado, estadoWorkflow
|
|
143
|
+
);
|
|
144
|
+
ee.documentos[index] = documento;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
ee.extras = JSON.parse(ee.extras);
|
|
148
|
+
ee.usuarioResponsable = JSON.parse(ee.usuarioResponsable);
|
|
149
|
+
ee.estado = JSON.parse(ee.estado);
|
|
150
|
+
ee.estado = new Estado(ee.estado);
|
|
151
|
+
ee.bitacora = JSON.parse(ee.bitacora);
|
|
152
|
+
ee.notas = JSON.parse(ee.notas);
|
|
153
|
+
Object.assign(ee, ee.extras);
|
|
154
|
+
|
|
155
|
+
return new ExpedienteElectronico(ee);
|
|
133
156
|
}
|
|
134
|
-
|
|
157
|
+
|
|
158
|
+
throw new Error("Expediente no encontrado después de la actualización");
|
|
159
|
+
} catch (e) {
|
|
160
|
+
console.error(e);
|
|
161
|
+
throw new Error("Expediente no encontrado después de la actualización");
|
|
162
|
+
}
|
|
135
163
|
}
|
|
136
164
|
|
|
137
165
|
async updateExpediente(id: any, expediente:ExpedienteElectronico): Promise<ExpedienteElectronico> {
|