refs #5918 fix(worker_time-control): isMailSended
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-10-03 14:03:52 +02:00
parent 21ddcb7e8e
commit 45e41de9a9
3 changed files with 14 additions and 13 deletions

View File

@ -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 models = Self.app.models;
const args = ctx.args;
const myOptions = {}; const myOptions = {};
@ -48,20 +47,21 @@ module.exports = Self => {
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({ const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
where: { where: {
workerFk: args.workerId, workerFk: workerId,
year: args.year, year,
week: args.week week
} }
}, myOptions); }, myOptions);
console.log('workerTimeControlMail: ', workerTimeControlMail);
if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`); if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`);
await workerTimeControlMail.updateAttributes({ await workerTimeControlMail.updateAttributes({
state: args.state, state,
reason: args.reason || null reason: reason || null
}, myOptions); }, myOptions);
if (args.state == 'SENDED') { if (state == 'SENDED') {
await workerTimeControlMail.updateAttributes({ await workerTimeControlMail.updateAttributes({
sendedCounter: workerTimeControlMail.sendedCounter + 1 sendedCounter: workerTimeControlMail.sendedCounter + 1
}, myOptions); }, myOptions);

View File

@ -143,21 +143,22 @@ class Controller extends Section {
} }
isMailSended() { isMailSended() {
const filterTimeControl = { const filter = {
where: { where: {
year: this._date.getFullYear(), year: this._date.getFullYear(),
week: this.getWeekNumber(this._date) week: this.getWeekNumber(this._date)
}, },
limit: 1 limit: 1
}; };
this.$http.get('WorkerTimeControlMails', {filterTimeControl}) // no repeat request
this.$http.get('WorkerTimeControlMails', {filter})
.then(res => { .then(res => {
if (!res.data.length) { if (!res.data.length) {
this.canResend = false; this.canResend = false;
return; return;
} }
const filterDepartment = { const filter = {
where: { where: {
workerFk: this.$params.id workerFk: this.$params.id
}, },
@ -165,9 +166,9 @@ class Controller extends Section {
relation: 'department' relation: 'department'
} }
}; };
this.$http.get('WorkerDepartments', {filterDepartment}) this.$http.get('WorkerDepartments/findOne', {filter})
.then(res => { .then(res => {
const department = res.data[0].department; const department = res.data.department;
if (department.isTeleworking) this.canResend = true; if (department.isTeleworking) this.canResend = true;
}); });
}); });