forked from ustaxcourt/ef-cms
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMessageResult.js
56 lines (51 loc) · 1.46 KB
/
MessageResult.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const joi = require('joi');
const {
joiValidationDecorator,
validEntityDecorator,
} = require('./JoiValidationDecorator');
const {
TRIAL_CITY_STRINGS,
TRIAL_LOCATION_MATCHER,
} = require('./EntityConstants');
const { JoiValidationConstants } = require('./JoiValidationConstants');
const { messageDecorator } = require('./Message');
/**
* constructor
*
* @param {object} rawMessage the raw message data
* @constructor
*/
function MessageResult() {
this.entityName = 'MessageResult';
}
MessageResult.prototype.init = function init(
rawMessage,
{ applicationContext },
) {
messageDecorator(this, rawMessage, { applicationContext });
this.trialDate = rawMessage.trialDate;
this.trialLocation = rawMessage.trialLocation;
};
MessageResult.VALIDATION_RULES = {
trialDate: joi
.alternatives()
.optional()
.description('When this case goes to trial.'),
trialLocation: joi
.alternatives()
.try(
JoiValidationConstants.STRING.valid(...TRIAL_CITY_STRINGS, null),
JoiValidationConstants.STRING.pattern(TRIAL_LOCATION_MATCHER),
JoiValidationConstants.STRING.valid('Standalone Remote'),
)
.optional()
.description(
'Where this case goes to trial. This may be different that the preferred trial location.',
),
};
joiValidationDecorator(
MessageResult,
joi.object().keys(MessageResult.VALIDATION_RULES),
MessageResult.VALIDATION_ERROR_MESSAGES,
);
exports.MessageResult = validEntityDecorator(MessageResult);