2021-10-06 17:29:15 +03:00
|
|
|
import BaseValidator from './base';
|
|
|
|
import validator from 'validator';
|
|
|
|
|
|
|
|
export default BaseValidator.create({
|
2021-10-19 10:35:18 +03:00
|
|
|
properties: ['name', 'amount', 'displayTitle', 'displayDescription', 'code', 'durationInMonths'],
|
2021-10-06 17:29:15 +03:00
|
|
|
|
|
|
|
name(model) {
|
|
|
|
if (!model.name) {
|
2021-10-22 13:13:15 +03:00
|
|
|
model.errors.add('name', 'Please enter a name.');
|
2021-10-06 17:29:15 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
2021-11-24 15:48:22 +03:00
|
|
|
if (!validator.isLength(model.name || '', 0, 40)) {
|
|
|
|
model.errors.add('name', 'Name cannot be longer than 40 characters.');
|
2021-10-06 17:29:15 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
2021-10-19 10:35:18 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
amount(model) {
|
|
|
|
if (!model.amount) {
|
2021-10-22 13:13:15 +03:00
|
|
|
model.errors.add('amount', 'Please enter the amount.');
|
2021-10-19 10:35:18 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
displayDescription(model) {
|
|
|
|
if (!validator.isLength(model.displayDescription || '', 0, 191)) {
|
|
|
|
model.errors.add('displayDescription', 'Display description cannot be longer than 191 characters.');
|
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
durationInMonths(model) {
|
|
|
|
if (model.duration === 'repeating' && !model.durationInMonths) {
|
2021-10-22 13:13:15 +03:00
|
|
|
model.errors.add('durationInMonths', 'Please enter the duration in months.');
|
2021-10-19 10:35:18 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
code(model) {
|
|
|
|
if (!model.code) {
|
2021-10-22 13:13:15 +03:00
|
|
|
model.errors.add('code', 'Please enter an offer code.');
|
2021-10-19 10:35:18 +03:00
|
|
|
this.invalidate();
|
|
|
|
}
|
2021-10-06 17:29:15 +03:00
|
|
|
}
|
|
|
|
});
|