1 | /**
|
2 | * @copyright Copyright (c) 2019 Maxim Khorin <maksimovichu@gmail.com>
|
3 | */
|
4 | ;
|
5 |
|
6 | const Base = require('./Validator');
|
7 |
|
8 | module.exports = class DefaultValueValidator extends Base {
|
9 |
|
10 | constructor (config) {
|
11 | super({
|
12 | value: null,
|
13 | skipOnEmpty: false,
|
14 | ...config
|
15 | });
|
16 | }
|
17 |
|
18 | async validateAttr (attr, model) {
|
19 | if (!this.isEmptyValue(model.get(attr))) {
|
20 | return;
|
21 | }
|
22 | model.set(attr, typeof this.value === 'function'
|
23 | ? await this.value.call(this, attr, model, this)
|
24 | : this.value);
|
25 | }
|
26 | }; |
\ | No newline at end of file |