summary refs log tree commit diff
path: root/src/api/routes/users/@me
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/routes/users/@me')
-rw-r--r--src/api/routes/users/@me/activities/statistics/applications.ts2
-rw-r--r--src/api/routes/users/@me/affinities/guilds.ts2
-rw-r--r--src/api/routes/users/@me/affinities/users.ts2
-rw-r--r--src/api/routes/users/@me/applications/#app_id/entitlements.ts2
-rw-r--r--src/api/routes/users/@me/billing/country-code.ts2
-rw-r--r--src/api/routes/users/@me/billing/payment-sources.ts2
-rw-r--r--src/api/routes/users/@me/billing/subscriptions.ts2
-rw-r--r--src/api/routes/users/@me/channels.ts4
-rw-r--r--src/api/routes/users/@me/connections.ts2
-rw-r--r--src/api/routes/users/@me/devices.ts2
-rw-r--r--src/api/routes/users/@me/disable.ts2
-rw-r--r--src/api/routes/users/@me/email-settings.ts2
-rw-r--r--src/api/routes/users/@me/entitlements.ts2
-rw-r--r--src/api/routes/users/@me/guilds.ts5
-rw-r--r--src/api/routes/users/@me/guilds/premium/subscription-slots.ts2
-rw-r--r--src/api/routes/users/@me/index.ts20
-rw-r--r--src/api/routes/users/@me/library.ts2
-rw-r--r--src/api/routes/users/@me/mfa/codes.ts18
-rw-r--r--src/api/routes/users/@me/mfa/totp/disable.ts19
-rw-r--r--src/api/routes/users/@me/mfa/totp/enable.ts24
-rw-r--r--src/api/routes/users/@me/notes.ts27
-rw-r--r--src/api/routes/users/@me/relationships.ts39
-rw-r--r--src/api/routes/users/@me/settings.ts4
23 files changed, 90 insertions, 98 deletions
diff --git a/src/api/routes/users/@me/activities/statistics/applications.ts b/src/api/routes/users/@me/activities/statistics/applications.ts
index 014df8af..ba359b47 100644
--- a/src/api/routes/users/@me/activities/statistics/applications.ts
+++ b/src/api/routes/users/@me/activities/statistics/applications.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/affinities/guilds.ts b/src/api/routes/users/@me/affinities/guilds.ts
index 8d744744..e733910f 100644
--- a/src/api/routes/users/@me/affinities/guilds.ts
+++ b/src/api/routes/users/@me/affinities/guilds.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/affinities/users.ts b/src/api/routes/users/@me/affinities/users.ts
index 6d4e4991..758bedc3 100644
--- a/src/api/routes/users/@me/affinities/users.ts
+++ b/src/api/routes/users/@me/affinities/users.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/applications/#app_id/entitlements.ts b/src/api/routes/users/@me/applications/#app_id/entitlements.ts
index 411e95bf..8e407184 100644
--- a/src/api/routes/users/@me/applications/#app_id/entitlements.ts
+++ b/src/api/routes/users/@me/applications/#app_id/entitlements.ts
@@ -1,5 +1,5 @@
-import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/users/@me/billing/country-code.ts b/src/api/routes/users/@me/billing/country-code.ts
index 33d40796..72601f42 100644
--- a/src/api/routes/users/@me/billing/country-code.ts
+++ b/src/api/routes/users/@me/billing/country-code.ts
@@ -1,5 +1,5 @@
-import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/users/@me/billing/payment-sources.ts b/src/api/routes/users/@me/billing/payment-sources.ts
index 014df8af..ba359b47 100644
--- a/src/api/routes/users/@me/billing/payment-sources.ts
+++ b/src/api/routes/users/@me/billing/payment-sources.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/billing/subscriptions.ts b/src/api/routes/users/@me/billing/subscriptions.ts
index 411e95bf..8e407184 100644
--- a/src/api/routes/users/@me/billing/subscriptions.ts
+++ b/src/api/routes/users/@me/billing/subscriptions.ts
@@ -1,5 +1,5 @@
-import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/users/@me/channels.ts b/src/api/routes/users/@me/channels.ts
index ad483529..c17275ec 100644
--- a/src/api/routes/users/@me/channels.ts
+++ b/src/api/routes/users/@me/channels.ts
@@ -1,6 +1,6 @@
-import { Request, Response, Router } from "express";
-import { Recipient, DmChannelDTO, Channel, DmChannelCreateSchema } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Channel, DmChannelCreateSchema, DmChannelDTO, Recipient } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/users/@me/connections.ts b/src/api/routes/users/@me/connections.ts
index 411e95bf..8e407184 100644
--- a/src/api/routes/users/@me/connections.ts
+++ b/src/api/routes/users/@me/connections.ts
@@ -1,5 +1,5 @@
-import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/users/@me/devices.ts b/src/api/routes/users/@me/devices.ts
index 8556a3ad..cb01e576 100644
--- a/src/api/routes/users/@me/devices.ts
+++ b/src/api/routes/users/@me/devices.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/disable.ts b/src/api/routes/users/@me/disable.ts
index 3a1d48b8..05976908 100644
--- a/src/api/routes/users/@me/disable.ts
+++ b/src/api/routes/users/@me/disable.ts
@@ -1,6 +1,6 @@
+import { route } from "@fosscord/api";
 import { User } from "@fosscord/util";
 import { Request, Response, Router } from "express";
-import { route } from "@fosscord/api";
 
 let bcrypt: any;
 try {
diff --git a/src/api/routes/users/@me/email-settings.ts b/src/api/routes/users/@me/email-settings.ts
index 3114984e..28d0864a 100644
--- a/src/api/routes/users/@me/email-settings.ts
+++ b/src/api/routes/users/@me/email-settings.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/entitlements.ts b/src/api/routes/users/@me/entitlements.ts
index 341e2b4c..7aaa5d7c 100644
--- a/src/api/routes/users/@me/entitlements.ts
+++ b/src/api/routes/users/@me/entitlements.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/guilds.ts b/src/api/routes/users/@me/guilds.ts
index 4d4fccd4..5141aa3d 100644
--- a/src/api/routes/users/@me/guilds.ts
+++ b/src/api/routes/users/@me/guilds.ts
@@ -1,7 +1,6 @@
-import { Router, Request, Response } from "express";
-import { Guild, Member, User, GuildDeleteEvent, GuildMemberRemoveEvent, emitEvent, Config } from "@fosscord/util";
-import { HTTPError } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { Config, emitEvent, Guild, GuildDeleteEvent, GuildMemberRemoveEvent, HTTPError, Member, User } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
diff --git a/src/api/routes/users/@me/guilds/premium/subscription-slots.ts b/src/api/routes/users/@me/guilds/premium/subscription-slots.ts
index 014df8af..ba359b47 100644
--- a/src/api/routes/users/@me/guilds/premium/subscription-slots.ts
+++ b/src/api/routes/users/@me/guilds/premium/subscription-slots.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/index.ts b/src/api/routes/users/@me/index.ts
index 4421d54f..fcb0a9df 100644
--- a/src/api/routes/users/@me/index.ts
+++ b/src/api/routes/users/@me/index.ts
@@ -53,17 +53,17 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
 		}
 		user.data.hash = await bcrypt.hash(body.new_password, 12);
 		user.data.valid_tokens_since = new Date();
-		token = await generateToken(user.id) as string;
+		token = (await generateToken(user.id)) as string;
 	}
 
-    if(body.username){
-        let check_username = body?.username?.replace(/\s/g, '');
-        if(!check_username) {
-            throw FieldErrors({
-                username: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
-            });
-        }
-    }
+	if (body.username) {
+		let check_username = body?.username?.replace(/\s/g, "");
+		if (!check_username) {
+			throw FieldErrors({
+				username: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }
+			});
+		}
+	}
 
 	user = OrmUtils.mergeDeep(user, body);
 	await user.save();
@@ -77,7 +77,7 @@ router.patch("/", route({ body: "UserModifySchema" }), async (req: Request, res:
 		user_id: req.user_id,
 		data: user
 	} as UserUpdateEvent);
-	
+
 	res.json({
 		...user,
 		token
diff --git a/src/api/routes/users/@me/library.ts b/src/api/routes/users/@me/library.ts
index 7ac13bae..0aea02a0 100644
--- a/src/api/routes/users/@me/library.ts
+++ b/src/api/routes/users/@me/library.ts
@@ -1,5 +1,5 @@
-import { Router, Response, Request } from "express";
 import { route } from "@fosscord/api";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
diff --git a/src/api/routes/users/@me/mfa/codes.ts b/src/api/routes/users/@me/mfa/codes.ts
index 8d90f993..c62581cc 100644
--- a/src/api/routes/users/@me/mfa/codes.ts
+++ b/src/api/routes/users/@me/mfa/codes.ts
@@ -19,25 +19,21 @@ router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Re
 
 	const user = await User.findOneOrFail({ where: { id: req.user_id }, select: ["data"] });
 
-	if (!await bcrypt.compare(password, user.data.hash || "")) {
+	if (!(await bcrypt.compare(password, user.data.hash || ""))) {
 		throw FieldErrors({ password: { message: req.t("auth:login.INVALID_PASSWORD"), code: "INVALID_PASSWORD" } });
 	}
 
 	var codes: BackupCode[];
 	if (regenerate && Config.get().security.twoFactor.generateBackupCodes) {
-		await BackupCode.update(
-			{ user: { id: req.user_id } },
-			{ expired: true }
-		);
+		await BackupCode.update({ user: { id: req.user_id } }, { expired: true });
 
 		codes = generateMfaBackupCodes(req.user_id);
-		await Promise.all(codes.map(x => x.save()));
-	}
-	else {
+		await Promise.all(codes.map((x) => x.save()));
+	} else {
 		codes = await BackupCode.find({
 			where: {
 				user: {
-					id: req.user_id,
+					id: req.user_id
 				},
 				expired: false
 			}
@@ -45,8 +41,8 @@ router.post("/", route({ body: "MfaCodesSchema" }), async (req: Request, res: Re
 	}
 
 	return res.json({
-		backup_codes: codes.map(x => ({ ...x, expired: undefined })),
-	})
+		backup_codes: codes.map((x) => ({ ...x, expired: undefined }))
+	});
 });
 
 export default router;
diff --git a/src/api/routes/users/@me/mfa/totp/disable.ts b/src/api/routes/users/@me/mfa/totp/disable.ts
index 2fe9355c..6bc9a5c7 100644
--- a/src/api/routes/users/@me/mfa/totp/disable.ts
+++ b/src/api/routes/users/@me/mfa/totp/disable.ts
@@ -1,8 +1,8 @@
-import { Router, Request, Response } from "express";
 import { route } from "@fosscord/api";
-import { verifyToken } from 'node-2fa';
+import { BackupCode, generateToken, TotpDisableSchema, User } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 import { HTTPError } from "lambert-server";
-import { User, generateToken, BackupCode, TotpDisableSchema } from "@fosscord/util";
+import { verifyToken } from "node-2fa";
 
 const router = Router();
 
@@ -14,28 +14,27 @@ router.post("/", route({ body: "TotpDisableSchema" }), async (req: Request, res:
 	const backup = await BackupCode.findOne({ where: { code: body.code } });
 	if (!backup) {
 		const ret = verifyToken(user.totp_secret!, body.code);
-		if (!ret || ret.delta != 0)
-			throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
+		if (!ret || ret.delta != 0) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
 	}
 
 	await User.update(
 		{ id: req.user_id },
 		{
 			mfa_enabled: false,
-			totp_secret: "",
-		},
+			totp_secret: ""
+		}
 	);
 
 	await BackupCode.update(
 		{ user: { id: req.user_id } },
 		{
-			expired: true,
+			expired: true
 		}
 	);
 
 	return res.json({
-		token: await generateToken(user.id),
+		token: await generateToken(user.id)
 	});
 });
 
-export default router;
\ No newline at end of file
+export default router;
diff --git a/src/api/routes/users/@me/mfa/totp/enable.ts b/src/api/routes/users/@me/mfa/totp/enable.ts
index a38a133a..f3a73c28 100644
--- a/src/api/routes/users/@me/mfa/totp/enable.ts
+++ b/src/api/routes/users/@me/mfa/totp/enable.ts
@@ -1,8 +1,8 @@
+import { route } from "@fosscord/api";
 import { BackupCode, Config, generateMfaBackupCodes, generateToken, TotpEnableSchema, User } from "@fosscord/util";
 import { Request, Response, Router } from "express";
 import { HTTPError } from "lambert-server";
-import { verifyToken } from 'node-2fa';
-import { route } from '@fosscord/api';
+import { verifyToken } from "node-2fa";
 
 let bcrypt: any;
 try {
@@ -21,34 +21,28 @@ router.post("/", route({ body: "TotpEnableSchema" }), async (req: Request, res:
 
 	// TODO: Are guests allowed to enable 2fa?
 	if (user.data.hash) {
-		if (!await bcrypt.compare(body.password, user.data.hash)) {
+		if (!(await bcrypt.compare(body.password, user.data.hash))) {
 			throw new HTTPError(req.t("auth:login.INVALID_PASSWORD"));
 		}
 	}
 
-	if (!body.secret)
-		throw new HTTPError(req.t("auth:login.INVALID_TOTP_SECRET"), 60005);
+	if (!body.secret) throw new HTTPError(req.t("auth:login.INVALID_TOTP_SECRET"), 60005);
 
-	if (!body.code)
-		throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
+	if (!body.code) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
 
-	if (verifyToken(body.secret, body.code)?.delta != 0)
-		throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
+	if (verifyToken(body.secret, body.code)?.delta != 0) throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
 
 	let backup_codes: BackupCode[] = [];
 	if (Config.get().security.twoFactor.generateBackupCodes) {
 		backup_codes = generateMfaBackupCodes(req.user_id);
-		await Promise.all(backup_codes.map(x => x.save()));
+		await Promise.all(backup_codes.map((x) => x.save()));
 	}
 
-	await User.update(
-		{ id: req.user_id },
-		{ mfa_enabled: true, totp_secret: body.secret }
-	);
+	await User.update({ id: req.user_id }, { mfa_enabled: true, totp_secret: body.secret });
 
 	res.send({
 		token: await generateToken(user.id),
-		backup_codes: backup_codes.map(x => ({ ...x, expired: undefined })),
+		backup_codes: backup_codes.map((x) => ({ ...x, expired: undefined }))
 	});
 });
 
diff --git a/src/api/routes/users/@me/notes.ts b/src/api/routes/users/@me/notes.ts
index f938f088..fc207401 100644
--- a/src/api/routes/users/@me/notes.ts
+++ b/src/api/routes/users/@me/notes.ts
@@ -1,6 +1,6 @@
-import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
-import { User, Note, emitEvent, Snowflake } from "@fosscord/util";
+import { emitEvent, Note, Snowflake, User } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router: Router = Router();
 
@@ -10,38 +10,31 @@ router.get("/:id", route({}), async (req: Request, res: Response) => {
 	const note = await Note.findOneOrFail({
 		where: {
 			owner: { id: req.user_id },
-			target: { id: id },
+			target: { id: id }
 		}
 	});
 
 	return res.json({
 		note: note?.content,
 		note_user_id: id,
-		user_id: req.user_id,
+		user_id: req.user_id
 	});
 });
 
 router.put("/:id", route({}), async (req: Request, res: Response) => {
 	const { id } = req.params;
 	const owner = await User.findOneOrFail({ where: { id: req.user_id } });
-	const target = await User.findOneOrFail({ where: { id: id } });		//if noted user does not exist throw
+	const target = await User.findOneOrFail({ where: { id: id } }); //if noted user does not exist throw
 	const { note } = req.body;
 
 	if (note && note.length) {
 		// upsert a note
 		if (await Note.findOne({ where: { owner: { id: owner.id }, target: { id: target.id } } })) {
-			Note.update(
-				{ owner: { id: owner.id }, target: { id: target.id } },
-				{ owner, target, content: note }
-			);
+			Note.update({ owner: { id: owner.id }, target: { id: target.id } }, { owner, target, content: note });
+		} else {
+			Note.insert({ id: Snowflake.generate(), owner, target, content: note });
 		}
-		else {
-			Note.insert(
-				{ id: Snowflake.generate(), owner, target, content: note }
-			);
-		}
-	}
-	else {
+	} else {
 		await Note.delete({ owner: { id: owner.id }, target: { id: target.id } });
 	}
 
@@ -51,7 +44,7 @@ router.put("/:id", route({}), async (req: Request, res: Response) => {
 			note: note,
 			id: target.id
 		},
-		user_id: owner.id,
+		user_id: owner.id
 	});
 
 	return res.status(204);
diff --git a/src/api/routes/users/@me/relationships.ts b/src/api/routes/users/@me/relationships.ts
index f7464b99..8267c142 100644
--- a/src/api/routes/users/@me/relationships.ts
+++ b/src/api/routes/users/@me/relationships.ts
@@ -1,18 +1,18 @@
+import { route } from "@fosscord/api";
 import {
-	RelationshipAddEvent,
-	User,
-	PublicUserProjection,
-	RelationshipType,
-	RelationshipRemoveEvent,
+	Config,
+	DiscordApiErrors,
 	emitEvent,
+	HTTPError,
+	OrmUtils,
+	PublicUserProjection,
 	Relationship,
-	Config
+	RelationshipAddEvent,
+	RelationshipRemoveEvent,
+	RelationshipType,
+	User
 } from "@fosscord/util";
-import { Router, Response, Request } from "express";
-import { HTTPError } from "@fosscord/util";
-import { DiscordApiErrors } from "@fosscord/util";
-import { route } from "@fosscord/api";
-import { OrmUtils } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();
 
@@ -42,7 +42,11 @@ router.put("/:id", route({ body: "RelationshipPutSchema" }), async (req: Request
 	return await updateRelationship(
 		req,
 		res,
-		await User.findOneOrFail({ where: { id: req.params.id }, relations: ["relationships", "relationships.to"], select: userProjection }),
+		await User.findOneOrFail({
+			where: { id: req.params.id },
+			relations: ["relationships", "relationships.to"],
+			select: userProjection
+		}),
 		req.body.type ?? RelationshipType.friends
 	);
 });
@@ -132,7 +136,9 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ
 			relationship.type = RelationshipType.blocked;
 			await relationship.save();
 		} else {
-			relationship = await (OrmUtils.mergeDeep(new Relationship(), { to_id: id, type: RelationshipType.blocked, from_id: req.user_id }) as Relationship).save();
+			relationship = await (
+				OrmUtils.mergeDeep(new Relationship(), { to_id: id, type: RelationshipType.blocked, from_id: req.user_id }) as Relationship
+			).save();
 		}
 
 		if (friendRequest && friendRequest.type !== RelationshipType.blocked) {
@@ -158,7 +164,12 @@ async function updateRelationship(req: Request, res: Response, friend: User, typ
 	const { maxFriends } = Config.get().limits.user;
 	if (user.relationships.length >= maxFriends) throw DiscordApiErrors.MAXIMUM_FRIENDS.withParams(maxFriends);
 
-	let incoming_relationship = OrmUtils.mergeDeep(new Relationship(), { nickname: undefined, type: RelationshipType.incoming, to: user, from: friend });
+	let incoming_relationship = OrmUtils.mergeDeep(new Relationship(), {
+		nickname: undefined,
+		type: RelationshipType.incoming,
+		to: user,
+		from: friend
+	});
 	let outgoing_relationship = OrmUtils.mergeDeep(new Relationship(), {
 		nickname: undefined,
 		type: RelationshipType.outgoing,
diff --git a/src/api/routes/users/@me/settings.ts b/src/api/routes/users/@me/settings.ts
index 7578d36e..e276a22a 100644
--- a/src/api/routes/users/@me/settings.ts
+++ b/src/api/routes/users/@me/settings.ts
@@ -1,6 +1,6 @@
-import { Router, Response, Request } from "express";
-import { User, UserSettings } from "@fosscord/util";
 import { route } from "@fosscord/api";
+import { User, UserSettings } from "@fosscord/util";
+import { Request, Response, Router } from "express";
 
 const router = Router();