mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-11-10 17:47:07 +08:00
fix(api-autoreply): Autoreply API endpoints added to API docs generation 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
This commit is contained in:
parent
7e9e62ea7a
commit
aa60ef93fe
1 changed files with 116 additions and 31 deletions
|
@ -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, {
|
||||
|
@ -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, {
|
||||
|
@ -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, {
|
||||
|
|
Loading…
Reference in a new issue