fpavon-ee-shared 1.0.44 → 1.0.45
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.js +1 -1
- package/dist/documentos/infrastructure/repository/documentos.ftp.repository.js +42 -52
- package/documentos/application/documentos.useCase.ts +1 -1
- package/documentos/infrastructure/repository/documentos.ftp.repository.ts +52 -63
- package/package.json +1 -1
|
@@ -38,7 +38,7 @@ class DocumentosUseCase {
|
|
|
38
38
|
});
|
|
39
39
|
this.generarPinDeFirmaUseCase = (registrosDeFirma) => __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
// 1. Obtener la lista de PINs que ya están ocupados por el usuario
|
|
41
|
-
const pinsOcupados = yield this.documentosRepository.buscarPinesActivosPorUsuario(registrosDeFirma.
|
|
41
|
+
const pinsOcupados = yield this.documentosRepository.buscarPinesActivosPorUsuario(registrosDeFirma.firmanteUid);
|
|
42
42
|
// 2. Crear una lista de todos los PINs posibles (00 a 99)
|
|
43
43
|
const todosLosPins = [];
|
|
44
44
|
for (let i = 0; i < 100; i++) {
|
|
@@ -176,56 +176,46 @@ class DocumentosFTPRepository {
|
|
|
176
176
|
insertPinDeFirma(pin) {
|
|
177
177
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
178
|
let started = false;
|
|
179
|
+
// NOTA: Usar getDbPool() (Singleton) es lo más recomendable para estabilidad.
|
|
179
180
|
const pool = yield (0, connection_sql_1.getConnectionForTransaction)();
|
|
180
181
|
const transaction = new mssql_1.default.Transaction(pool);
|
|
181
182
|
try {
|
|
182
183
|
yield transaction.begin();
|
|
183
184
|
started = true;
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
@DocumentoUuidFirmado,
|
|
217
|
-
@FirmanteUid,
|
|
218
|
-
@FirmanteNombreCompleto,
|
|
219
|
-
@FirmanteCargo,
|
|
220
|
-
@DatosCertificado,
|
|
221
|
-
@FechaFirma,
|
|
222
|
-
@EsValida,
|
|
223
|
-
@Decision,
|
|
224
|
-
@Comentario,
|
|
225
|
-
@Pin
|
|
226
|
-
)`);
|
|
185
|
+
const request = transaction.request();
|
|
186
|
+
request.input("PIN", mssql_1.default.VarChar(2), pin.PIN);
|
|
187
|
+
request.input("UUID", mssql_1.default.UniqueIdentifier, pin.UUID);
|
|
188
|
+
request.input("CODIGO_INTERNO", mssql_1.default.NVarChar(100), pin.CODIGO_INTERNO);
|
|
189
|
+
request.input("FIRMADO", mssql_1.default.Bit, pin.FIRMADO);
|
|
190
|
+
request.input("UUID_FIRMADO", mssql_1.default.UniqueIdentifier, pin.UUID_FIRMADO);
|
|
191
|
+
request.input("FECHA_FIRMA", mssql_1.default.Date, pin.FECHA_FIRMA);
|
|
192
|
+
request.input("USUARIO", mssql_1.default.VarChar(10), pin.USUARIO);
|
|
193
|
+
// 2. Ejecutar la consulta INSERT adaptada a la nueva tabla
|
|
194
|
+
const insertResult = yield request.query(`
|
|
195
|
+
INSERT INTO dbo.FirmaCertificadoLocal (
|
|
196
|
+
PIN,
|
|
197
|
+
UUID,
|
|
198
|
+
CODIGO_INTERNO,
|
|
199
|
+
FIRMADO,
|
|
200
|
+
UUID_FIRMADO,
|
|
201
|
+
FECHA_FIRMA,
|
|
202
|
+
USUARIO
|
|
203
|
+
)
|
|
204
|
+
VALUES (
|
|
205
|
+
@PIN,
|
|
206
|
+
@UUID,
|
|
207
|
+
@CODIGO_INTERNO,
|
|
208
|
+
@FIRMADO,
|
|
209
|
+
@UUID_FIRMADO,
|
|
210
|
+
@FECHA_FIRMA,
|
|
211
|
+
@USUARIO
|
|
212
|
+
)`);
|
|
213
|
+
// MUY IMPORTANTE: Verifica que la inserción afecte 1 fila.
|
|
214
|
+
if (insertResult.rowsAffected[0] === 0) {
|
|
215
|
+
throw new Error("La inserción del registro de PIN falló (0 filas afectadas).");
|
|
216
|
+
}
|
|
227
217
|
yield transaction.commit();
|
|
228
|
-
return pin;
|
|
218
|
+
return pin; // Devuelve el objeto insertado
|
|
229
219
|
}
|
|
230
220
|
catch (error) {
|
|
231
221
|
if (started) {
|
|
@@ -233,10 +223,10 @@ class DocumentosFTPRepository {
|
|
|
233
223
|
yield transaction.rollback();
|
|
234
224
|
}
|
|
235
225
|
catch (rollbackError) {
|
|
236
|
-
console.error("Error
|
|
226
|
+
console.error("Error en rollback:", rollbackError);
|
|
237
227
|
}
|
|
238
228
|
}
|
|
239
|
-
console.error(`Error DocumentosSqlRepository.insertPinDeFirma
|
|
229
|
+
console.error(`Error DocumentosSqlRepository.insertPinDeFirma (FirmaCertificadoLocal): ${error.message}`);
|
|
240
230
|
throw error;
|
|
241
231
|
}
|
|
242
232
|
});
|
|
@@ -258,13 +248,13 @@ class DocumentosFTPRepository {
|
|
|
258
248
|
started = true;
|
|
259
249
|
const result = yield pool
|
|
260
250
|
.request()
|
|
261
|
-
.input("
|
|
251
|
+
.input("UsuarioUid", mssql_1.default.VarChar(10), firmanteUid)
|
|
262
252
|
.query(`
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
253
|
+
SELECT PIN
|
|
254
|
+
FROM dbo.FirmaCertificadoLocal
|
|
255
|
+
WHERE USUARIO = @UsuarioUid
|
|
256
|
+
AND UUID_FIRMADO IS NULL;
|
|
257
|
+
`);
|
|
268
258
|
yield transaction.commit();
|
|
269
259
|
return result.recordsets[0].map(pin => pin.Pin);
|
|
270
260
|
}
|
|
@@ -41,7 +41,7 @@ export class DocumentosUseCase{
|
|
|
41
41
|
generarPinDeFirmaUseCase = async (registrosDeFirma:any)=>{
|
|
42
42
|
|
|
43
43
|
// 1. Obtener la lista de PINs que ya están ocupados por el usuario
|
|
44
|
-
const pinsOcupados: string[] = await this.documentosRepository.buscarPinesActivosPorUsuario(registrosDeFirma.
|
|
44
|
+
const pinsOcupados: string[] = await this.documentosRepository.buscarPinesActivosPorUsuario(registrosDeFirma.firmanteUid);
|
|
45
45
|
|
|
46
46
|
// 2. Crear una lista de todos los PINs posibles (00 a 99)
|
|
47
47
|
const todosLosPins: string[] = [];
|
|
@@ -169,9 +169,11 @@ export class DocumentosFTPRepository implements IDocumentosRepository{
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
async insertPinDeFirma(pin:any): Promise<IDocumentoFTP>{
|
|
172
|
+
async insertPinDeFirma(pin: any): Promise<IDocumentoFTP> {
|
|
173
173
|
let started = false;
|
|
174
|
-
|
|
174
|
+
|
|
175
|
+
// NOTA: Usar getDbPool() (Singleton) es lo más recomendable para estabilidad.
|
|
176
|
+
const pool = await getConnectionForTransaction();
|
|
175
177
|
|
|
176
178
|
const transaction = new sql.Transaction(pool);
|
|
177
179
|
|
|
@@ -179,68 +181,55 @@ export class DocumentosFTPRepository implements IDocumentosRepository{
|
|
|
179
181
|
await transaction.begin();
|
|
180
182
|
started = true;
|
|
181
183
|
|
|
182
|
-
const
|
|
183
|
-
.request()
|
|
184
|
-
.input("ExpedienteId", sql.Int, pin.ExpedienteId) // int, not null
|
|
185
|
-
.input("DocumentoUuidOriginal", sql.NVarChar(50), pin.DocumentoUuidOriginal) // nvarchar(50), not null
|
|
186
|
-
.input("DocumentoUuidFirmado", sql.NVarChar(50), pin.DocumentoUuidFirmado) // nvarchar(50), null (Debe ser NULL en la inserción inicial)
|
|
187
|
-
.input("FirmanteUid", sql.NVarChar(100), pin.FirmanteUid) // nvarchar(100), not null
|
|
188
|
-
.input("FirmanteNombreCompleto", sql.NVarChar(255), pin.FirmanteNombreCompleto) // nvarchar(255), not null
|
|
189
|
-
.input("FirmanteCargo", sql.NVarChar(255), pin.FirmanteCargo) // nvarchar(255), null
|
|
190
|
-
.input("DatosCertificado", sql.NVarChar(sql.MAX), pin.DatosCertificado) // nvarchar(max), null (Ajusta según tu necesidad, originalmente NOT NULL)
|
|
191
|
-
.input("FechaFirma", sql.DateTime2, pin.FechaFirma) // datetime2(7), not null
|
|
192
|
-
.input("EsValida", sql.Bit, pin.EsValida) // bit, not null (Debe ser 0/false inicialmente)
|
|
193
|
-
.input("Decision", sql.NVarChar(20), pin.Decision) // nvarchar(20), not null ('PENDIENTE' inicialmente)
|
|
194
|
-
.input("Comentario", sql.NVarChar(sql.MAX), pin.Comentario) // nvarchar(max), null
|
|
195
|
-
.input("Pin", sql.Char(2), pin.Pin)
|
|
196
|
-
.query(`
|
|
197
|
-
INSERT INTO dbo.RegistrosDeFirma (
|
|
198
|
-
ExpedienteId,
|
|
199
|
-
DocumentoUuidOriginal,
|
|
200
|
-
DocumentoUuidFirmado,
|
|
201
|
-
FirmanteUid,
|
|
202
|
-
FirmanteNombreCompleto,
|
|
203
|
-
FirmanteCargo,
|
|
204
|
-
DatosCertificado,
|
|
205
|
-
FechaFirma,
|
|
206
|
-
EsValida,
|
|
207
|
-
Decision,
|
|
208
|
-
Comentario,
|
|
209
|
-
Pin
|
|
210
|
-
)
|
|
211
|
-
VALUES (
|
|
212
|
-
@ExpedienteId,
|
|
213
|
-
@DocumentoUuidOriginal,
|
|
214
|
-
@DocumentoUuidFirmado,
|
|
215
|
-
@FirmanteUid,
|
|
216
|
-
@FirmanteNombreCompleto,
|
|
217
|
-
@FirmanteCargo,
|
|
218
|
-
@DatosCertificado,
|
|
219
|
-
@FechaFirma,
|
|
220
|
-
@EsValida,
|
|
221
|
-
@Decision,
|
|
222
|
-
@Comentario,
|
|
223
|
-
@Pin
|
|
224
|
-
)`
|
|
225
|
-
)
|
|
184
|
+
const request = transaction.request();
|
|
226
185
|
|
|
186
|
+
request.input("PIN", sql.VarChar(2), pin.PIN);
|
|
187
|
+
request.input("UUID", sql.UniqueIdentifier, pin.UUID);
|
|
188
|
+
request.input("CODIGO_INTERNO", sql.NVarChar(100), pin.CODIGO_INTERNO);
|
|
189
|
+
|
|
190
|
+
request.input("FIRMADO", sql.Bit, pin.FIRMADO);
|
|
191
|
+
request.input("UUID_FIRMADO", sql.UniqueIdentifier, pin.UUID_FIRMADO);
|
|
192
|
+
request.input("FECHA_FIRMA", sql.Date, pin.FECHA_FIRMA);
|
|
193
|
+
request.input("USUARIO", sql.VarChar(10), pin.USUARIO);
|
|
227
194
|
|
|
195
|
+
// 2. Ejecutar la consulta INSERT adaptada a la nueva tabla
|
|
196
|
+
const insertResult = await request.query(`
|
|
197
|
+
INSERT INTO dbo.FirmaCertificadoLocal (
|
|
198
|
+
PIN,
|
|
199
|
+
UUID,
|
|
200
|
+
CODIGO_INTERNO,
|
|
201
|
+
FIRMADO,
|
|
202
|
+
UUID_FIRMADO,
|
|
203
|
+
FECHA_FIRMA,
|
|
204
|
+
USUARIO
|
|
205
|
+
)
|
|
206
|
+
VALUES (
|
|
207
|
+
@PIN,
|
|
208
|
+
@UUID,
|
|
209
|
+
@CODIGO_INTERNO,
|
|
210
|
+
@FIRMADO,
|
|
211
|
+
@UUID_FIRMADO,
|
|
212
|
+
@FECHA_FIRMA,
|
|
213
|
+
@USUARIO
|
|
214
|
+
)`);
|
|
215
|
+
|
|
216
|
+
// MUY IMPORTANTE: Verifica que la inserción afecte 1 fila.
|
|
217
|
+
if (insertResult.rowsAffected[0] === 0) {
|
|
218
|
+
throw new Error("La inserción del registro de PIN falló (0 filas afectadas).");
|
|
219
|
+
}
|
|
220
|
+
|
|
228
221
|
await transaction.commit();
|
|
229
|
-
return pin;
|
|
222
|
+
return pin; // Devuelve el objeto insertado
|
|
223
|
+
|
|
230
224
|
} catch (error: any) {
|
|
231
225
|
if (started) {
|
|
232
226
|
try {
|
|
233
227
|
await transaction.rollback();
|
|
234
228
|
} catch (rollbackError) {
|
|
235
|
-
console.error(
|
|
236
|
-
|
|
237
|
-
rollbackError
|
|
238
|
-
);
|
|
239
|
-
}
|
|
229
|
+
console.error("Error en rollback:", rollbackError);
|
|
230
|
+
}
|
|
240
231
|
}
|
|
241
|
-
console.error(
|
|
242
|
-
`Error DocumentosSqlRepository.insertPinDeFirma al crear pin: ${error.message}`
|
|
243
|
-
);
|
|
232
|
+
console.error(`Error DocumentosSqlRepository.insertPinDeFirma (FirmaCertificadoLocal): ${error.message}`);
|
|
244
233
|
throw error;
|
|
245
234
|
}
|
|
246
235
|
}
|
|
@@ -262,14 +251,14 @@ export class DocumentosFTPRepository implements IDocumentosRepository{
|
|
|
262
251
|
await transaction.begin();
|
|
263
252
|
started = true;
|
|
264
253
|
const result = await pool
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
254
|
+
.request()
|
|
255
|
+
.input("UsuarioUid", sql.VarChar(10), firmanteUid)
|
|
256
|
+
.query(`
|
|
257
|
+
SELECT PIN
|
|
258
|
+
FROM dbo.FirmaCertificadoLocal
|
|
259
|
+
WHERE USUARIO = @UsuarioUid
|
|
260
|
+
AND UUID_FIRMADO IS NULL;
|
|
261
|
+
`);
|
|
273
262
|
await transaction.commit();
|
|
274
263
|
|
|
275
264
|
return result.recordsets[0].map(pin=>pin.Pin);
|