1 | const { exception } = require('q3-core-responder');
|
2 | const Decorator = require('./decorator');
|
3 | const Schema = require('./schema');
|
4 |
|
5 | Schema.loadClass(Decorator);
|
6 |
|
7 | Schema.pre('save', function conditionalRequirements() {
|
8 | if (
|
9 | (!this.couponCode && !this.requiredSkus) ||
|
10 | (this.couponCode && this.requiredSkus)
|
11 | )
|
12 | exception('Validation')
|
13 | .msg('codeOrSku')
|
14 | .field('couponCode')
|
15 | .field('requiredSkus')
|
16 | .throw();
|
17 | });
|
18 |
|
19 | module.exports = Schema;
|