35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
const UserError = require('vn-loopback/util/user-error');
|
|
const moment = require('moment');
|
|
|
|
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.getMondayWeekYear = (week, year) => {
|
|
if (!week || !year) {
|
|
const today = Date.vnNew();
|
|
today.setDate(today.getDate() - 7);
|
|
week = moment(today).isoWeek();
|
|
year = moment(today).isoWeekYear();
|
|
}
|
|
const date = moment(year, 'YYYY').week(week).startOf('isoweek').toDate();
|
|
return {date, year, week};
|
|
};
|
|
};
|