Skip to content

Commit

Permalink
fix(api-autoreply): Autoreply API endpoints added to API docs generat…
Browse files Browse the repository at this point in the history
…ion ZMS-130 (#632)

* Update Autoreply information api endpoint added to api docs generation

* Delete Autoreply information api endpoint added to api docs generation

* Request Autoreply information api endpoint added to api docs generation
  • Loading branch information
NickOvt authored Feb 23, 2024
1 parent 7e9e62e commit aa60ef9
Showing 1 changed file with 116 additions and 31 deletions.
147 changes: 116 additions & 31 deletions lib/api/autoreply.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,57 @@ const tools = require('../tools');
const roles = require('../roles');
const { sessSchema, sessIPSchema, booleanSchema } = require('../schemas');
const { publish, AUTOREPLY_USER_DISABLED, AUTOREPLY_USER_ENABLED } = require('../events');
const { userId } = require('../schemas/request/general-schemas');
const { successRes } = require('../schemas/response/general-schemas');

module.exports = (db, server) => {
server.put(
'/users/:user/autoreply',
{
path: '/users/:user/autoreply',
tags: ['Autoreplies'],
summary: 'Update Autoreply information',
validationObjs: {
requestBody: {
status: booleanSchema.description('Is the autoreply enabled (true) or not (false)'),
name: Joi.string().allow('').trim().max(128).description('Name that is used for the From: header in autoreply message'),
subject: Joi.string()
.allow('')
.trim()
.max(2 * 1024)
.description('Subject line for the autoreply. If empty then uses subject of the original message'),
text: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('Plaintext formatted content of the autoreply message'),
html: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('HTML formatted content of the autoreply message'),
start: Joi.date().empty('').allow(false).description('Datestring of the start of the autoreply or boolean false to disable start checks'),
end: Joi.date().empty('').allow(false).description('Datestring of the end of the autoreply or boolean false to disable end checks'),
sess: sessSchema,
ip: sessIPSchema
},
queryParams: {},
pathParams: {
user: userId
},
response: {
200: { description: 'Success', model: Joi.object({ success: successRes, id: Joi.string().required().description('Autoreply ID') }) }
}
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
user: Joi.string().hex().lowercase().length(24).required(),
status: booleanSchema,
name: Joi.string().allow('').trim().max(128),
subject: Joi.string()
.allow('')
.trim()
.max(2 * 1024),
text: Joi.string()
.allow('')
.trim()
.max(128 * 1024),
html: Joi.string()
.allow('')
.trim()
.max(128 * 1024),
start: Joi.date().empty('').allow(false),
end: Joi.date().empty('').allow(false),
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 @@ -95,14 +119,58 @@ module.exports = (db, server) => {
);

server.get(
'/users/:user/autoreply',
{
path: '/users/:user/autoreply',
tags: ['Autoreplies'],
summary: 'Request Autoreply information',
validationObjs: {
requestBody: {},
queryParams: {
sess: sessSchema,
ip: sessIPSchema
},
pathParams: { user: userId },
response: {
200: {
description: 'Success',
model: Joi.object({
success: successRes,
status: booleanSchema.description('Is the autoreply enabled (true) or not (false)'),
name: Joi.string().allow('').trim().max(128).description('Name that is used for the From: header in autoreply message'),
subject: Joi.string()
.allow('')
.trim()
.max(2 * 1024)
.description('Subject line for the autoreply. If empty then uses subject of the original message'),
text: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('Plaintext formatted content of the autoreply message'),
html: Joi.string()
.allow('')
.trim()
.max(128 * 1024)
.description('HTML formatted content of the autoreply message'),
start: Joi.date()
.empty('')
.allow(false)
.description('Datestring of the start of the autoreply or boolean false to disable start checks'),
end: Joi.date().empty('').allow(false).description('Datestring of the end of the autoreply or boolean false to disable end checks')
})
}
}
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
user: Joi.string().hex().lowercase().length(24).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 @@ -145,14 +213,31 @@ module.exports = (db, server) => {
);

server.del(
'/users/:user/autoreply',
{
path: '/users/:user/autoreply',
tags: ['Autoreplies'],
summary: 'Delete Autoreply information',
validationObjs: {
requestBody: {},
queryParams: {
sess: sessSchema,
ip: sessIPSchema
},
pathParams: {
user: userId
},
reponse: { 200: { description: 'Success', model: Joi.object({ success: successRes }) } }
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
user: Joi.string().hex().lowercase().length(24).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

0 comments on commit aa60ef9

Please sign in to comment.