1 | "use strict";
|
2 |
|
3 | var _UserGroup = _interopRequireDefault(require("../models/UserGroup"));
|
4 |
|
5 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6 |
|
7 | var Rules = spice.classes.validate.Rules;
|
8 |
|
9 | Rules.prototype.shouldExist = function* (field, value, args, message) {
|
10 | try {
|
11 | var loaded = require("../models/".concat(args));
|
12 |
|
13 | var Class = loaded.default;
|
14 | var obj = new Class();
|
15 | var found = yield obj.exist(value);
|
16 |
|
17 | if (found) {
|
18 | return true;
|
19 | }
|
20 | } catch (e) {
|
21 | this.validator.addError(field, 'rule', field + 'ShouldExist', 'Cannot Validate ' + args);
|
22 | }
|
23 |
|
24 | return false;
|
25 | };
|
26 |
|
27 | Rules.prototype.userGroupIsUnique = function* (field, value, message) {
|
28 | try {
|
29 | var group = new _UserGroup.default();
|
30 | var group_found = yield group.get({
|
31 | id: value
|
32 | });
|
33 | console.log(group_found);
|
34 | this.validator.addError(field, 'rule', 'usergroupIsUnique', message || 'This usergroup has already been created');
|
35 | return false;
|
36 | } catch (e) {
|
37 | if (e.message == 'user_group does not exist') {
|
38 | return true;
|
39 | } else {
|
40 | this.validator.addError(field, 'rule', 'userGroupIsUnique', 'Cannot Validate usergroup');
|
41 | return false;
|
42 | }
|
43 | }
|
44 | }; |
\ | No newline at end of file |