Skip to content

Commit

Permalink
fix(api-audit): Added all Audit API endpoints to API docs generation …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
NickOvt authored Mar 18, 2024
1 parent a5c7d70 commit b9e3f94
Showing 1 changed file with 90 additions and 14 deletions.
104 changes: 90 additions & 14 deletions lib/api/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,44 @@ const roles = require('../roles');
const mboxExport = require('../mbox-export');
const ObjectId = require('mongodb').ObjectId;
const { sessSchema, sessIPSchema } = require('../schemas');
const { userId } = require('../schemas/request/general-schemas');
const { successRes } = require('../schemas/response/general-schemas');

module.exports = (db, server, auditHandler) => {
server.post(
'/audit',
{
path: '/audit',
tags: ['Audit'],
summary: 'Create new audit',
description: 'Initiates a message audit',
validationObjs: {
requestBody: {
user: userId,
start: Joi.date().empty('').allow(false).description('Start time as ISO date'),
end: Joi.date().empty('').allow(false).description('End time as ISO date'),
expires: Joi.date().empty('').greater('now').required().description('Expiration date. Audit data is deleted after this date'),
sess: sessSchema,
ip: sessIPSchema
},
queryParams: {},
pathParams: {},
response: {
200: {
description: 'Success',
model: Joi.object({ success: successRes, id: Joi.string().required().description('ID for the created Audit') })
}
}
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
user: Joi.string().hex().lowercase().length(24).required(),
start: Joi.date().empty('').allow(false),
end: Joi.date().empty('').allow(false),
expires: Joi.date().empty('').greater('now').required(),
sess: sessSchema,
ip: sessIPSchema
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;

const schema = Joi.object({
...pathParams,
...requestBody,
...queryParams
});

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

server.get(
'/audit/:audit',
{
path: '/audit/:audit',
tags: ['Audit'],
summary: 'Request Audit Info',
description: 'This method returns information about stored audit',
validationObjs: {
requestBody: {},
pathParams: {
audit: Joi.string().hex().lowercase().length(24).required().description('ID of the Audit')
},
queryParams: {},
response: {
200: {
description: 'Success',
model: Joi.object({
success: successRes,
id: Joi.string().required().description('ID of the Audit'),
user: userId,
start: Joi.date().empty('').allow(false).description('Start time as ISO date'),
end: Joi.date().empty('').allow(false).description('End time as ISO date'),
expires: Joi.date().empty('').greater('now').required().description('Expiration date. Audit data is deleted after this date'),
import: Joi.object({
status: Joi.string().required().description('Status of the audit'),
failed: Joi.number().required().description('How many messages failed'),
copied: Joi.number().required().description('How many messages copied')
})
.required()
.description('Audit import data')
})
}
}
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
audit: Joi.string().hex().lowercase().length(24).required()
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;

const schema = Joi.object({
...pathParams,
...requestBody,
...queryParams
});

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

server.get(
'/audit/:audit/export.mbox',
{
path: '/audit/:audit/export.mbox',
tags: ['Audit'],
summary: 'Export Audited Emails',
description: 'This method returns a mailbox file that contains all audited emails',
validationObjs: {
requestBody: {},
queryParams: {},
pathParams: { audit: Joi.string().hex().lowercase().length(24).required().description('ID of the Audit') },
response: { 200: { description: 'Success', model: Joi.object() } }
},
responseType: 'application/octet-stream'
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
audit: Joi.string().hex().lowercase().length(24).required()
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;

const schema = Joi.object({
...pathParams,
...requestBody,
...queryParams
});

const result = schema.validate(req.params, {
Expand Down

0 comments on commit b9e3f94

Please sign in to comment.