Skip to content

Commit aa60ef9

Browse files
authored
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
1 parent 7e9e62e commit aa60ef9

File tree

1 file changed

+116
-31
lines changed

1 file changed

+116
-31
lines changed

lib/api/autoreply.js

Lines changed: 116 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,57 @@ const tools = require('../tools');
66
const roles = require('../roles');
77
const { sessSchema, sessIPSchema, booleanSchema } = require('../schemas');
88
const { publish, AUTOREPLY_USER_DISABLED, AUTOREPLY_USER_ENABLED } = require('../events');
9+
const { userId } = require('../schemas/request/general-schemas');
10+
const { successRes } = require('../schemas/response/general-schemas');
911

1012
module.exports = (db, server) => {
1113
server.put(
12-
'/users/:user/autoreply',
14+
{
15+
path: '/users/:user/autoreply',
16+
tags: ['Autoreplies'],
17+
summary: 'Update Autoreply information',
18+
validationObjs: {
19+
requestBody: {
20+
status: booleanSchema.description('Is the autoreply enabled (true) or not (false)'),
21+
name: Joi.string().allow('').trim().max(128).description('Name that is used for the From: header in autoreply message'),
22+
subject: Joi.string()
23+
.allow('')
24+
.trim()
25+
.max(2 * 1024)
26+
.description('Subject line for the autoreply. If empty then uses subject of the original message'),
27+
text: Joi.string()
28+
.allow('')
29+
.trim()
30+
.max(128 * 1024)
31+
.description('Plaintext formatted content of the autoreply message'),
32+
html: Joi.string()
33+
.allow('')
34+
.trim()
35+
.max(128 * 1024)
36+
.description('HTML formatted content of the autoreply message'),
37+
start: Joi.date().empty('').allow(false).description('Datestring of the start of the autoreply or boolean false to disable start checks'),
38+
end: Joi.date().empty('').allow(false).description('Datestring of the end of the autoreply or boolean false to disable end checks'),
39+
sess: sessSchema,
40+
ip: sessIPSchema
41+
},
42+
queryParams: {},
43+
pathParams: {
44+
user: userId
45+
},
46+
response: {
47+
200: { description: 'Success', model: Joi.object({ success: successRes, id: Joi.string().required().description('Autoreply ID') }) }
48+
}
49+
}
50+
},
1351
tools.responseWrapper(async (req, res) => {
1452
res.charSet('utf-8');
1553

16-
const schema = Joi.object().keys({
17-
user: Joi.string().hex().lowercase().length(24).required(),
18-
status: booleanSchema,
19-
name: Joi.string().allow('').trim().max(128),
20-
subject: Joi.string()
21-
.allow('')
22-
.trim()
23-
.max(2 * 1024),
24-
text: Joi.string()
25-
.allow('')
26-
.trim()
27-
.max(128 * 1024),
28-
html: Joi.string()
29-
.allow('')
30-
.trim()
31-
.max(128 * 1024),
32-
start: Joi.date().empty('').allow(false),
33-
end: Joi.date().empty('').allow(false),
34-
sess: sessSchema,
35-
ip: sessIPSchema
54+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
55+
56+
const schema = Joi.object({
57+
...pathParams,
58+
...requestBody,
59+
...queryParams
3660
});
3761

3862
const result = schema.validate(req.params, {
@@ -95,14 +119,58 @@ module.exports = (db, server) => {
95119
);
96120

97121
server.get(
98-
'/users/:user/autoreply',
122+
{
123+
path: '/users/:user/autoreply',
124+
tags: ['Autoreplies'],
125+
summary: 'Request Autoreply information',
126+
validationObjs: {
127+
requestBody: {},
128+
queryParams: {
129+
sess: sessSchema,
130+
ip: sessIPSchema
131+
},
132+
pathParams: { user: userId },
133+
response: {
134+
200: {
135+
description: 'Success',
136+
model: Joi.object({
137+
success: successRes,
138+
status: booleanSchema.description('Is the autoreply enabled (true) or not (false)'),
139+
name: Joi.string().allow('').trim().max(128).description('Name that is used for the From: header in autoreply message'),
140+
subject: Joi.string()
141+
.allow('')
142+
.trim()
143+
.max(2 * 1024)
144+
.description('Subject line for the autoreply. If empty then uses subject of the original message'),
145+
text: Joi.string()
146+
.allow('')
147+
.trim()
148+
.max(128 * 1024)
149+
.description('Plaintext formatted content of the autoreply message'),
150+
html: Joi.string()
151+
.allow('')
152+
.trim()
153+
.max(128 * 1024)
154+
.description('HTML formatted content of the autoreply message'),
155+
start: Joi.date()
156+
.empty('')
157+
.allow(false)
158+
.description('Datestring of the start of the autoreply or boolean false to disable start checks'),
159+
end: Joi.date().empty('').allow(false).description('Datestring of the end of the autoreply or boolean false to disable end checks')
160+
})
161+
}
162+
}
163+
}
164+
},
99165
tools.responseWrapper(async (req, res) => {
100166
res.charSet('utf-8');
101167

102-
const schema = Joi.object().keys({
103-
user: Joi.string().hex().lowercase().length(24).required(),
104-
sess: sessSchema,
105-
ip: sessIPSchema
168+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
169+
170+
const schema = Joi.object({
171+
...pathParams,
172+
...requestBody,
173+
...queryParams
106174
});
107175

108176
const result = schema.validate(req.params, {
@@ -145,14 +213,31 @@ module.exports = (db, server) => {
145213
);
146214

147215
server.del(
148-
'/users/:user/autoreply',
216+
{
217+
path: '/users/:user/autoreply',
218+
tags: ['Autoreplies'],
219+
summary: 'Delete Autoreply information',
220+
validationObjs: {
221+
requestBody: {},
222+
queryParams: {
223+
sess: sessSchema,
224+
ip: sessIPSchema
225+
},
226+
pathParams: {
227+
user: userId
228+
},
229+
reponse: { 200: { description: 'Success', model: Joi.object({ success: successRes }) } }
230+
}
231+
},
149232
tools.responseWrapper(async (req, res) => {
150233
res.charSet('utf-8');
151234

152-
const schema = Joi.object().keys({
153-
user: Joi.string().hex().lowercase().length(24).required(),
154-
sess: sessSchema,
155-
ip: sessIPSchema
235+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
236+
237+
const schema = Joi.object({
238+
...pathParams,
239+
...requestBody,
240+
...queryParams
156241
});
157242

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

0 commit comments

Comments
 (0)