/
subscriber.js
46 lines (35 loc) · 914 Bytes
/
subscriber.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
/**
* @fileoverview Model schema for a subscriber type
*/
import Joi from 'joi';
import { schema as emailSchema } from './subscriber/email';
import { schema as webhookSchema } from './subscriber/webhook';
import { validTypes } from '../repositories/subscription';
const prefix = 'SB';
const schema = Joi.object({
id: Joi.string()
.regex(/^SB.+$/)
.required(),
created_at: Joi.date()
.iso()
.required(),
updated_at: Joi.date()
.iso()
.required(),
type: Joi.string()
.only(validTypes)
.required(),
is_confirmed: Joi.boolean()
.required(),
components: Joi.array()
.items(Joi.string())
.unique()
.required()
})
.when(Joi.object({ type: Joi.string().only('email') }).unknown(), {
then: emailSchema
})
.when(Joi.object({ type: Joi.string().only('webhook') }).unknown(), {
then: webhookSchema
});
export default { schema, prefix };