summary refs log tree commit diff
path: root/src/api/routes/applications/#id
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-01-05 17:12:21 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-01-05 17:16:55 +1100
commitdf449169bde6c0576757700f68f2d406139cc846 (patch)
treef8bcbaf30ed3ed007d392a51614a134e543e3c17 /src/api/routes/applications/#id
parentchannel flags whoops (diff)
downloadserver-df449169bde6c0576757700f68f2d406139cc846.tar.xz
Prettier
Diffstat (limited to 'src/api/routes/applications/#id')
-rw-r--r--src/api/routes/applications/#id/bot/index.ts65
-rw-r--r--src/api/routes/applications/#id/index.ts70
-rw-r--r--src/api/routes/applications/#id/skus.ts2
3 files changed, 90 insertions, 47 deletions
diff --git a/src/api/routes/applications/#id/bot/index.ts b/src/api/routes/applications/#id/bot/index.ts
index c21e19ca..c4cfccd8 100644
--- a/src/api/routes/applications/#id/bot/index.ts
+++ b/src/api/routes/applications/#id/bot/index.ts
@@ -1,13 +1,23 @@
 import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
-import { Application, generateToken, User, BotModifySchema, handleFile, DiscordApiErrors } from "@fosscord/util";
+import {
+	Application,
+	generateToken,
+	User,
+	BotModifySchema,
+	handleFile,
+	DiscordApiErrors,
+} from "@fosscord/util";
 import { HTTPError } from "lambert-server";
 import { verifyToken } from "node-2fa";
 
 const router: Router = Router();
 
 router.post("/", route({}), async (req: Request, res: Response) => {
-	const app = await Application.findOneOrFail({ where: { id: req.params.id }, relations: ["owner"] });
+	const app = await Application.findOneOrFail({
+		where: { id: req.params.id },
+		relations: ["owner"],
+	});
 
 	if (app.owner.id != req.user_id)
 		throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
@@ -31,7 +41,7 @@ router.post("/", route({}), async (req: Request, res: Response) => {
 	await app.save();
 
 	res.send({
-		token: await generateToken(user.id)
+		token: await generateToken(user.id),
 	}).status(204);
 });
 
@@ -42,7 +52,10 @@ router.post("/reset", route({}), async (req: Request, res: Response) => {
 	if (owner.id != req.user_id)
 		throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
 
-	if (owner.totp_secret && (!req.body.code || verifyToken(owner.totp_secret, req.body.code)))
+	if (
+		owner.totp_secret &&
+		(!req.body.code || verifyToken(owner.totp_secret, req.body.code))
+	)
 		throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
 
 	bot.data = { hash: undefined, valid_tokens_since: new Date() };
@@ -54,30 +67,36 @@ router.post("/reset", route({}), async (req: Request, res: Response) => {
 	res.json({ token }).status(200);
 });
 
-router.patch("/", route({ body: "BotModifySchema" }), async (req: Request, res: Response) => {
-	const body = req.body as BotModifySchema;
-	if (!body.avatar?.trim()) delete body.avatar;
+router.patch(
+	"/",
+	route({ body: "BotModifySchema" }),
+	async (req: Request, res: Response) => {
+		const body = req.body as BotModifySchema;
+		if (!body.avatar?.trim()) delete body.avatar;
 
-	const app = await Application.findOneOrFail({ where: { id: req.params.id }, relations: ["bot", "owner"] });
+		const app = await Application.findOneOrFail({
+			where: { id: req.params.id },
+			relations: ["bot", "owner"],
+		});
 
-	if (!app.bot)
-		throw DiscordApiErrors.BOT_ONLY_ENDPOINT;
+		if (!app.bot) throw DiscordApiErrors.BOT_ONLY_ENDPOINT;
 
-	if (app.owner.id != req.user_id)
-		throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
+		if (app.owner.id != req.user_id)
+			throw DiscordApiErrors.ACTION_NOT_AUTHORIZED_ON_APPLICATION;
 
-	if (body.avatar)
-		body.avatar = await handleFile(
-			`/avatars/${app.id}`,
-			body.avatar as string,
-		);
+		if (body.avatar)
+			body.avatar = await handleFile(
+				`/avatars/${app.id}`,
+				body.avatar as string,
+			);
 
-	app.bot.assign(body);
+		app.bot.assign(body);
 
-	app.bot.save();
+		app.bot.save();
 
-	await app.save();
-	res.json(app).status(200);
-});
+		await app.save();
+		res.json(app).status(200);
+	},
+);
 
-export default router;
\ No newline at end of file
+export default router;
diff --git a/src/api/routes/applications/#id/index.ts b/src/api/routes/applications/#id/index.ts
index 79df256a..11cd5a56 100644
--- a/src/api/routes/applications/#id/index.ts
+++ b/src/api/routes/applications/#id/index.ts
@@ -1,57 +1,81 @@
 import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
-import { Application, OrmUtils, DiscordApiErrors, ApplicationModifySchema, User } from "@fosscord/util";
+import {
+	Application,
+	OrmUtils,
+	DiscordApiErrors,
+	ApplicationModifySchema,
+	User,
+} from "@fosscord/util";
 import { verifyToken } from "node-2fa";
 import { HTTPError } from "lambert-server";
 
 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"] });
+	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);
 });
 
-router.patch("/", route({ body: "ApplicationModifySchema" }), async (req: Request, res: Response) => {
-	const body = req.body as ApplicationModifySchema;
+router.patch(
+	"/",
+	route({ body: "ApplicationModifySchema" }),
+	async (req: Request, res: Response) => {
+		const body = req.body as ApplicationModifySchema;
 
-	const app = await Application.findOneOrFail({ where: { id: req.params.id }, relations: ["owner", "bot"] });
+		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;
+		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);
 
-	if (app.bot) {
-		app.bot.assign({ bio: body.description });
-		await app.bot.save();
-	}
+		if (app.bot) {
+			app.bot.assign({ bio: body.description });
+			await app.bot.save();
+		}
 
-	app.assign(body);
+		app.assign(body);
 
-	await app.save();
+		await app.save();
 
-	return res.json(app);
-});
+		return res.json(app);
+	},
+);
 
 router.post("/delete", route({}), async (req: Request, res: Response) => {
-	const app = await Application.findOneOrFail({ where: { id: req.params.id }, relations: ["bot", "owner"] });
+	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)))
+	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.bot)
-		await User.delete({ id: app.bot.id });
+	if (app.bot) await User.delete({ id: app.bot.id });
 
 	await Application.delete({ id: app.id });
 
 	res.send().status(200);
 });
 
-
-export default router;
\ No newline at end of file
+export default router;
diff --git a/src/api/routes/applications/#id/skus.ts b/src/api/routes/applications/#id/skus.ts
index 5b667f36..2383e6f7 100644
--- a/src/api/routes/applications/#id/skus.ts
+++ b/src/api/routes/applications/#id/skus.ts
@@ -8,4 +8,4 @@ router.get("/", route({}), async (req: Request, res: Response) => {
 	res.json([]).status(200);
 });
 
-export default router;
\ No newline at end of file
+export default router;