@@ -7,21 +7,60 @@ const tools = require('../tools');
7
7
const roles = require ( '../roles' ) ;
8
8
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema } = require ( '../schemas' ) ;
9
9
const { publish, DOMAINALIAS_CREATED , DOMAINALIAS_DELETED } = require ( '../events' ) ;
10
+ const { successRes, totalRes, pageRes, previousCursorRes, nextCursorRes } = require ( '../schemas/response/general-schemas' ) ;
10
11
11
12
module . exports = ( db , server ) => {
12
13
server . get (
13
- { name : 'domainaliases' , path : '/domainaliases' } ,
14
+ {
15
+ name : 'domainaliases' ,
16
+ path : '/domainaliases' ,
17
+ tags : [ 'DomainAliases' ] ,
18
+ summary : 'List registered Domain Aliases' ,
19
+ validationObjs : {
20
+ requestBody : { } ,
21
+ pathParams : { } ,
22
+ queryParams : {
23
+ query : Joi . string ( ) . trim ( ) . empty ( '' ) . max ( 255 ) . description ( 'Partial match of a Domain Alias or Domain name' ) ,
24
+ limit : Joi . number ( ) . default ( 20 ) . min ( 1 ) . max ( 250 ) . description ( 'How many records to return' ) ,
25
+ next : nextPageCursorSchema ,
26
+ previous : previousPageCursorSchema ,
27
+ page : pageNrSchema ,
28
+ sess : sessSchema ,
29
+ ip : sessIPSchema
30
+ } ,
31
+ response : {
32
+ 200 : {
33
+ descrition : 'Success' ,
34
+ model : Joi . object ( {
35
+ success : successRes ,
36
+ total : totalRes ,
37
+ page : pageRes ,
38
+ previousCursor : previousCursorRes ,
39
+ nextCursor : nextCursorRes ,
40
+ results : Joi . array ( )
41
+ . items (
42
+ Joi . object ( {
43
+ id : Joi . string ( ) . required ( ) . description ( 'ID of the Domain Alias' ) ,
44
+ alias : Joi . string ( ) . required ( ) . description ( 'Domain Alias' ) ,
45
+ domain : Joi . string ( ) . required ( ) . description ( 'The domain this alias applies to' )
46
+ } ) . $_setFlag ( 'objectName' , 'GetDomainAliasesResult' )
47
+ )
48
+ . required ( )
49
+ . description ( 'Aliases listing' )
50
+ } )
51
+ }
52
+ }
53
+ }
54
+ } ,
14
55
tools . responseWrapper ( async ( req , res ) => {
15
56
res . charSet ( 'utf-8' ) ;
16
57
17
- const schema = Joi . object ( ) . keys ( {
18
- query : Joi . string ( ) . trim ( ) . empty ( '' ) . max ( 255 ) ,
19
- limit : Joi . number ( ) . default ( 20 ) . min ( 1 ) . max ( 250 ) ,
20
- next : nextPageCursorSchema ,
21
- previous : previousPageCursorSchema ,
22
- page : pageNrSchema ,
23
- sess : sessSchema ,
24
- ip : sessIPSchema
58
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
59
+
60
+ const schema = Joi . object ( {
61
+ ...pathParams ,
62
+ ...queryParams ,
63
+ ...requestBody
25
64
} ) ;
26
65
27
66
const result = schema . validate ( req . params , {
@@ -127,21 +166,45 @@ module.exports = (db, server) => {
127
166
) ;
128
167
129
168
server . post (
130
- '/domainaliases' ,
169
+ {
170
+ path : '/domainaliases' ,
171
+ tags : [ 'DomainAliases' ] ,
172
+ summary : 'Create new Domain Alias' ,
173
+ description : 'Add a new Alias for a Domain. This allows to accept mail on username@domain and username@alias' ,
174
+ validationObjs : {
175
+ requestBody : {
176
+ alias : Joi . string ( )
177
+ . max ( 255 )
178
+ //.hostname()
179
+ . required ( )
180
+ . description ( 'Domain Alias' ) ,
181
+ domain : Joi . string ( )
182
+ . max ( 255 )
183
+ //.hostname()
184
+ . required ( )
185
+ . description ( 'Domain name this Alias applies to' ) ,
186
+ sess : sessSchema ,
187
+ ip : sessIPSchema
188
+ } ,
189
+ queryParams : { } ,
190
+ pathParams : { } ,
191
+ response : {
192
+ 200 : {
193
+ description : 'Success' ,
194
+ model : Joi . object ( { success : successRes , id : Joi . string ( ) . required ( ) . description ( 'ID of the Domain Alias' ) } )
195
+ }
196
+ }
197
+ }
198
+ } ,
131
199
tools . responseWrapper ( async ( req , res ) => {
132
200
res . charSet ( 'utf-8' ) ;
133
201
134
- const schema = Joi . object ( ) . keys ( {
135
- alias : Joi . string ( )
136
- . max ( 255 )
137
- //.hostname()
138
- . required ( ) ,
139
- domain : Joi . string ( )
140
- . max ( 255 )
141
- //.hostname()
142
- . required ( ) ,
143
- sess : sessSchema ,
144
- ip : sessIPSchema
202
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
203
+
204
+ const schema = Joi . object ( {
205
+ ...pathParams ,
206
+ ...queryParams ,
207
+ ...requestBody
145
208
} ) ;
146
209
147
210
const result = schema . validate ( req . params , {
@@ -225,17 +288,40 @@ module.exports = (db, server) => {
225
288
) ;
226
289
227
290
server . get (
228
- '/domainaliases/resolve/:alias' ,
291
+ {
292
+ path : '/domainaliases/resolve/:alias' ,
293
+ tags : [ 'DomainAliases' ] ,
294
+ summary : 'Resolve ID for a domain alias' ,
295
+ validationObjs : {
296
+ requestBody : { } ,
297
+ pathParams : {
298
+ alias : Joi . string ( )
299
+ . max ( 255 )
300
+ //.hostname()
301
+ . required ( )
302
+ . description ( 'Alias domain' )
303
+ } ,
304
+ queryParams : {
305
+ sess : sessSchema ,
306
+ ip : sessIPSchema
307
+ } ,
308
+ response : {
309
+ 200 : {
310
+ description : 'Success' ,
311
+ model : Joi . object ( { success : successRes , id : Joi . string ( ) . required ( ) . description ( 'Unique ID (24 byte hex)' ) } )
312
+ }
313
+ }
314
+ }
315
+ } ,
229
316
tools . responseWrapper ( async ( req , res ) => {
230
317
res . charSet ( 'utf-8' ) ;
231
318
232
- const schema = Joi . object ( ) . keys ( {
233
- alias : Joi . string ( )
234
- . max ( 255 )
235
- //.hostname()
236
- . required ( ) ,
237
- sess : sessSchema ,
238
- ip : sessIPSchema
319
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
320
+
321
+ const schema = Joi . object ( {
322
+ ...pathParams ,
323
+ ...queryParams ,
324
+ ...requestBody
239
325
} ) ;
240
326
241
327
const result = schema . validate ( req . params , {
@@ -291,14 +377,42 @@ module.exports = (db, server) => {
291
377
) ;
292
378
293
379
server . get (
294
- '/domainaliases/:alias' ,
380
+ {
381
+ path : '/domainaliases/:alias' ,
382
+ tags : [ 'DomainAliases' ] ,
383
+ summary : 'Request Alias information' ,
384
+ validationObjs : {
385
+ requestBody : { } ,
386
+ queryParams : {
387
+ sess : sessSchema ,
388
+ ip : sessIPSchema
389
+ } ,
390
+ pathParams : {
391
+ alias : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) . description ( 'ID of the Alias' )
392
+ } ,
393
+ response : {
394
+ 200 : {
395
+ description : 'Success' ,
396
+ model : Joi . object ( {
397
+ success : successRes ,
398
+ id : Joi . string ( ) . required ( ) . description ( 'ID of the Alias' ) ,
399
+ alias : Joi . string ( ) . required ( ) . description ( 'Alias domain' ) ,
400
+ domain : Joi . string ( ) . required ( ) . description ( 'Alias target' ) ,
401
+ created : Joi . date ( ) . required ( ) . description ( 'Datestring of the time the alias was created' )
402
+ } )
403
+ }
404
+ }
405
+ }
406
+ } ,
295
407
tools . responseWrapper ( async ( req , res ) => {
296
408
res . charSet ( 'utf-8' ) ;
297
409
298
- const schema = Joi . object ( ) . keys ( {
299
- alias : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) ,
300
- sess : sessSchema ,
301
- ip : sessIPSchema
410
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
411
+
412
+ const schema = Joi . object ( {
413
+ ...pathParams ,
414
+ ...queryParams ,
415
+ ...requestBody
302
416
} ) ;
303
417
304
418
const result = schema . validate ( req . params , {
@@ -352,7 +466,20 @@ module.exports = (db, server) => {
352
466
) ;
353
467
354
468
server . del (
355
- '/domainaliases/:alias' ,
469
+ {
470
+ path : '/domainaliases/:alias' ,
471
+ tags : [ 'DomainAliases' ] ,
472
+ summary : 'Delete an Alias' ,
473
+ validationObjs : {
474
+ requestBody : { } ,
475
+ pathParams : { alias : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) . description ( 'ID of the Alias' ) } ,
476
+ queryParams : {
477
+ sess : sessSchema ,
478
+ ip : sessIPSchema
479
+ } ,
480
+ response : { 200 : { description : 'Success' , model : Joi . object ( { success : successRes } ) } }
481
+ }
482
+ } ,
356
483
tools . responseWrapper ( async ( req , res ) => {
357
484
res . charSet ( 'utf-8' ) ;
358
485
0 commit comments