diff options
Diffstat (limited to 'api/src/routes/guilds/#guild_id')
-rw-r--r-- | api/src/routes/guilds/#guild_id/bans.ts | 5 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/emojis.ts | 5 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/index.ts | 3 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/members/#member_id/index.ts | 3 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/roles/#role_id/index.ts | 3 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/roles/index.ts | 3 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/stickers.ts | 5 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/templates.ts | 7 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/vanity-url.ts | 3 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/voice-states/#user_id/index.ts | 3 | ||||
-rw-r--r-- | api/src/routes/guilds/#guild_id/widget.json.ts | 3 |
11 files changed, 27 insertions, 16 deletions
diff --git a/api/src/routes/guilds/#guild_id/bans.ts b/api/src/routes/guilds/#guild_id/bans.ts index 5ff63958..0743687d 100644 --- a/api/src/routes/guilds/#guild_id/bans.ts +++ b/api/src/routes/guilds/#guild_id/bans.ts @@ -2,6 +2,7 @@ import { Request, Response, Router } from "express"; import { DiscordApiErrors, emitEvent, getPermission, GuildBanAddEvent, GuildBanRemoveEvent, Guild, Ban, User, Member } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { getIpAdress, route } from "@fosscord/api"; +import { OrmUtils } from "@fosscord/util"; export interface BanCreateSchema { delete_message_days?: string; @@ -90,7 +91,7 @@ router.put("/:user_id", route({ body: "BanCreateSchema", permission: "BAN_MEMBER const banned_user = await User.getPublicUser(banned_user_id); - const ban = Object.assign(new Ban(),{ + const ban = OrmUtils.mergeDeep(new Ban(),{ user_id: banned_user_id, guild_id: guild_id, ip: getIpAdress(req), @@ -122,7 +123,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 = Object.assign(new Ban(), { + const ban = OrmUtils.mergeDeep(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 3e2ed4c2..53a44ec3 100644 --- a/api/src/routes/guilds/#guild_id/emojis.ts +++ b/api/src/routes/guilds/#guild_id/emojis.ts @@ -1,6 +1,7 @@ import { Router, Request, Response } from "express"; import { Config, DiscordApiErrors, emitEvent, Emoji, GuildEmojisUpdateEvent, handleFile, Member, Snowflake, User } from "@fosscord/util"; import { route } from "@fosscord/api"; +import { OrmUtils } from "@fosscord/util"; const router = Router(); @@ -50,7 +51,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 Object.assign(new Emoji(), { + const emoji = await OrmUtils.mergeDeep(new Emoji(), { id: id, guild_id: guild_id, ...body, @@ -80,7 +81,7 @@ router.patch( const { emoji_id, guild_id } = req.params; const body = req.body as EmojiModifySchema; - const emoji = await Object.assign(new Emoji(), { ...body, id: emoji_id, guild_id: guild_id }).save(); + const emoji = await OrmUtils.mergeDeep(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 643db7ce..abece88e 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/api/src/routes/guilds/#guild_id/index.ts @@ -3,6 +3,7 @@ import { DiscordApiErrors, emitEvent, getPermission, getRights, Guild, GuildUpda import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; import { GuildCreateSchema } from "../index"; +import { OrmUtils } from "@fosscord/util"; const router = Router(); @@ -59,7 +60,7 @@ router.patch("/", route({ body: "GuildUpdateSchema"}), async (req: Request, res: relations: ["emojis", "roles", "stickers"] }); // TODO: check if body ids are valid - guild = Object.assign(guild, body); + guild = OrmUtils.mergeDeep(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 eb31ec1d..824e34a4 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 @@ -2,6 +2,7 @@ import { Request, Response, Router } from "express"; import { Member, getPermission, getRights, Role, GuildMemberUpdateEvent, emitEvent, Sticker, Emoji, Rights, Guild } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; +import { OrmUtils } from "@fosscord/util"; const router = Router(); @@ -31,7 +32,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) => Object.assign(new Role(), { id: x })); // foreign key constraint will fail if role doesn't exist + member.roles = body.roles.map((x) => OrmUtils.mergeDeep(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 a4b91237..0482b9ca 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 @@ -3,6 +3,7 @@ import { Role, Member, GuildRoleUpdateEvent, GuildRoleDeleteEvent, emitEvent, ha import { route } from "@fosscord/api"; import { HTTPError } from "@fosscord/util"; import { RoleModifySchema } from "../"; +import { OrmUtils } from "@fosscord/util"; const router = Router(); @@ -43,7 +44,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 = Object.assign(new Role(), { + const role = OrmUtils.mergeDeep(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 7e588d52..6fbb8702 100644 --- a/api/src/routes/guilds/#guild_id/roles/index.ts +++ b/api/src/routes/guilds/#guild_id/roles/index.ts @@ -13,6 +13,7 @@ import { } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; +import { OrmUtils } from "@fosscord/util"; const router: Router = Router(); @@ -51,7 +52,7 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" }) if (role_count > maxRoles) throw DiscordApiErrors.MAXIMUM_ROLES.withParams(maxRoles); - let role: Role = Object.assign(new Role(),{ + let role: Role = OrmUtils.mergeDeep(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 c6a5037f..157ccff4 100644 --- a/api/src/routes/guilds/#guild_id/stickers.ts +++ b/api/src/routes/guilds/#guild_id/stickers.ts @@ -13,6 +13,7 @@ import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; import multer from "multer"; import { HTTPError } from "@fosscord/util"; +import { OrmUtils } from "@fosscord/util"; const router = Router(); router.get("/", route({}), async (req: Request, res: Response) => { @@ -43,7 +44,7 @@ router.post( const id = Snowflake.generate(); const [sticker] = await Promise.all([ - Object.assign(new Sticker(), { + OrmUtils.mergeDeep(new Sticker(), { ...body, guild_id, id, @@ -105,7 +106,7 @@ router.patch( const { guild_id, sticker_id } = req.params; const body = req.body as ModifyGuildStickerSchema; - const sticker = await Object.assign(new Sticker(), { ...body, guild_id, id: sticker_id }).save(); + const sticker = await OrmUtils.mergeDeep(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 edff6717..3d14de41 100644 --- a/api/src/routes/guilds/#guild_id/templates.ts +++ b/api/src/routes/guilds/#guild_id/templates.ts @@ -3,6 +3,7 @@ import { Guild, Template } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { route } from "@fosscord/api"; import { generateCode } from "@fosscord/api"; +import { OrmUtils } from "@fosscord/util"; const router: Router = Router(); @@ -47,7 +48,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 Object.assign(new Template(), { + const template = await OrmUtils.mergeDeep(new Template(), { ...req.body, code: generateCode(), creator_id: req.user_id, @@ -75,7 +76,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 Object.assign(new Template(), { code, serialized_source_guild: guild }).save(); + const template = await OrmUtils.mergeDeep(new Template(), { code, serialized_source_guild: guild }).save(); res.json(template); }); @@ -84,7 +85,7 @@ router.patch("/:code", route({ body: "TemplateModifySchema", permission: "MANAGE const { code, guild_id } = req.params; const { name, description } = req.body; - const template = await Object.assign(new Template(), { code, name: name, description: description, source_guild_id: guild_id }).save(); + const template = await OrmUtils.mergeDeep(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 426559bd..ac46e18a 100644 --- a/api/src/routes/guilds/#guild_id/vanity-url.ts +++ b/api/src/routes/guilds/#guild_id/vanity-url.ts @@ -2,6 +2,7 @@ import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial } from import { Router, Request, Response } from "express"; import { route } from "@fosscord/api"; import { HTTPError } from "@fosscord/util"; +import { OrmUtils } from "@fosscord/util"; const router = Router(); @@ -47,7 +48,7 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" }) const { id } = await Channel.findOneOrFail({ where: { guild_id, type: ChannelType.GUILD_TEXT } }); - await Object.assign(new Invite(), { + await OrmUtils.mergeDeep(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 5900963e..32d1aadf 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 @@ -1,6 +1,7 @@ import { Channel, ChannelType, DiscordApiErrors, emitEvent, getPermission, VoiceState, VoiceStateUpdateEvent } from "@fosscord/util"; import { route } from "@fosscord/api"; import { Request, Response, Router } from "express"; +import { OrmUtils } from "@fosscord/util"; const router = Router(); //TODO need more testing when community guild and voice stage channel are working @@ -42,7 +43,7 @@ router.patch("/", route({ body: "VoiceStateUpdateSchema" }), async (req: Request }); if (!voice_state) throw DiscordApiErrors.UNKNOWN_VOICE_STATE; - voice_state = Object.assign(voice_state, body); + voice_state = OrmUtils.mergeDeep(voice_state, body) as VoiceState; 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/#guild_id/widget.json.ts b/api/src/routes/guilds/#guild_id/widget.json.ts index b7a93a46..37739418 100644 --- a/api/src/routes/guilds/#guild_id/widget.json.ts +++ b/api/src/routes/guilds/#guild_id/widget.json.ts @@ -2,6 +2,7 @@ import { Request, Response, Router } from "express"; import { Config, Permissions, Guild, Invite, Channel, Member } from "@fosscord/util"; import { HTTPError } from "@fosscord/util"; import { random, route } from "@fosscord/api"; +import { OrmUtils } from "@fosscord/util"; const router: Router = Router(); @@ -41,7 +42,7 @@ router.get("/", route({}), async (req: Request, res: Response) => { inviter_id: null }; - invite = await new Invite(body).save(); + invite = await OrmUtils.mergeDeep(new Invite(), body).save(); } // Fetch voice channels, and the @everyone permissions object |