Skip to content

Commit b9e3f94

Browse files
authored
fix(api-audit): Added all Audit API endpoints to API docs generation ZMS-135 (#642)
* Added Create new audit api endpoint to API docs generation * Request Audit info API endpoint added to API docs generation * added Export Audited Emails API endpoint to API docs generation
1 parent a5c7d70 commit b9e3f94

File tree

1 file changed

+90
-14
lines changed

1 file changed

+90
-14
lines changed

lib/api/audit.js

+90-14
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,44 @@ const roles = require('../roles');
77
const mboxExport = require('../mbox-export');
88
const ObjectId = require('mongodb').ObjectId;
99
const { sessSchema, sessIPSchema } = require('../schemas');
10+
const { userId } = require('../schemas/request/general-schemas');
11+
const { successRes } = require('../schemas/response/general-schemas');
1012

1113
module.exports = (db, server, auditHandler) => {
1214
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+
},
1439
tools.responseWrapper(async (req, res) => {
1540
res.charSet('utf-8');
1641

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
2448
});
2549

2650
const result = schema.validate(req.params, {
@@ -60,12 +84,48 @@ module.exports = (db, server, auditHandler) => {
6084
);
6185

6286
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+
},
64120
tools.responseWrapper(async (req, res) => {
65121
res.charSet('utf-8');
66122

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
69129
});
70130

71131
const result = schema.validate(req.params, {
@@ -108,12 +168,28 @@ module.exports = (db, server, auditHandler) => {
108168
);
109169

110170
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+
},
112184
tools.responseWrapper(async (req, res) => {
113185
res.charSet('utf-8');
114186

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
117193
});
118194

119195
const result = schema.validate(req.params, {

0 commit comments

Comments
 (0)