5918-worker.time-control_resend #1685
|
@ -0,0 +1,3 @@
|
||||||
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES
|
||||||
|
('WorkerDepartment', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -0,0 +1,103 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('updateWorkerTimeControlMail()', () => {
|
||||||
|
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`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -40,30 +40,39 @@ module.exports = Self => {
|
||||||
Self.updateWorkerTimeControlMail = async(ctx, options) => {
|
Self.updateWorkerTimeControlMail = async(ctx, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
const [sent] = await models.WorkerTimeControlMail.find({
|
||||||
where: {
|
where: {
|
||||||
workerFk: args.workerId,
|
|
||||||
year: args.year,
|
year: args.year,
|
||||||
week: args.week
|
week: args.week,
|
||||||
}
|
},
|
||||||
|
limit: 1
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
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({
|
const workerTimeControlMail = await models.WorkerTimeControlMail.upsertWithWhere(
|
||||||
state: args.state,
|
{
|
||||||
reason: args.reason || null
|
year: args.year,
|
||||||
}, myOptions);
|
week: args.week,
|
||||||
|
workerFk: args.workerId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
state: args.state,
|
||||||
|
reason: args.workerId,
|
||||||
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
workerFk: args.workerId
|
||||||
|
},
|
||||||
|
myOptions);
|
||||||
|
|
||||||
if (args.state == 'SENDED') {
|
if (args.state == 'SENDED') {
|
||||||
await workerTimeControlMail.updateAttributes({
|
await workerTimeControlMail.updateAttributes({
|
||||||
sendedCounter: workerTimeControlMail.sendedCounter + 1
|
sendedCounter: workerTimeControlMail.sendedCounter ? workerTimeControlMail.sendedCounter + 1 : 1
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,9 +61,8 @@ module.exports = Self => {
|
||||||
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
||||||
ctx.args.url = url;
|
ctx.args.url = url;
|
||||||
|
|
||||||
await Self.sendTemplate(ctx, 'weekly-hour-record');
|
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
||||||
|
return Self.sendTemplate(ctx, 'weekly-hour-record');
|
||||||
return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
||||||
|
|
|
@ -79,30 +79,32 @@
|
||||||
</vn-table>
|
</vn-table>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
|
|
||||||
<vn-button-bar ng-show="$ctrl.state" class="vn-w-lg">
|
<vn-button-bar class="vn-w-lg">
|
||||||
|
<div ng-show="$ctrl.state">
|
||||||
|
<vn-button
|
||||||
|
label="Satisfied"
|
||||||
|
disabled="$ctrl.state == 'CONFIRMED'"
|
||||||
|
ng-show="$ctrl.isHimSelf"
|
||||||
|
ng-click="$ctrl.isSatisfied()">
|
||||||
|
</vn-button>
|
||||||
|
<vn-button
|
||||||
|
label="Not satisfied"
|
||||||
|
disabled="$ctrl.state == 'REVISE'"
|
||||||
|
ng-show="$ctrl.isHimSelf"
|
||||||
|
ng-click="reason.show()">
|
||||||
|
</vn-button>
|
||||||
|
<vn-button
|
||||||
|
label="Reason"
|
||||||
|
ng-show="$ctrl.reason && ($ctrl.isHimSelf || $ctrl.isHr)"
|
||||||
|
ng-click="reason.show()">
|
||||||
|
</vn-button>
|
||||||
|
</div>
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Satisfied"
|
label="{{$ctrl.state ? 'Resend' : 'Send'}}"
|
||||||
disabled="$ctrl.state == 'CONFIRMED'"
|
|
||||||
ng-if="$ctrl.isHimSelf"
|
|
||||||
ng-click="$ctrl.isSatisfied()">
|
|
||||||
</vn-button>
|
|
||||||
<vn-button
|
|
||||||
label="Not satisfied"
|
|
||||||
disabled="$ctrl.state == 'REVISE'"
|
|
||||||
ng-if="$ctrl.isHimSelf"
|
|
||||||
ng-click="reason.show()">
|
|
||||||
</vn-button>
|
|
||||||
<vn-button
|
|
||||||
label="Reason"
|
|
||||||
ng-if="$ctrl.reason && ($ctrl.isHimSelf || $ctrl.isHr)"
|
|
||||||
ng-click="reason.show()">
|
|
||||||
</vn-button>
|
|
||||||
<vn-button
|
|
||||||
label="Resend"
|
|
||||||
ng-click="sendEmailConfirmation.show()"
|
ng-click="sendEmailConfirmation.show()"
|
||||||
class="right"
|
class="right"
|
||||||
vn-tooltip="Resend email of this week to the user"
|
vn-tooltip="{{$ctrl.state ? 'Resend' : 'Send'}} email of this week to the user"
|
||||||
ng-show="::$ctrl.isHr">
|
ng-if="$ctrl.isHr && $ctrl.state != 'CONFIRMED' && $ctrl.canResend">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -53,6 +53,8 @@ class Controller extends Section {
|
||||||
set worker(value) {
|
set worker(value) {
|
||||||
this._worker = value;
|
this._worker = value;
|
||||||
this.fetchHours();
|
this.fetchHours();
|
||||||
|
if (this.date)
|
||||||
|
this.getWeekData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,7 +112,8 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.weekTotalHours) this.fetchHours();
|
if (!this.weekTotalHours) this.fetchHours();
|
||||||
this.getWeekData();
|
if (this.worker)
|
||||||
|
this.getWeekData();
|
||||||
}
|
}
|
||||||
|
|
||||||
set weekTotalHours(totalHours) {
|
set weekTotalHours(totalHours) {
|
||||||
|
@ -127,17 +130,34 @@ class Controller extends Section {
|
||||||
workerFk: this.$params.id,
|
workerFk: this.$params.id,
|
||||||
year: this._date.getFullYear(),
|
year: this._date.getFullYear(),
|
||||||
week: this.getWeekNumber(this._date)
|
week: this.getWeekNumber(this._date)
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
this.$http.get('WorkerTimeControlMails', {filter})
|
this.$http.get('WorkerTimeControlMails', {filter})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const mail = res.data;
|
if (!res.data.length) {
|
||||||
if (!mail.length) {
|
|
||||||
this.state = null;
|
this.state = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.state = mail[0].state;
|
const [mail] = res.data;
|
||||||
this.reason = mail[0].reason;
|
this.state = mail.state;
|
||||||
|
this.reason = mail.reason;
|
||||||
|
});
|
||||||
|
this.canBeResend();
|
||||||
|
}
|
||||||
|
|
||||||
|
canBeResend() {
|
||||||
|
this.canResend = false;
|
||||||
|
const filter = {
|
||||||
|
where: {
|
||||||
|
year: this._date.getFullYear(),
|
||||||
|
week: this.getWeekNumber(this._date)
|
||||||
|
},
|
||||||
|
limit: 1
|
||||||
|
};
|
||||||
|
this.$http.get('WorkerTimeControlMails', {filter})
|
||||||
|
.then(res => {
|
||||||
|
if (res.data.length)
|
||||||
|
this.canResend = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,30 +376,25 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
isSatisfied() {
|
isSatisfied() {
|
||||||
const params = {
|
this.updateWorkerTimeControlMail('CONFIRMED');
|
||||||
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!'));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isUnsatisfied() {
|
isUnsatisfied() {
|
||||||
if (!this.reason) throw new UserError(`You must indicate a reason`);
|
if (!this.reason) throw new UserError(`You must indicate a reason`);
|
||||||
|
this.updateWorkerTimeControlMail('REVISE', this.reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWorkerTimeControlMail(state, reason) {
|
||||||
const params = {
|
const params = {
|
||||||
workerId: this.worker.id,
|
workerId: this.worker.id,
|
||||||
year: this.date.getFullYear(),
|
year: this.date.getFullYear(),
|
||||||
week: this.weekNumber,
|
week: this.weekNumber,
|
||||||
state: 'REVISE',
|
state
|
||||||
reason: this.reason
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (reason)
|
||||||
|
params.reason = reason;
|
||||||
|
|
||||||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
||||||
this.$http.post(query, params).then(() => {
|
this.$http.post(query, params).then(() => {
|
||||||
this.getMailStates(this.date);
|
this.getMailStates(this.date);
|
||||||
|
|
Loading…
Reference in New Issue