From 7367d1cdfeb5f5b4ba9114229ced38bd920e70c9 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 27 Jul 2023 14:41:53 +0200 Subject: [PATCH 1/4] refs #6013 fix: add await --- .../back/methods/worker-time-control/weeklyHourRecordEmail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index f44080559..3203dea82 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -51,7 +51,7 @@ module.exports = Self => { const salix = await models.Url.findOne({ where: { appName: 'salix', - environment: process.env.NODE_ENV || 'dev' + environment: process.env.NODE_ENV || 'development' } }, myOptions); @@ -61,7 +61,7 @@ module.exports = Self => { const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; ctx.args.url = url; - Self.sendTemplate(ctx, 'weekly-hour-record'); + await Self.sendTemplate(ctx, 'weekly-hour-record'); return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions); }; From 0054f2d82f04b3a26bbf341be66f499918ee8676 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 27 Jul 2023 15:07:10 +0200 Subject: [PATCH 2/4] refs #6013 fix: codigo no bloqueante --- .../methods/worker-time-control/sendMail.js | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index ab5e56a77..13317fc65 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -121,15 +121,18 @@ module.exports = Self => { `, [started, ended]); stmts.push(stmt); - stmt = new ParameterizedSQL(`INSERT INTO mail (receiver, subject, body) - SELECT CONCAT(u.name, '@verdnatura.es'), - CONCAT('Error registro de horas semana ', ?, ' año ', ?) , - CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) - FROM tmp.timeControlError tce - JOIN vn.workerTimeControl wtc ON wtc.id = tce.id - JOIN worker w ON w.id = wtc.userFK - JOIN account.user u ON u.id = w.bossFk - GROUP BY w.bossFk`, [args.week, args.year]); + stmt = new ParameterizedSQL(` + INSERT INTO mail (receiver, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', ?, ' año ', ?) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', + GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM tmp.timeControlError tce + JOIN vn.workerTimeControl wtc ON wtc.id = tce.id + JOIN worker w ON w.id = wtc.userFK + JOIN account.user u ON u.id = w.bossFk + GROUP BY w.bossFk + `, [args.week, args.year]); stmts.push(stmt); stmt = new ParameterizedSQL(` @@ -176,6 +179,7 @@ module.exports = Self => { const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); + console.log(days[index]); for (let day of days[index]) { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); @@ -371,7 +375,30 @@ module.exports = Self => { } } catch (e) { if (tx) await tx.rollback(); - throw e; + delete myOptions.transaction; + + const stmts = []; + let stmt; + stmt = new ParameterizedSQL(` + INSERT INTO mail (receiver, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', ?, ' año ', ?) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', + GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM worker w + JOIN account.user u ON u.id = w.bossFk + WHERE w.id = ? + GROUP BY w.bossFk + `, [args.week, args.year, day.workerFk]); + stmts.push(stmt); + + const sql = ParameterizedSQL.join(stmts, ';'); + await conn.executeStmt(sql); + + previousWorkerFk = day.workerFk; + previousReceiver = day.receiver; + + continue; } } From 251ed36eca664a9c015bcc15003d49dc39a774cc Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 28 Jul 2023 10:51:48 +0200 Subject: [PATCH 3/4] refs #6013 feat: mostrar error en el mail --- .../back/methods/worker-time-control/sendMail.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 13317fc65..4988d1f46 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -179,7 +179,6 @@ module.exports = Self => { const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); - console.log(days[index]); for (let day of days[index]) { if (!myOptions.transaction) { tx = await Self.beginTransaction({}); @@ -374,22 +373,18 @@ module.exports = Self => { delete myOptions.transaction; } } catch (e) { - if (tx) await tx.rollback(); - delete myOptions.transaction; - const stmts = []; let stmt; stmt = new ParameterizedSQL(` INSERT INTO mail (receiver, subject, body) SELECT CONCAT(u.name, '@verdnatura.es'), CONCAT('Error registro de horas semana ', ?, ' año ', ?) , - CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', - GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + CONCAT('No se ha podido enviar el registro de horas al empleado: ', + w.id, ' ', w.firstName, ' ', w.lastName, ' por el motivo: ', ?) FROM worker w JOIN account.user u ON u.id = w.bossFk WHERE w.id = ? - GROUP BY w.bossFk - `, [args.week, args.year, day.workerFk]); + `, [args.week, args.year, e.message, day.workerFk]); stmts.push(stmt); const sql = ParameterizedSQL.join(stmts, ';'); @@ -398,6 +393,9 @@ module.exports = Self => { previousWorkerFk = day.workerFk; previousReceiver = day.receiver; + if (tx) await tx.rollback(); + delete myOptions.transaction; + continue; } } From beeebbdf9c7522e7f9eaf1519001e815780ba313 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 24 Aug 2023 09:33:58 +0200 Subject: [PATCH 4/4] =?UTF-8?q?refs=20#6013=20refactor:=20siempre=20se=20c?= =?UTF-8?q?rea=20una=20tranacci=C3=B3n=20para=20cada=20dia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/worker-time-control/sendMail.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 4988d1f46..66fb7cc23 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -180,10 +180,8 @@ module.exports = Self => { const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); for (let day of days[index]) { - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; try { workerFk = day.workerFk; if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null @@ -368,10 +366,7 @@ module.exports = Self => { previousReceiver = day.receiver; } - if (tx) { - await tx.commit(); - delete myOptions.transaction; - } + if (tx) await tx.commit(); } catch (e) { const stmts = []; let stmt; @@ -394,7 +389,6 @@ module.exports = Self => { previousReceiver = day.receiver; if (tx) await tx.rollback(); - delete myOptions.transaction; continue; }