Skip to content

Commit 5af8126

Browse files
authored
fix(api-domainaliases): Added DomainAliases API endpoints to API docs generation ZMS-132 (#641)
* added List registered Domain Aliases endpoint to API docs generation * added Create new Domain Alias API endpoint to API docs generation * added Resolve ID for a domain alias API endpoint to API docs generation * added Delete an Alias API endpoint to API docs generation * Added Request Alias information API endpoint to API docs generation
1 parent 64c6b5e commit 5af8126

File tree

1 file changed

+162
-35
lines changed

1 file changed

+162
-35
lines changed

lib/api/domainaliases.js

+162-35
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,60 @@ const tools = require('../tools');
77
const roles = require('../roles');
88
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema } = require('../schemas');
99
const { publish, DOMAINALIAS_CREATED, DOMAINALIAS_DELETED } = require('../events');
10+
const { successRes, totalRes, pageRes, previousCursorRes, nextCursorRes } = require('../schemas/response/general-schemas');
1011

1112
module.exports = (db, server) => {
1213
server.get(
13-
{ name: 'domainaliases', path: '/domainaliases' },
14+
{
15+
name: 'domainaliases',
16+
path: '/domainaliases',
17+
tags: ['DomainAliases'],
18+
summary: 'List registered Domain Aliases',
19+
validationObjs: {
20+
requestBody: {},
21+
pathParams: {},
22+
queryParams: {
23+
query: Joi.string().trim().empty('').max(255).description('Partial match of a Domain Alias or Domain name'),
24+
limit: Joi.number().default(20).min(1).max(250).description('How many records to return'),
25+
next: nextPageCursorSchema,
26+
previous: previousPageCursorSchema,
27+
page: pageNrSchema,
28+
sess: sessSchema,
29+
ip: sessIPSchema
30+
},
31+
response: {
32+
200: {
33+
descrition: 'Success',
34+
model: Joi.object({
35+
success: successRes,
36+
total: totalRes,
37+
page: pageRes,
38+
previousCursor: previousCursorRes,
39+
nextCursor: nextCursorRes,
40+
results: Joi.array()
41+
.items(
42+
Joi.object({
43+
id: Joi.string().required().description('ID of the Domain Alias'),
44+
alias: Joi.string().required().description('Domain Alias'),
45+
domain: Joi.string().required().description('The domain this alias applies to')
46+
}).$_setFlag('objectName', 'GetDomainAliasesResult')
47+
)
48+
.required()
49+
.description('Aliases listing')
50+
})
51+
}
52+
}
53+
}
54+
},
1455
tools.responseWrapper(async (req, res) => {
1556
res.charSet('utf-8');
1657

17-
const schema = Joi.object().keys({
18-
query: Joi.string().trim().empty('').max(255),
19-
limit: Joi.number().default(20).min(1).max(250),
20-
next: nextPageCursorSchema,
21-
previous: previousPageCursorSchema,
22-
page: pageNrSchema,
23-
sess: sessSchema,
24-
ip: sessIPSchema
58+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
59+
60+
const schema = Joi.object({
61+
...pathParams,
62+
...queryParams,
63+
...requestBody
2564
});
2665

2766
const result = schema.validate(req.params, {
@@ -127,21 +166,45 @@ module.exports = (db, server) => {
127166
);
128167

129168
server.post(
130-
'/domainaliases',
169+
{
170+
path: '/domainaliases',
171+
tags: ['DomainAliases'],
172+
summary: 'Create new Domain Alias',
173+
description: 'Add a new Alias for a Domain. This allows to accept mail on username@domain and username@alias',
174+
validationObjs: {
175+
requestBody: {
176+
alias: Joi.string()
177+
.max(255)
178+
//.hostname()
179+
.required()
180+
.description('Domain Alias'),
181+
domain: Joi.string()
182+
.max(255)
183+
//.hostname()
184+
.required()
185+
.description('Domain name this Alias applies to'),
186+
sess: sessSchema,
187+
ip: sessIPSchema
188+
},
189+
queryParams: {},
190+
pathParams: {},
191+
response: {
192+
200: {
193+
description: 'Success',
194+
model: Joi.object({ success: successRes, id: Joi.string().required().description('ID of the Domain Alias') })
195+
}
196+
}
197+
}
198+
},
131199
tools.responseWrapper(async (req, res) => {
132200
res.charSet('utf-8');
133201

134-
const schema = Joi.object().keys({
135-
alias: Joi.string()
136-
.max(255)
137-
//.hostname()
138-
.required(),
139-
domain: Joi.string()
140-
.max(255)
141-
//.hostname()
142-
.required(),
143-
sess: sessSchema,
144-
ip: sessIPSchema
202+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
203+
204+
const schema = Joi.object({
205+
...pathParams,
206+
...queryParams,
207+
...requestBody
145208
});
146209

147210
const result = schema.validate(req.params, {
@@ -225,17 +288,40 @@ module.exports = (db, server) => {
225288
);
226289

227290
server.get(
228-
'/domainaliases/resolve/:alias',
291+
{
292+
path: '/domainaliases/resolve/:alias',
293+
tags: ['DomainAliases'],
294+
summary: 'Resolve ID for a domain alias',
295+
validationObjs: {
296+
requestBody: {},
297+
pathParams: {
298+
alias: Joi.string()
299+
.max(255)
300+
//.hostname()
301+
.required()
302+
.description('Alias domain')
303+
},
304+
queryParams: {
305+
sess: sessSchema,
306+
ip: sessIPSchema
307+
},
308+
response: {
309+
200: {
310+
description: 'Success',
311+
model: Joi.object({ success: successRes, id: Joi.string().required().description('Unique ID (24 byte hex)') })
312+
}
313+
}
314+
}
315+
},
229316
tools.responseWrapper(async (req, res) => {
230317
res.charSet('utf-8');
231318

232-
const schema = Joi.object().keys({
233-
alias: Joi.string()
234-
.max(255)
235-
//.hostname()
236-
.required(),
237-
sess: sessSchema,
238-
ip: sessIPSchema
319+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
320+
321+
const schema = Joi.object({
322+
...pathParams,
323+
...queryParams,
324+
...requestBody
239325
});
240326

241327
const result = schema.validate(req.params, {
@@ -291,14 +377,42 @@ module.exports = (db, server) => {
291377
);
292378

293379
server.get(
294-
'/domainaliases/:alias',
380+
{
381+
path: '/domainaliases/:alias',
382+
tags: ['DomainAliases'],
383+
summary: 'Request Alias information',
384+
validationObjs: {
385+
requestBody: {},
386+
queryParams: {
387+
sess: sessSchema,
388+
ip: sessIPSchema
389+
},
390+
pathParams: {
391+
alias: Joi.string().hex().lowercase().length(24).required().description('ID of the Alias')
392+
},
393+
response: {
394+
200: {
395+
description: 'Success',
396+
model: Joi.object({
397+
success: successRes,
398+
id: Joi.string().required().description('ID of the Alias'),
399+
alias: Joi.string().required().description('Alias domain'),
400+
domain: Joi.string().required().description('Alias target'),
401+
created: Joi.date().required().description('Datestring of the time the alias was created')
402+
})
403+
}
404+
}
405+
}
406+
},
295407
tools.responseWrapper(async (req, res) => {
296408
res.charSet('utf-8');
297409

298-
const schema = Joi.object().keys({
299-
alias: Joi.string().hex().lowercase().length(24).required(),
300-
sess: sessSchema,
301-
ip: sessIPSchema
410+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
411+
412+
const schema = Joi.object({
413+
...pathParams,
414+
...queryParams,
415+
...requestBody
302416
});
303417

304418
const result = schema.validate(req.params, {
@@ -352,7 +466,20 @@ module.exports = (db, server) => {
352466
);
353467

354468
server.del(
355-
'/domainaliases/:alias',
469+
{
470+
path: '/domainaliases/:alias',
471+
tags: ['DomainAliases'],
472+
summary: 'Delete an Alias',
473+
validationObjs: {
474+
requestBody: {},
475+
pathParams: { alias: Joi.string().hex().lowercase().length(24).required().description('ID of the Alias') },
476+
queryParams: {
477+
sess: sessSchema,
478+
ip: sessIPSchema
479+
},
480+
response: { 200: { description: 'Success', model: Joi.object({ success: successRes }) } }
481+
}
482+
},
356483
tools.responseWrapper(async (req, res) => {
357484
res.charSet('utf-8');
358485

0 commit comments

Comments
 (0)