From 8267daef3a80304060afe759f91276ac05c20ae3 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 21 Jul 2023 12:58:44 +0200 Subject: [PATCH 1/8] refs #5918 fix: permite reenviar el correo si ha dado fallo --- modules/worker/front/time-control/index.html | 2 ++ modules/worker/front/time-control/index.js | 31 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index 760b0dafc..b6161db2d 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -97,6 +97,8 @@ ng-if="$ctrl.reason && ($ctrl.isHimSelf || $ctrl.isHr)" ng-click="reason.show()"> + + { + if (!res.data.length) { + this.canResend = false; + return; + } + + const filter = { + where: { + workerFk: this.$params.id + }, + include: { + relation: 'department' + } + }; + this.$http.get('WorkerDepartments', {filter}) + .then(res => { + const department = res.data[0].department; + if (department.isTeleworking) this.canResend = true; + }); + }); + } + /** * Worker hours data */ From 1f63648697d585ef03cc18ba77108c14f744ba57 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 24 Aug 2023 09:10:04 +0200 Subject: [PATCH 2/8] =?UTF-8?q?refs=20#5918=20fix:=20muestra=20los=20boton?= =?UTF-8?q?es=20en=20una=20l=C3=ADnea=20y=20no=20carga=20todos=20los=20dat?= =?UTF-8?q?os=20de=20workerTimeControlMail=20de=20la=20semana?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/changes/233601/00-ACL_workerDepartment.sql | 3 +++ modules/worker/front/time-control/index.html | 12 +++++------- modules/worker/front/time-control/index.js | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 db/changes/233601/00-ACL_workerDepartment.sql diff --git a/db/changes/233601/00-ACL_workerDepartment.sql b/db/changes/233601/00-ACL_workerDepartment.sql new file mode 100644 index 000000000..ceb8d5d75 --- /dev/null +++ b/db/changes/233601/00-ACL_workerDepartment.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId) + VALUES + ('WorkerDepartment', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index 307d9a50f..847eb9505 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -79,32 +79,30 @@ - + - - + ng-show="$ctrl.isHr && $ctrl.canResend"> diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index f63a766e8..91f095334 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -117,7 +117,8 @@ class Controller extends Section { where: { year: this._date.getFullYear(), week: this.getWeekNumber(this._date) - } + }, + limit: 1 }; this.$http.get('WorkerTimeControlMails', {filter}) .then(res => { From 9da5c4c1db4d9bff39b578d943406333d33a7625 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 25 Aug 2023 10:04:27 +0200 Subject: [PATCH 3/8] refs #5918 refacotr: cambiado nombre variable --- modules/worker/front/time-control/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 91f095334..88bd2e92a 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -113,21 +113,21 @@ class Controller extends Section { } isMailSended() { - const filter = { + const filterTimeControl = { where: { year: this._date.getFullYear(), week: this.getWeekNumber(this._date) }, limit: 1 }; - this.$http.get('WorkerTimeControlMails', {filter}) + this.$http.get('WorkerTimeControlMails', {filterTimeControl}) .then(res => { if (!res.data.length) { this.canResend = false; return; } - const filter = { + const filterDepartment = { where: { workerFk: this.$params.id }, @@ -135,7 +135,7 @@ class Controller extends Section { relation: 'department' } }; - this.$http.get('WorkerDepartments', {filter}) + this.$http.get('WorkerDepartments', {filterDepartment}) .then(res => { const department = res.data[0].department; if (department.isTeleworking) this.canResend = true; From 45e41de9a9a47ebdc0e75577763795b1f38b24bf Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 3 Oct 2023 14:03:52 +0200 Subject: [PATCH 4/8] refs #5918 fix(worker_time-control): isMailSended --- .../00-ACL_workerDepartment.sql | 0 .../updateWorkerTimeControlMail.js | 16 ++++++++-------- modules/worker/front/time-control/index.js | 11 ++++++----- 3 files changed, 14 insertions(+), 13 deletions(-) rename db/changes/{233601 => 234201}/00-ACL_workerDepartment.sql (100%) diff --git a/db/changes/233601/00-ACL_workerDepartment.sql b/db/changes/234201/00-ACL_workerDepartment.sql similarity index 100% rename from db/changes/233601/00-ACL_workerDepartment.sql rename to db/changes/234201/00-ACL_workerDepartment.sql diff --git a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js index 6fe30de91..e12cf9c59 100644 --- a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js +++ b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js @@ -37,9 +37,8 @@ module.exports = Self => { } }); - Self.updateWorkerTimeControlMail = async(ctx, options) => { + Self.updateWorkerTimeControlMail = async(ctx, workerId, year, week, state, reason, options) => { const models = Self.app.models; - const args = ctx.args; const myOptions = {}; @@ -48,20 +47,21 @@ module.exports = Self => { const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({ where: { - workerFk: args.workerId, - year: args.year, - week: args.week + workerFk: workerId, + year, + week } }, myOptions); + console.log('workerTimeControlMail: ', workerTimeControlMail); if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`); await workerTimeControlMail.updateAttributes({ - state: args.state, - reason: args.reason || null + state, + reason: reason || null }, myOptions); - if (args.state == 'SENDED') { + if (state == 'SENDED') { await workerTimeControlMail.updateAttributes({ sendedCounter: workerTimeControlMail.sendedCounter + 1 }, myOptions); diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 0b427a10d..4bf25886f 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -143,21 +143,22 @@ class Controller extends Section { } isMailSended() { - const filterTimeControl = { + const filter = { where: { year: this._date.getFullYear(), week: this.getWeekNumber(this._date) }, limit: 1 }; - this.$http.get('WorkerTimeControlMails', {filterTimeControl}) + // no repeat request + this.$http.get('WorkerTimeControlMails', {filter}) .then(res => { if (!res.data.length) { this.canResend = false; return; } - const filterDepartment = { + const filter = { where: { workerFk: this.$params.id }, @@ -165,9 +166,9 @@ class Controller extends Section { relation: 'department' } }; - this.$http.get('WorkerDepartments', {filterDepartment}) + this.$http.get('WorkerDepartments/findOne', {filter}) .then(res => { - const department = res.data[0].department; + const department = res.data.department; if (department.isTeleworking) this.canResend = true; }); }); From df6d10e514b4b1a54b382392b32fc6458ef7d2ab Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 4 Oct 2023 12:17:24 +0200 Subject: [PATCH 5/8] refs #5918 fix(workerTimeControl): resend mail --- .../updateWorkerTimeControlMail.js | 37 +++++++---- .../weeklyHourRecordEmail.js | 5 +- modules/worker/front/time-control/index.html | 2 +- modules/worker/front/time-control/index.js | 64 +++++++------------ 4 files changed, 49 insertions(+), 59 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js index e12cf9c59..4e41a5bdd 100644 --- a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js +++ b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js @@ -37,31 +37,40 @@ module.exports = Self => { } }); - Self.updateWorkerTimeControlMail = async(ctx, workerId, year, week, state, reason, options) => { + Self.updateWorkerTimeControlMail = async(ctx, options) => { const models = Self.app.models; - + const args = ctx.args; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({ + const [sent] = await models.WorkerTimeControlMail.find({ where: { - workerFk: workerId, - year, - week - } + year: args.year, + week: args.week, + }, + limit: 1 }, myOptions); - console.log('workerTimeControlMail: ', workerTimeControlMail); - if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`); + if (!sent) throw new UserError(`There aren't records for this week`); - await workerTimeControlMail.updateAttributes({ - state, - reason: reason || null - }, myOptions); + const workerTimeControlMail = await models.WorkerTimeControlMail.upsertWithWhere( + { + year: args.year, + week: args.week, + workerFk: args.workerId + }, + { + state: args.state, + reason: args.workerId, + year: args.year, + week: args.week, + workerFk: args.workerId + }, + myOptions); - if (state == 'SENDED') { + if (args.state == 'SENDED') { await workerTimeControlMail.updateAttributes({ sendedCounter: workerTimeControlMail.sendedCounter + 1 }, myOptions); diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index 3203dea82..816a1d22b 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -61,9 +61,8 @@ module.exports = Self => { const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`; ctx.args.url = url; - await Self.sendTemplate(ctx, 'weekly-hour-record'); - - return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions); + await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions); + return Self.sendTemplate(ctx, 'weekly-hour-record'); }; function getMondayDateFromYearWeek(yearNumber, weekNumber) { diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index 847eb9505..ce8a66356 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -102,7 +102,7 @@ ng-click="sendEmailConfirmation.show()" class="right" vn-tooltip="Resend email of this week to the user" - ng-show="$ctrl.isHr && $ctrl.canResend"> + ng-show="$ctrl.isHr && $ctrl.state != 'CONFIRMED' && $ctrl.canResend"> diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 4bf25886f..9137d7839 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -53,6 +53,8 @@ class Controller extends Section { set worker(value) { this._worker = value; this.fetchHours(); + if (this.date) + this.getWeekData(); } /** @@ -110,8 +112,8 @@ class Controller extends Section { } if (!this.weekTotalHours) this.fetchHours(); - this.getWeekData(); - this.isMailSended(); + if (this.worker) + this.getWeekData(); } set weekTotalHours(totalHours) { @@ -128,21 +130,23 @@ class Controller extends Section { workerFk: this.$params.id, year: this._date.getFullYear(), week: this.getWeekNumber(this._date) - } + }, }; this.$http.get('WorkerTimeControlMails', {filter}) .then(res => { - const mail = res.data; - if (!mail.length) { + if (!res.data.length) { this.state = null; return; } - this.state = mail[0].state; - this.reason = mail[0].reason; + const [mail] = res.data; + this.state = mail.state; + this.reason = mail.reason; }); + this.canBeResend(); } - isMailSended() { + canBeResend() { + this.canResend = false; const filter = { where: { year: this._date.getFullYear(), @@ -150,27 +154,10 @@ class Controller extends Section { }, limit: 1 }; - // no repeat request this.$http.get('WorkerTimeControlMails', {filter}) .then(res => { - if (!res.data.length) { - this.canResend = false; - return; - } - - const filter = { - where: { - workerFk: this.$params.id - }, - include: { - relation: 'department' - } - }; - this.$http.get('WorkerDepartments/findOne', {filter}) - .then(res => { - const department = res.data.department; - if (department.isTeleworking) this.canResend = true; - }); + if (res.data.length) + this.canResend = true; }); } @@ -389,30 +376,25 @@ class Controller extends Section { } isSatisfied() { - const params = { - workerId: this.worker.id, - year: this.date.getFullYear(), - week: this.weekNumber, - state: 'CONFIRMED' - }; - const query = `WorkerTimeControls/updateWorkerTimeControlMail`; - this.$http.post(query, params).then(() => { - this.getMailStates(this.date); - this.getWeekData(); - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + this.updateWorkerTimeControlMail('CONFIRMED'); } isUnsatisfied() { if (!this.reason) throw new UserError(`You must indicate a reason`); + this.updateWorkerTimeControlMail('REVISE', this.reason); + } + updateWorkerTimeControlMail(state, reason) { const params = { workerId: this.worker.id, year: this.date.getFullYear(), week: this.weekNumber, - state: 'REVISE', - reason: this.reason + state }; + + if (reason) + params.reason = reason; + const query = `WorkerTimeControls/updateWorkerTimeControlMail`; this.$http.post(query, params).then(() => { this.getMailStates(this.date); From f8a510b330e6dc331ab986bbc7bfc79ce68530d4 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 4 Oct 2023 12:31:46 +0200 Subject: [PATCH 6/8] refs #5918 fix(workerTimeControl): update(workerTimeControl --- .../methods/worker-time-control/updateWorkerTimeControlMail.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js index 4e41a5bdd..3594f05fe 100644 --- a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js +++ b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js @@ -72,7 +72,7 @@ module.exports = Self => { if (args.state == 'SENDED') { await workerTimeControlMail.updateAttributes({ - sendedCounter: workerTimeControlMail.sendedCounter + 1 + sendedCounter: workerTimeControlMail.sendedCounter ? workerTimeControlMail.sendedCounter + 1 : 1 }, myOptions); } }; From d1cb2a1d9a0ca13861b7c704391a789ebe39db35 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Oct 2023 10:30:36 +0200 Subject: [PATCH 7/8] refs #5918 test: add updateWorkerTimeControlMail --- .../specs/updateWorkerTimeControlMail.spec.js | 103 ++++++++++++++++++ modules/worker/front/time-control/index.html | 6 +- 2 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js diff --git a/modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js b/modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js new file mode 100644 index 000000000..e51021024 --- /dev/null +++ b/modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js @@ -0,0 +1,103 @@ +const models = require('vn-loopback/server/server').models; + +describe('workerTimeControl getMailStates()', () => { + it('should update WorkerTimeControlMail if exist record', async() => { + const tx = await models.WorkerTimeControlMail.beginTransaction({}); + const args = { + workerId: 9, + week: 50, + year: 2000, + state: 'CONFIRMED' + }; + const ctx = {args}; + + try { + const options = {transaction: tx}; + const beforeMail = await models.WorkerTimeControlMail.findOne({ + where: { + workerFk: args.workerId, + year: args.year, + week: args.week, + } + }, options); + await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options); + const afterMail = await models.WorkerTimeControlMail.findOne({ + where: { + workerFk: args.workerId, + year: args.year, + week: args.week, + } + }, options); + + expect(beforeMail.state).toEqual('SENDED'); + expect(afterMail.state).toEqual(args.state); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should insert WorkerTimeControlMail if exist record', async() => { + const tx = await models.WorkerTimeControlMail.beginTransaction({}); + const args = { + workerId: 1, + week: 51, + year: 2000, + state: 'SENDED' + }; + const ctx = {args}; + + try { + const options = {transaction: tx}; + const beforeMail = await models.WorkerTimeControlMail.find({ + where: { + workerFk: args.workerId, + year: args.year, + week: args.week, + } + }, options); + await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options); + const afterMail = await models.WorkerTimeControlMail.find({ + where: { + workerFk: args.workerId, + year: args.year, + week: args.week, + } + }, options); + + expect(beforeMail).toEqual([]); + expect(afterMail.length).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should throw error if not exist any record in this week', async() => { + const tx = await models.WorkerTimeControlMail.beginTransaction({}); + const ctx = {args: { + workerId: 1, + week: 1, + year: 0, + state: 'SENDED' + }}; + + let error; + try { + const options = {transaction: tx}; + await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toEqual(`There aren't records for this week`); + }); +}); + diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index ce8a66356..f147b759b 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -98,11 +98,11 @@ ng-click="reason.show()"> + vn-tooltip="{{$ctrl.state ? 'Resend' : 'Send'}} email of this week to the user" + ng-if="$ctrl.isHr && $ctrl.state != 'CONFIRMED' && $ctrl.canResend"> From 4300b24c1437a7fe78c20e2919da755720eae276 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 18 Oct 2023 10:45:15 +0200 Subject: [PATCH 8/8] refs #5918 refactor(worker_timeControl): simplify ng-show --- .../specs/updateWorkerTimeControlMail.spec.js | 2 +- modules/worker/front/time-control/index.html | 36 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js b/modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js index e51021024..3b5b2b73f 100644 --- a/modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/updateWorkerTimeControlMail.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('workerTimeControl getMailStates()', () => { +describe('updateWorkerTimeControlMail()', () => { it('should update WorkerTimeControlMail if exist record', async() => { const tx = await models.WorkerTimeControlMail.beginTransaction({}); const args = { diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index f147b759b..c34a1e3ca 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -80,23 +80,25 @@ - - - - - - +
+ + + + + + +