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 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);

View File

@ -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;
});
});