Adding Basic API Documentation
This commit is contained in:
@ -1,29 +1,60 @@
|
||||
import { Router, Request } from "express";
|
||||
import { GetUserMiddleware } from "../middlewares/user";
|
||||
import RequestError, { HttpStatusCode } from "../../helper/request_error";
|
||||
import promiseMiddleware from "../../helper/promiseMiddleware";
|
||||
import Client from "../../models/client";
|
||||
import User from "../../models/user";
|
||||
import verify, { Types } from "../middlewares/verify";
|
||||
import { randomBytes } from "crypto";
|
||||
|
||||
|
||||
const ClientRouter: Router = Router();
|
||||
ClientRouter.use(GetUserMiddleware(true, true), (req: Request, res, next) => {
|
||||
if (!req.isAdmin) res.sendStatus(HttpStatusCode.FORBIDDEN)
|
||||
else next()
|
||||
});
|
||||
ClientRouter.route("/")
|
||||
/**
|
||||
* @api {get} /admin/client
|
||||
* @apiName AdminGetClients
|
||||
*
|
||||
* @apiGroup admin_client
|
||||
* @apiPermission admin
|
||||
*
|
||||
* @apiSuccess {Object[]} clients
|
||||
* @apiSuccess {String} clients._id The internally used id
|
||||
* @apiSuccess {String} clients.maintainer
|
||||
* @apiSuccess {Boolean} clients.internal
|
||||
* @apiSuccess {String} clients.name
|
||||
* @apiSuccess {String} clients.redirect_url
|
||||
* @apiSuccess {String} clients.website
|
||||
* @apiSuccess {String} clients.logo
|
||||
* @apiSuccess {String} clients.client_id Client ID used outside of DB
|
||||
* @apiSuccess {String} clients.client_secret
|
||||
*/
|
||||
.get(promiseMiddleware(async (req, res) => {
|
||||
let clients = await Client.find({});
|
||||
//ToDo check if user is required!
|
||||
res.json(clients);
|
||||
}))
|
||||
.delete(promiseMiddleware(async (req, res) => {
|
||||
let { id } = req.query;
|
||||
await Client.delete(id);
|
||||
res.json({ success: true });
|
||||
}))
|
||||
/**
|
||||
* @api {get} /admin/client
|
||||
* @apiName AdminAddClients
|
||||
*
|
||||
* @apiGroup admin_client
|
||||
* @apiPermission admin
|
||||
*
|
||||
* @apiParam {Boolean} internal Is it an internal app
|
||||
* @apiParam {String} name
|
||||
* @apiParam {String} redirect_url
|
||||
* @apiParam {String} website
|
||||
* @apiParam {String} logo
|
||||
*
|
||||
* @apiSuccess {Object[]} clients
|
||||
* @apiSuccess {String} clients._id The internally used id
|
||||
* @apiSuccess {String} clients.maintainer
|
||||
* @apiSuccess {Boolean} clients.internal
|
||||
* @apiSuccess {String} clients.name
|
||||
* @apiSuccess {String} clients.redirect_url
|
||||
* @apiSuccess {String} clients.website
|
||||
* @apiSuccess {String} clients.logo
|
||||
* @apiSuccess {String} clients.client_id Client ID used outside of DB
|
||||
* @apiSuccess {String} clients.client_secret
|
||||
*/
|
||||
.post(verify({
|
||||
internal: {
|
||||
type: Types.BOOLEAN,
|
||||
@ -49,11 +80,48 @@ ClientRouter.route("/")
|
||||
await Client.save(client)
|
||||
res.json(client);
|
||||
}))
|
||||
|
||||
ClientRouter.route("/:id")
|
||||
/**
|
||||
* @api {delete} /admin/client/:id
|
||||
* @apiParam {String} id Client _id
|
||||
* @apiName AdminDeleteClient
|
||||
*
|
||||
* @apiGroup admin_client
|
||||
* @apiPermission admin
|
||||
*
|
||||
* @apiSuccess {Boolean} success
|
||||
*/
|
||||
.delete(promiseMiddleware(async (req, res) => {
|
||||
let { id } = req.params;
|
||||
await Client.delete(id);
|
||||
res.json({ success: true });
|
||||
}))
|
||||
/**
|
||||
* @api {put} /admin/client/:id
|
||||
* @apiParam {String} id Client _id
|
||||
* @apiName AdminUpdateClient
|
||||
*
|
||||
* @apiGroup admin_client
|
||||
* @apiPermission admin
|
||||
*
|
||||
* @apiParam {Boolean} internal Is it an internal app
|
||||
* @apiParam {String} name
|
||||
* @apiParam {String} redirect_url
|
||||
* @apiParam {String} website
|
||||
* @apiParam {String} logo
|
||||
*
|
||||
* @apiSuccess {String} _id The internally used id
|
||||
* @apiSuccess {String} maintainer UserID of client maintainer
|
||||
* @apiSuccess {Boolean} internal Defines if it is a internal client
|
||||
* @apiSuccess {String} name The name of the Client
|
||||
* @apiSuccess {String} redirect_url Redirect URL after login
|
||||
* @apiSuccess {String} website Website of Client
|
||||
* @apiSuccess {String} logo The Logo of the Client (optional)
|
||||
* @apiSuccess {String} client_id Client ID used outside of DB
|
||||
* @apiSuccess {String} client_secret The client secret, that can be used to obtain token
|
||||
*/
|
||||
.put(verify({
|
||||
id: {
|
||||
type: Types.STRING,
|
||||
query: true
|
||||
},
|
||||
internal: {
|
||||
type: Types.BOOLEAN,
|
||||
optional: true
|
||||
@ -85,4 +153,5 @@ ClientRouter.route("/")
|
||||
res.json(client);
|
||||
}))
|
||||
|
||||
|
||||
export default ClientRouter;
|
Reference in New Issue
Block a user