@@ -6,33 +6,57 @@ const tools = require('../tools');
6
6
const roles = require ( '../roles' ) ;
7
7
const { sessSchema, sessIPSchema, booleanSchema } = require ( '../schemas' ) ;
8
8
const { publish, AUTOREPLY_USER_DISABLED , AUTOREPLY_USER_ENABLED } = require ( '../events' ) ;
9
+ const { userId } = require ( '../schemas/request/general-schemas' ) ;
10
+ const { successRes } = require ( '../schemas/response/general-schemas' ) ;
9
11
10
12
module . exports = ( db , server ) => {
11
13
server . put (
12
- '/users/:user/autoreply' ,
14
+ {
15
+ path : '/users/:user/autoreply' ,
16
+ tags : [ 'Autoreplies' ] ,
17
+ summary : 'Update Autoreply information' ,
18
+ validationObjs : {
19
+ requestBody : {
20
+ status : booleanSchema . description ( 'Is the autoreply enabled (true) or not (false)' ) ,
21
+ name : Joi . string ( ) . allow ( '' ) . trim ( ) . max ( 128 ) . description ( 'Name that is used for the From: header in autoreply message' ) ,
22
+ subject : Joi . string ( )
23
+ . allow ( '' )
24
+ . trim ( )
25
+ . max ( 2 * 1024 )
26
+ . description ( 'Subject line for the autoreply. If empty then uses subject of the original message' ) ,
27
+ text : Joi . string ( )
28
+ . allow ( '' )
29
+ . trim ( )
30
+ . max ( 128 * 1024 )
31
+ . description ( 'Plaintext formatted content of the autoreply message' ) ,
32
+ html : Joi . string ( )
33
+ . allow ( '' )
34
+ . trim ( )
35
+ . max ( 128 * 1024 )
36
+ . description ( 'HTML formatted content of the autoreply message' ) ,
37
+ start : Joi . date ( ) . empty ( '' ) . allow ( false ) . description ( 'Datestring of the start of the autoreply or boolean false to disable start checks' ) ,
38
+ end : Joi . date ( ) . empty ( '' ) . allow ( false ) . description ( 'Datestring of the end of the autoreply or boolean false to disable end checks' ) ,
39
+ sess : sessSchema ,
40
+ ip : sessIPSchema
41
+ } ,
42
+ queryParams : { } ,
43
+ pathParams : {
44
+ user : userId
45
+ } ,
46
+ response : {
47
+ 200 : { description : 'Success' , model : Joi . object ( { success : successRes , id : Joi . string ( ) . required ( ) . description ( 'Autoreply ID' ) } ) }
48
+ }
49
+ }
50
+ } ,
13
51
tools . responseWrapper ( async ( req , res ) => {
14
52
res . charSet ( 'utf-8' ) ;
15
53
16
- const schema = Joi . object ( ) . keys ( {
17
- user : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) ,
18
- status : booleanSchema ,
19
- name : Joi . string ( ) . allow ( '' ) . trim ( ) . max ( 128 ) ,
20
- subject : Joi . string ( )
21
- . allow ( '' )
22
- . trim ( )
23
- . max ( 2 * 1024 ) ,
24
- text : Joi . string ( )
25
- . allow ( '' )
26
- . trim ( )
27
- . max ( 128 * 1024 ) ,
28
- html : Joi . string ( )
29
- . allow ( '' )
30
- . trim ( )
31
- . max ( 128 * 1024 ) ,
32
- start : Joi . date ( ) . empty ( '' ) . allow ( false ) ,
33
- end : Joi . date ( ) . empty ( '' ) . allow ( false ) ,
34
- sess : sessSchema ,
35
- ip : sessIPSchema
54
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
55
+
56
+ const schema = Joi . object ( {
57
+ ...pathParams ,
58
+ ...requestBody ,
59
+ ...queryParams
36
60
} ) ;
37
61
38
62
const result = schema . validate ( req . params , {
@@ -95,14 +119,58 @@ module.exports = (db, server) => {
95
119
) ;
96
120
97
121
server . get (
98
- '/users/:user/autoreply' ,
122
+ {
123
+ path : '/users/:user/autoreply' ,
124
+ tags : [ 'Autoreplies' ] ,
125
+ summary : 'Request Autoreply information' ,
126
+ validationObjs : {
127
+ requestBody : { } ,
128
+ queryParams : {
129
+ sess : sessSchema ,
130
+ ip : sessIPSchema
131
+ } ,
132
+ pathParams : { user : userId } ,
133
+ response : {
134
+ 200 : {
135
+ description : 'Success' ,
136
+ model : Joi . object ( {
137
+ success : successRes ,
138
+ status : booleanSchema . description ( 'Is the autoreply enabled (true) or not (false)' ) ,
139
+ name : Joi . string ( ) . allow ( '' ) . trim ( ) . max ( 128 ) . description ( 'Name that is used for the From: header in autoreply message' ) ,
140
+ subject : Joi . string ( )
141
+ . allow ( '' )
142
+ . trim ( )
143
+ . max ( 2 * 1024 )
144
+ . description ( 'Subject line for the autoreply. If empty then uses subject of the original message' ) ,
145
+ text : Joi . string ( )
146
+ . allow ( '' )
147
+ . trim ( )
148
+ . max ( 128 * 1024 )
149
+ . description ( 'Plaintext formatted content of the autoreply message' ) ,
150
+ html : Joi . string ( )
151
+ . allow ( '' )
152
+ . trim ( )
153
+ . max ( 128 * 1024 )
154
+ . description ( 'HTML formatted content of the autoreply message' ) ,
155
+ start : Joi . date ( )
156
+ . empty ( '' )
157
+ . allow ( false )
158
+ . description ( 'Datestring of the start of the autoreply or boolean false to disable start checks' ) ,
159
+ end : Joi . date ( ) . empty ( '' ) . allow ( false ) . description ( 'Datestring of the end of the autoreply or boolean false to disable end checks' )
160
+ } )
161
+ }
162
+ }
163
+ }
164
+ } ,
99
165
tools . responseWrapper ( async ( req , res ) => {
100
166
res . charSet ( 'utf-8' ) ;
101
167
102
- const schema = Joi . object ( ) . keys ( {
103
- user : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) ,
104
- sess : sessSchema ,
105
- ip : sessIPSchema
168
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
169
+
170
+ const schema = Joi . object ( {
171
+ ...pathParams ,
172
+ ...requestBody ,
173
+ ...queryParams
106
174
} ) ;
107
175
108
176
const result = schema . validate ( req . params , {
@@ -145,14 +213,31 @@ module.exports = (db, server) => {
145
213
) ;
146
214
147
215
server . del (
148
- '/users/:user/autoreply' ,
216
+ {
217
+ path : '/users/:user/autoreply' ,
218
+ tags : [ 'Autoreplies' ] ,
219
+ summary : 'Delete Autoreply information' ,
220
+ validationObjs : {
221
+ requestBody : { } ,
222
+ queryParams : {
223
+ sess : sessSchema ,
224
+ ip : sessIPSchema
225
+ } ,
226
+ pathParams : {
227
+ user : userId
228
+ } ,
229
+ reponse : { 200 : { description : 'Success' , model : Joi . object ( { success : successRes } ) } }
230
+ }
231
+ } ,
149
232
tools . responseWrapper ( async ( req , res ) => {
150
233
res . charSet ( 'utf-8' ) ;
151
234
152
- const schema = Joi . object ( ) . keys ( {
153
- user : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) ,
154
- sess : sessSchema ,
155
- ip : sessIPSchema
235
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
236
+
237
+ const schema = Joi . object ( {
238
+ ...pathParams ,
239
+ ...requestBody ,
240
+ ...queryParams
156
241
} ) ;
157
242
158
243
const result = schema . validate ( req . params , {
0 commit comments