34 lines
1.4 KiB
JavaScript
34 lines
1.4 KiB
JavaScript
const UserError = require('vn-loopback/util/user-error');
|
|
|
|
module.exports = Self => {
|
|
require('../methods/worker-time-control/filter')(Self);
|
|
require('../methods/worker-time-control/addTimeEntry')(Self);
|
|
require('../methods/worker-time-control/deleteTimeEntry')(Self);
|
|
require('../methods/worker-time-control/updateTimeEntry')(Self);
|
|
require('../methods/worker-time-control/sendMail')(Self);
|
|
require('../methods/worker-time-control/updateMailState')(Self);
|
|
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
|
|
require('../methods/worker-time-control/getMailStates')(Self);
|
|
require('../methods/worker-time-control/resendWeeklyHourEmail')(Self);
|
|
require('../methods/worker-time-control/login')(Self);
|
|
require('../methods/worker-time-control/getClockIn')(Self);
|
|
require('../methods/worker-time-control/clockIn')(Self);
|
|
|
|
Self.rewriteDbError(function(err) {
|
|
if (err.code === 'ER_DUP_ENTRY')
|
|
return new UserError(`The introduced hour already exists`);
|
|
return err;
|
|
});
|
|
|
|
Self.getStartDateOfWeekNumber = (week, year) => {
|
|
const simple = new Date(year, 0, 1 + (week - 1) * 7);
|
|
const dow = simple.getDay();
|
|
const weekStart = simple;
|
|
if (dow <= 4)
|
|
weekStart.setDate(simple.getDate() - simple.getDay() + 1);
|
|
else
|
|
weekStart.setDate(simple.getDate() + 8 - simple.getDay());
|
|
return weekStart;
|
|
};
|
|
};
|