fpavon-ee-shared 1.0.57 → 1.0.58

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.
@@ -22,31 +22,31 @@ class ExpedienteElectronicoSqlRepository {
22
22
  getExpedienteById(id) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  try {
25
- let query = `SELECT ee.* from ExpedienteElectronico ee WHERE ee.id=${parseInt(id)}`;
26
- return yield (0, connection_sql_1.getConnection)(query).then((response) => {
27
- if (response.recordset.length > 0) {
28
- let expediente = response.recordset[0];
29
- expediente.bitacora = JSON.parse(expediente.bitacora);
30
- expediente.notas = JSON.parse(expediente.notas);
31
- expediente.documentos = JSON.parse(expediente.documentos);
32
- expediente.documentos.forEach((doc, index) => {
33
- const estadoWorkflow = doc.estadoWorkflow;
34
- const documento = new documento_class_1.Documento(doc.uuid, doc.nombre, doc.descripcion, doc.size, { extras: doc.extras }, doc.firmado, estadoWorkflow);
35
- expediente.documentos[index] = documento;
36
- });
37
- expediente.extras = JSON.parse(expediente.extras);
38
- expediente.usuarioResponsable = JSON.parse(expediente.usuarioResponsable);
39
- expediente.estado = JSON.parse(expediente.estado);
40
- expediente.estado = new estado_class_1.Estado(expediente.estado);
41
- Object.assign(expediente, expediente.extras);
42
- return new expediente_electronico_class_1.ExpedienteElectronico(expediente);
43
- }
44
- else {
45
- if (response.recordset.length == 0) {
46
- throw new Error(`No existe la expediente con id=${id}`);
47
- }
48
- }
25
+ const pool = yield (0, connection_sql_1.getConnectionForTransaction)();
26
+ const result = yield pool
27
+ .request()
28
+ .input("id", mssql_1.default.Int, parseInt(id))
29
+ .query(`
30
+ SELECT ee.*
31
+ FROM ExpedienteElectronico ee
32
+ WHERE ee.id = @id
33
+ `);
34
+ if (!result.recordset.length) {
35
+ throw new Error(`No existe el expediente con id=${id}`);
36
+ }
37
+ let expediente = result.recordset[0];
38
+ expediente.bitacora = JSON.parse(expediente.bitacora);
39
+ expediente.notas = JSON.parse(expediente.notas);
40
+ expediente.documentos = JSON.parse(expediente.documentos);
41
+ expediente.documentos.forEach((doc, index) => {
42
+ const documento = new documento_class_1.Documento(doc.uuid, doc.nombre, doc.descripcion, doc.size, { extras: doc.extras }, doc.firmado, doc.estadoWorkflow);
43
+ expediente.documentos[index] = documento;
49
44
  });
45
+ expediente.extras = JSON.parse(expediente.extras);
46
+ expediente.usuarioResponsable = JSON.parse(expediente.usuarioResponsable);
47
+ expediente.estado = new estado_class_1.Estado(JSON.parse(expediente.estado));
48
+ Object.assign(expediente, expediente.extras);
49
+ return new expediente_electronico_class_1.ExpedienteElectronico(expediente);
50
50
  }
51
51
  catch (error) {
52
52
  console.error("Error expedientesRepository.getExpedienteById=>", error);
@@ -16,40 +16,47 @@ import sql from "mssql";
16
16
  export class ExpedienteElectronicoSqlRepository implements IExpedienteElectronicoRepository {
17
17
  async getExpedienteById(id: string) {
18
18
  try {
19
- let query = `SELECT ee.* from ExpedienteElectronico ee WHERE ee.id=${parseInt(id)}`;
20
- return await getConnection(query).then((response) => {
21
- if (response.recordset.length > 0) {
22
- let expediente = response.recordset[0];
23
- expediente.bitacora = JSON.parse(expediente.bitacora);
24
- expediente.notas = JSON.parse(expediente.notas);
25
- expediente.documentos = JSON.parse(expediente.documentos);
26
- expediente.documentos.forEach((doc, index) => {
27
- const estadoWorkflow = doc.estadoWorkflow;
28
- const documento = new Documento(
29
- doc.uuid,
30
- doc.nombre,
31
- doc.descripcion,
32
- doc.size,
33
- { extras: doc.extras },
34
- doc.firmado,
35
- estadoWorkflow,
36
- );
37
- expediente.documentos[index] = documento;
38
- });
39
- expediente.extras = JSON.parse(expediente.extras);
40
- expediente.usuarioResponsable = JSON.parse(
41
- expediente.usuarioResponsable,
42
- );
43
- expediente.estado = JSON.parse(expediente.estado);
44
- expediente.estado = new Estado(expediente.estado);
45
- Object.assign(expediente, expediente.extras);
46
- return new ExpedienteElectronico(expediente);
47
- } else {
48
- if (response.recordset.length == 0) {
49
- throw new Error(`No existe la expediente con id=${id}`);
50
- }
51
- }
19
+ const pool = await getConnectionForTransaction();
20
+ const result = await pool
21
+ .request()
22
+ .input("id", sql.Int, parseInt(id))
23
+ .query(`
24
+ SELECT ee.*
25
+ FROM ExpedienteElectronico ee
26
+ WHERE ee.id = @id
27
+ `);
28
+
29
+ if (!result.recordset.length) {
30
+ throw new Error(`No existe el expediente con id=${id}`);
31
+ }
32
+
33
+ let expediente = result.recordset[0];
34
+
35
+ expediente.bitacora = JSON.parse(expediente.bitacora);
36
+ expediente.notas = JSON.parse(expediente.notas);
37
+ expediente.documentos = JSON.parse(expediente.documentos);
38
+
39
+ expediente.documentos.forEach((doc, index) => {
40
+ const documento = new Documento(
41
+ doc.uuid,
42
+ doc.nombre,
43
+ doc.descripcion,
44
+ doc.size,
45
+ { extras: doc.extras },
46
+ doc.firmado,
47
+ doc.estadoWorkflow
48
+ );
49
+ expediente.documentos[index] = documento;
52
50
  });
51
+
52
+ expediente.extras = JSON.parse(expediente.extras);
53
+ expediente.usuarioResponsable = JSON.parse(expediente.usuarioResponsable);
54
+ expediente.estado = new Estado(JSON.parse(expediente.estado));
55
+
56
+ Object.assign(expediente, expediente.extras);
57
+
58
+ return new ExpedienteElectronico(expediente);
59
+
53
60
  } catch (error) {
54
61
  console.error("Error expedientesRepository.getExpedienteById=>", error);
55
62
  throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fpavon-ee-shared",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "Carpeta compartida entre servicios de Expediente Electronico",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",