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/updateWorkerTimeControlMail')(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;
    });
};