@@ -7,20 +7,44 @@ const roles = require('../roles');
7
7
const mboxExport = require ( '../mbox-export' ) ;
8
8
const ObjectId = require ( 'mongodb' ) . ObjectId ;
9
9
const { sessSchema, sessIPSchema } = require ( '../schemas' ) ;
10
+ const { userId } = require ( '../schemas/request/general-schemas' ) ;
11
+ const { successRes } = require ( '../schemas/response/general-schemas' ) ;
10
12
11
13
module . exports = ( db , server , auditHandler ) => {
12
14
server . post (
13
- '/audit' ,
15
+ {
16
+ path : '/audit' ,
17
+ tags : [ 'Audit' ] ,
18
+ summary : 'Create new audit' ,
19
+ description : 'Initiates a message audit' ,
20
+ validationObjs : {
21
+ requestBody : {
22
+ user : userId ,
23
+ start : Joi . date ( ) . empty ( '' ) . allow ( false ) . description ( 'Start time as ISO date' ) ,
24
+ end : Joi . date ( ) . empty ( '' ) . allow ( false ) . description ( 'End time as ISO date' ) ,
25
+ expires : Joi . date ( ) . empty ( '' ) . greater ( 'now' ) . required ( ) . description ( 'Expiration date. Audit data is deleted after this date' ) ,
26
+ sess : sessSchema ,
27
+ ip : sessIPSchema
28
+ } ,
29
+ queryParams : { } ,
30
+ pathParams : { } ,
31
+ response : {
32
+ 200 : {
33
+ description : 'Success' ,
34
+ model : Joi . object ( { success : successRes , id : Joi . string ( ) . required ( ) . description ( 'ID for the created Audit' ) } )
35
+ }
36
+ }
37
+ }
38
+ } ,
14
39
tools . responseWrapper ( async ( req , res ) => {
15
40
res . charSet ( 'utf-8' ) ;
16
41
17
- const schema = Joi . object ( ) . keys ( {
18
- user : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) ,
19
- start : Joi . date ( ) . empty ( '' ) . allow ( false ) ,
20
- end : Joi . date ( ) . empty ( '' ) . allow ( false ) ,
21
- expires : Joi . date ( ) . empty ( '' ) . greater ( 'now' ) . required ( ) ,
22
- sess : sessSchema ,
23
- ip : sessIPSchema
42
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
43
+
44
+ const schema = Joi . object ( {
45
+ ...pathParams ,
46
+ ...requestBody ,
47
+ ...queryParams
24
48
} ) ;
25
49
26
50
const result = schema . validate ( req . params , {
@@ -60,12 +84,48 @@ module.exports = (db, server, auditHandler) => {
60
84
) ;
61
85
62
86
server . get (
63
- '/audit/:audit' ,
87
+ {
88
+ path : '/audit/:audit' ,
89
+ tags : [ 'Audit' ] ,
90
+ summary : 'Request Audit Info' ,
91
+ description : 'This method returns information about stored audit' ,
92
+ validationObjs : {
93
+ requestBody : { } ,
94
+ pathParams : {
95
+ audit : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) . description ( 'ID of the Audit' )
96
+ } ,
97
+ queryParams : { } ,
98
+ response : {
99
+ 200 : {
100
+ description : 'Success' ,
101
+ model : Joi . object ( {
102
+ success : successRes ,
103
+ id : Joi . string ( ) . required ( ) . description ( 'ID of the Audit' ) ,
104
+ user : userId ,
105
+ start : Joi . date ( ) . empty ( '' ) . allow ( false ) . description ( 'Start time as ISO date' ) ,
106
+ end : Joi . date ( ) . empty ( '' ) . allow ( false ) . description ( 'End time as ISO date' ) ,
107
+ expires : Joi . date ( ) . empty ( '' ) . greater ( 'now' ) . required ( ) . description ( 'Expiration date. Audit data is deleted after this date' ) ,
108
+ import : Joi . object ( {
109
+ status : Joi . string ( ) . required ( ) . description ( 'Status of the audit' ) ,
110
+ failed : Joi . number ( ) . required ( ) . description ( 'How many messages failed' ) ,
111
+ copied : Joi . number ( ) . required ( ) . description ( 'How many messages copied' )
112
+ } )
113
+ . required ( )
114
+ . description ( 'Audit import data' )
115
+ } )
116
+ }
117
+ }
118
+ }
119
+ } ,
64
120
tools . responseWrapper ( async ( req , res ) => {
65
121
res . charSet ( 'utf-8' ) ;
66
122
67
- const schema = Joi . object ( ) . keys ( {
68
- audit : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( )
123
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
124
+
125
+ const schema = Joi . object ( {
126
+ ...pathParams ,
127
+ ...requestBody ,
128
+ ...queryParams
69
129
} ) ;
70
130
71
131
const result = schema . validate ( req . params , {
@@ -108,12 +168,28 @@ module.exports = (db, server, auditHandler) => {
108
168
) ;
109
169
110
170
server . get (
111
- '/audit/:audit/export.mbox' ,
171
+ {
172
+ path : '/audit/:audit/export.mbox' ,
173
+ tags : [ 'Audit' ] ,
174
+ summary : 'Export Audited Emails' ,
175
+ description : 'This method returns a mailbox file that contains all audited emails' ,
176
+ validationObjs : {
177
+ requestBody : { } ,
178
+ queryParams : { } ,
179
+ pathParams : { audit : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( ) . description ( 'ID of the Audit' ) } ,
180
+ response : { 200 : { description : 'Success' , model : Joi . object ( ) } }
181
+ } ,
182
+ responseType : 'application/octet-stream'
183
+ } ,
112
184
tools . responseWrapper ( async ( req , res ) => {
113
185
res . charSet ( 'utf-8' ) ;
114
186
115
- const schema = Joi . object ( ) . keys ( {
116
- audit : Joi . string ( ) . hex ( ) . lowercase ( ) . length ( 24 ) . required ( )
187
+ const { pathParams, requestBody, queryParams } = req . route . spec . validationObjs ;
188
+
189
+ const schema = Joi . object ( {
190
+ ...pathParams ,
191
+ ...requestBody ,
192
+ ...queryParams
117
193
} ) ;
118
194
119
195
const result = schema . validate ( req . params , {
0 commit comments