-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbanner.js
133 lines (113 loc) · 3.45 KB
/
banner.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
const Joi = require('joi');
const mutate = require('../lib/mutate');
const SCOPES = ['GLOBAL', 'PIPELINE', 'BUILD'];
const MODEL = {
id: Joi.number().integer().positive(),
message: Joi.string()
.max(512)
.description('Body of banner to display')
.example('Due to planned upgrade of Kubernetes, Screwdriver will be down'),
isActive: Joi.boolean().description('Flag if the banner is active').example(true),
createTime: Joi.string()
.max(32)
.isoDate()
.description('When this banner was created')
.example('2017-01-06T01:49:50.384359267Z'),
createdBy: Joi.string().max(128).description('Username of user creating the banner').example('batman123'),
type: Joi.string().valid('info', 'warn').max(32).description('Type/Severity of the banner message').example('info'),
scope: Joi.string()
.max(16)
.valid(...SCOPES)
.description('Scope of the banner')
.example('GLOBAL')
.default('GLOBAL')
.required(),
scopeId: Joi.number()
.integer()
.positive()
.description('Identifier to pipelineId for PIPELINE, buildId for BUILD, or null for GLOBAL')
.when('scope', {
is: Joi.valid('GLOBAL'),
then: Joi.allow(null).optional(),
otherwise: Joi.required()
})
.example(1234)
};
module.exports = {
/**
* All the available properties of Banner
*
* @property base
* @type {Joi}
*/
base: Joi.object(MODEL).label('Banner'),
/**
* All the available properties of Banner
*
* @property fields
* @type {Object}
*/
fields: MODEL,
/**
* Properties for Banner that will come back during a GET request
*
* @property get
* @type {Joi}
*/
get: Joi.object(
mutate(MODEL, ['id', 'message', 'type', 'isActive', 'scope', 'scopeId', 'createdBy', 'createTime'], [])
).label('Get Banner'),
/**
* Properties for Banners that will be passed during a CREATE request
*
* @property create
* @type {Joi}
*/
create: Joi.object(mutate(MODEL, ['message'], ['type', 'isActive', 'scope', 'scopeId'])).label('Create Banner'),
/**
* Properties for Banners that will be passed during a UPDATE request
*
* @property update
* @type {Joi}
*/
update: Joi.object(mutate(MODEL, [], ['message', 'type', 'isActive'])).label('Update Banner'),
/**
* Properties for Banners that will come back during a LIST request.
* The LIST request will list all banners
*/
list: Joi.array()
.items(
Joi.object(
mutate(MODEL, ['id', 'message', 'type', 'isActive', 'scope', 'scopeId', 'createdBy', 'createTime'], [])
)
)
.label('List Banners'),
/**
* List of fields that determine a unique row
*
* @property keys
* @type {Array}
*/
keys: ['message', 'type', 'createTime', 'scope', 'scopeId'],
/**
* List of all fields in the model
* @property allKeys
* @type {Array}
*/
allKeys: Object.keys(MODEL),
/**
* Tablename to be used in the datastore
*
* @property tableName
* @type {String}
*/
tableName: 'banners',
/**
* List of indexes to create in the datastore
*
* @property indexes
* @type {Array}
*/
indexes: [{ fields: ['isActive'] }, { fields: ['scope', 'scopeId'] }]
};