summary refs log tree commit diff
path: root/api/src/routes/guilds
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/routes/guilds')
-rw-r--r--api/src/routes/guilds/#guild_id/bans.ts4
-rw-r--r--api/src/routes/guilds/#guild_id/emojis.ts4
-rw-r--r--api/src/routes/guilds/#guild_id/index.ts2
-rw-r--r--api/src/routes/guilds/#guild_id/members/#member_id/index.ts2
-rw-r--r--api/src/routes/guilds/#guild_id/roles/#role_id/index.ts2
-rw-r--r--api/src/routes/guilds/#guild_id/roles/index.ts2
-rw-r--r--api/src/routes/guilds/#guild_id/stickers.ts4
-rw-r--r--api/src/routes/guilds/#guild_id/templates.ts6
-rw-r--r--api/src/routes/guilds/#guild_id/vanity-url.ts2
-rw-r--r--api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts4
-rw-r--r--api/src/routes/guilds/templates/index.ts6
11 files changed, 19 insertions, 19 deletions
diff --git a/api/src/routes/guilds/#guild_id/bans.ts b/api/src/routes/guilds/#guild_id/bans.ts
index 128ff250..5ff63958 100644
--- a/api/src/routes/guilds/#guild_id/bans.ts
+++ b/api/src/routes/guilds/#guild_id/bans.ts
@@ -90,7 +90,7 @@ router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBER
 	
 	const banned_user = await User.getPublicUser(banned_user_id);
 
-	const ban = new Ban({
+	const ban = Object.assign(new Ban(),{
 		user_id: banned_user_id,
 		guild_id: guild_id,
 		ip: getIpAdress(req),
@@ -122,7 +122,7 @@ router.put("/@me", route({ body: "BanCreateSchema"}), async (req: Request, res:
 	if (req.permission!.cache.guild?.owner_id === req.params.user_id) 
 		throw new HTTPError("You are the guild owner, hence can't ban yourself", 403);
 	
-	const ban = new Ban({
+	const ban = Object.assign(new Ban(), {
 		user_id: req.params.user_id,
 		guild_id: guild_id,
 		ip: getIpAdress(req),
diff --git a/api/src/routes/guilds/#guild_id/emojis.ts b/api/src/routes/guilds/#guild_id/emojis.ts
index c4bcadf7..3e2ed4c2 100644
--- a/api/src/routes/guilds/#guild_id/emojis.ts
+++ b/api/src/routes/guilds/#guild_id/emojis.ts
@@ -50,7 +50,7 @@ router.post("/", route({ body: "EmojiCreateSchema", permission: "MANAGE_EMOJIS_A
 	const user = await User.findOneOrFail({ where: { id: req.user_id } });
 	body.image = (await handleFile(`/emojis/${id}`, body.image)) as string;
 
-	const emoji = await new Emoji({
+	const emoji = await Object.assign(new Emoji(), {
 		id: id,
 		guild_id: guild_id,
 		...body,
@@ -80,7 +80,7 @@ router.patch(
 		const { emoji_id, guild_id } = req.params;
 		const body = req.body as EmojiModifySchema;
 
-		const emoji = await new Emoji({ ...body, id: emoji_id, guild_id: guild_id }).save();
+		const emoji = await Object.assign(new Emoji(), { ...body, id: emoji_id, guild_id: guild_id }).save();
 
 		await emitEvent({
 			event: "GUILD_EMOJIS_UPDATE",
diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts
index 263579e7..643db7ce 100644
--- a/api/src/routes/guilds/#guild_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/index.ts
@@ -59,7 +59,7 @@ router.patch("/", route({ body: "GuildUpdateSchema"}), async (req: Request, res:
 		relations: ["emojis", "roles", "stickers"]
 	});
 	// TODO: check if body ids are valid
-	guild.assign(body);
+	guild = Object.assign(guild, body);
 
 	//TODO: check this, removed toJSON call
 	const data = JSON.parse(JSON.stringify(guild));
diff --git a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
index 2717ec2a..eb31ec1d 100644
--- a/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/members/#member_id/index.ts
@@ -31,7 +31,7 @@ router.patch("/", route({ body: "MemberChangeSchema" }), async (req: Request, re
 		permission.hasThrow("MANAGE_ROLES");
 
 		if (body.roles.indexOf(everyone.id) === -1) body.roles.push(everyone.id);
-		member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist
+		member.roles = body.roles.map((x) => Object.assign(new Role(), { id: x })); // foreign key constraint will fail if role doesn't exist
 	}
 
 	await member.save();
diff --git a/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts b/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts
index af04fd06..a4b91237 100644
--- a/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/roles/#role_id/index.ts
@@ -43,7 +43,7 @@ router.patch("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }
 
 	if (body.icon) body.icon = await handleFile(`/role-icons/${role_id}`, body.icon as string);
 
-	const role = new Role({
+	const role = Object.assign(new Role(), {
 		...body,
 		id: role_id,
 		guild_id,
diff --git a/api/src/routes/guilds/#guild_id/roles/index.ts b/api/src/routes/guilds/#guild_id/roles/index.ts
index d2d14122..7e588d52 100644
--- a/api/src/routes/guilds/#guild_id/roles/index.ts
+++ b/api/src/routes/guilds/#guild_id/roles/index.ts
@@ -51,7 +51,7 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" })
 
 	if (role_count > maxRoles) throw DiscordApiErrors.MAXIMUM_ROLES.withParams(maxRoles);
 
-	const role = new Role({
+	let role: Role = Object.assign(new Role(),{
 		// values before ...body are default and can be overriden
 		position: 0,
 		hoist: false,
diff --git a/api/src/routes/guilds/#guild_id/stickers.ts b/api/src/routes/guilds/#guild_id/stickers.ts
index 7913539b..c6a5037f 100644
--- a/api/src/routes/guilds/#guild_id/stickers.ts
+++ b/api/src/routes/guilds/#guild_id/stickers.ts
@@ -43,7 +43,7 @@ router.post(
 		const id = Snowflake.generate();
 
 		const [sticker] = await Promise.all([
-			new Sticker({
+			Object.assign(new Sticker(), {
 				...body,
 				guild_id,
 				id,
@@ -105,7 +105,7 @@ router.patch(
 		const { guild_id, sticker_id } = req.params;
 		const body = req.body as ModifyGuildStickerSchema;
 
-		const sticker = await new Sticker({ ...body, guild_id, id: sticker_id }).save();
+		const sticker = await Object.assign(new Sticker(), { ...body, guild_id, id: sticker_id }).save();
 		await sendStickerUpdateEvent(guild_id);
 
 		return res.json(sticker);
diff --git a/api/src/routes/guilds/#guild_id/templates.ts b/api/src/routes/guilds/#guild_id/templates.ts
index f2de46e4..edff6717 100644
--- a/api/src/routes/guilds/#guild_id/templates.ts
+++ b/api/src/routes/guilds/#guild_id/templates.ts
@@ -47,7 +47,7 @@ router.post("/", route({ body: "TemplateCreateSchema", permission: "MANAGE_GUILD
 	const exists = await Template.findOneOrFail({ where: { id: guild_id } }).catch((e) => {});
 	if (exists) throw new HTTPError("Template already exists", 400);
 
-	const template = await new Template({
+	const template = await Object.assign(new Template(), {
 		...req.body,
 		code: generateCode(),
 		creator_id: req.user_id,
@@ -75,7 +75,7 @@ router.put("/:code", route({ permission: "MANAGE_GUILD" }), async (req: Request,
 	const { code, guild_id } = req.params;
 	const guild = await Guild.findOneOrFail({ where: { id: guild_id }, select: TemplateGuildProjection });
 
-	const template = await new Template({ code, serialized_source_guild: guild }).save();
+	const template = await Object.assign(new Template(), { code, serialized_source_guild: guild }).save();
 
 	res.json(template);
 });
@@ -84,7 +84,7 @@ router.patch("/:code", route({ body: "TemplateModifySchema", permission: "MANAGE
 	const { code, guild_id } = req.params;
 	const { name, description } = req.body;
 
-	const template = await new Template({ code, name: name, description: description, source_guild_id: guild_id }).save();
+	const template = await Object.assign(new Template(), { code, name: name, description: description, source_guild_id: guild_id }).save();
 
 	res.json(template);
 });
diff --git a/api/src/routes/guilds/#guild_id/vanity-url.ts b/api/src/routes/guilds/#guild_id/vanity-url.ts
index b4d9f618..426559bd 100644
--- a/api/src/routes/guilds/#guild_id/vanity-url.ts
+++ b/api/src/routes/guilds/#guild_id/vanity-url.ts
@@ -47,7 +47,7 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" })
 
 	const { id } = await Channel.findOneOrFail({ where: { guild_id, type: ChannelType.GUILD_TEXT } });
 
-	await new Invite({
+	await Object.assign(new Invite(), {
 		vanity_url: true,
 		code: code,
 		temporary: false,
diff --git a/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts b/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts
index 37ea52b5..5900963e 100644
--- a/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts
+++ b/api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts
@@ -33,7 +33,7 @@ router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request
 	if (!body.suppress) body.request_to_speak_timestamp = new Date();
 	if (body.request_to_speak_timestamp) perms.hasThrow("REQUEST_TO_SPEAK");
 
-	const voice_state = await VoiceState.findOne({
+	let voice_state = await VoiceState.findOne({
 		where: {
 			guild_id,
 			channel_id: body.channel_id,
@@ -42,7 +42,7 @@ router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request
 	});
 	if (!voice_state) throw DiscordApiErrors.UNKNOWN_VOICE_STATE;
 
-	voice_state.assign(body);
+	voice_state = Object.assign(voice_state, body);
 	const channel = await Channel.findOneOrFail({ where: { guild_id, id: body.channel_id } });
 	if (channel.type !== ChannelType.GUILD_STAGE_VOICE) {
 		throw DiscordApiErrors.CANNOT_EXECUTE_ON_THIS_CHANNEL_TYPE;
diff --git a/api/src/routes/guilds/templates/index.ts b/api/src/routes/guilds/templates/index.ts
index e2242ebf..bb8cc017 100644
--- a/api/src/routes/guilds/templates/index.ts
+++ b/api/src/routes/guilds/templates/index.ts
@@ -57,13 +57,13 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req:
 	const guild_id = Snowflake.generate();
 
 	const [guild, role] = await Promise.all([
-		new Guild({
+		Object.assign(new Guild(), {
 			...body,
 			...template.serialized_source_guild,
 			id: guild_id,
 			owner_id: req.user_id
 		}).save(),
-		new Role({
+		(Object.assign(new Role(), {
 			id: guild_id,
 			guild_id: guild_id,
 			color: 0,
@@ -74,7 +74,7 @@ router.post("/:code", route({ body: "GuildTemplateCreateSchema" }), async (req:
 			permissions: BigInt("2251804225"),
 			position: 0,
 			tags: null
-		}).save()
+		}) as Role).save()
 	]);
 
 	await Member.addToGuild(req.user_id, guild_id);