diff --git a/src/api/routes/applications/#id/index.ts b/src/api/routes/applications/#id/index.ts
index 067f5dad..c372869a 100644
--- a/src/api/routes/applications/#id/index.ts
+++ b/src/api/routes/applications/#id/index.ts
@@ -16,32 +16,55 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import { Request, Response, Router } from "express";
import { route } from "@spacebar/api";
import {
Application,
- DiscordApiErrors,
ApplicationModifySchema,
+ DiscordApiErrors,
} from "@spacebar/util";
-import { verifyToken } from "node-2fa";
+import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
+import { verifyToken } from "node-2fa";
const router: Router = Router();
-router.get("/", route({}), async (req: Request, res: Response) => {
- const app = await Application.findOneOrFail({
- where: { id: req.params.id },
- relations: ["owner", "bot"],
- });
- if (app.owner.id != req.user_id)
- throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
+router.get(
+ "/",
+ route({
+ responses: {
+ 200: {
+ body: "Application",
+ },
+ 400: {
+ body: "APIErrorResponse",
+ },
+ },
+ }),
+ async (req: Request, res: Response) => {
+ const app = await Application.findOneOrFail({
+ where: { id: req.params.id },
+ relations: ["owner", "bot"],
+ });
+ if (app.owner.id != req.user_id)
+ throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
- return res.json(app);
-});
+ return res.json(app);
+ },
+);
router.patch(
"/",
- route({ body: "ApplicationModifySchema" }),
+ route({
+ requestBody: "ApplicationModifySchema",
+ responses: {
+ 200: {
+ body: "Application",
+ },
+ 400: {
+ body: "APIErrorResponse",
+ },
+ },
+ }),
async (req: Request, res: Response) => {
const body = req.body as ApplicationModifySchema;
@@ -73,23 +96,35 @@ router.patch(
},
);
-router.post("/delete", route({}), async (req: Request, res: Response) => {
- const app = await Application.findOneOrFail({
- where: { id: req.params.id },
- relations: ["bot", "owner"],
- });
- if (app.owner.id != req.user_id)
- throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
+router.post(
+ "/delete",
+ route({
+ responses: {
+ 200: {},
+ 400: {
+ body: "APIErrorResponse",
+ },
+ },
+ }),
+ async (req: Request, res: Response) => {
+ const app = await Application.findOneOrFail({
+ where: { id: req.params.id },
+ relations: ["bot", "owner"],
+ });
+ if (app.owner.id != req.user_id)
+ throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
- if (
- app.owner.totp_secret &&
- (!req.body.code || verifyToken(app.owner.totp_secret, req.body.code))
- )
- throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
+ if (
+ app.owner.totp_secret &&
+ (!req.body.code ||
+ verifyToken(app.owner.totp_secret, req.body.code))
+ )
+ throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
- await Application.delete({ id: app.id });
+ await Application.delete({ id: app.id });
- res.send().status(200);
-});
+ res.send().status(200);
+ },
+);
export default router;
|