Skip to content

Commit

Permalink
Added List registered webhooks api endpoint to api docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed May 6, 2024
1 parent e6a99bf commit 254efca
Showing 1 changed file with 54 additions and 11 deletions.
65 changes: 54 additions & 11 deletions lib/api/webhooks.js
Expand Up @@ -6,23 +6,66 @@ const ObjectId = require('mongodb').ObjectId;
const tools = require('../tools');
const roles = require('../roles');
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema } = require('../schemas');
const { successRes } = require('../schemas/response/general-schemas');
const { successRes, totalRes, pageRes, previousCursorRes, nextCursorRes } = require('../schemas/response/general-schemas');

module.exports = (db, server) => {
server.get(
{ name: 'webhooks', path: '/webhooks' },
{
name: 'webhooks',
path: '/webhooks',
tags: ['Webhooks'],
summary: 'List registered Webhooks',
validationObjs: {
requestBody: {},
queryParams: {
type: Joi.string()
.empty('')
.lowercase()
.max(128)
.description('Prefix or exact match. Prefix match must end with ".*", eg "channel.*". Use "*" for all types'),
user: Joi.string().hex().lowercase().length(24).description('User ID'),
limit: Joi.number().default(20).min(1).max(250).description('How many records to return'),
next: nextPageCursorSchema,
previous: previousPageCursorSchema,
page: pageNrSchema,
sess: sessSchema,
ip: sessIPSchema
},
pathParams: {},
response: {
200: {
description: 'Success',
model: Joi.object({
success: successRes,
total: totalRes,
page: pageRes,
previousCursor: previousCursorRes,
nextCursor: nextCursorRes,
results: Joi.array()
.items(
Joi.object({
id: Joi.string().required().description('Webhooks unique ID (24 byte hex)'),
type: Joi.array().items(Joi.string()).required().description('An array of event types this webhook matches'),
user: Joi.string().required().description('User ID or null'),
url: Joi.string().required().description('Webhook URL')
}).$_setFlag('objectName', 'GetWebhooksResult')
)
.required()
.description('Webhook listing')
})
}
}
}
},
tools.responseWrapper(async (req, res) => {
res.charSet('utf-8');

const schema = Joi.object().keys({
type: Joi.string().empty('').lowercase().max(128),
user: Joi.string().hex().lowercase().length(24),
limit: Joi.number().default(20).min(1).max(250),
next: nextPageCursorSchema,
previous: previousPageCursorSchema,
page: pageNrSchema,
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 254efca

Please sign in to comment.