salix/modules/worker/back/models/department.js

16 lines
557 B
JavaScript
Raw Normal View History

2019-03-12 14:04:09 +00:00
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
require('../methods/department/getLeaves')(Self);
require('../methods/department/nodeAdd')(Self);
require('../methods/department/nodeDelete')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_ROW_IS_REFERENCED_2')
return new UserError(`You cannot remove this department`);
if (err.code === 'ER_DUP_ENTRY')
return new UserError(`The department name can't be repeated`);
return err;
});
};