summary refs log tree commit diff
path: root/api/src
diff options
context:
space:
mode:
authorLobo Metalúrgico <43734867+LoboMetalurgico@users.noreply.github.com>2021-10-09 10:52:43 -0300
committerLobo Metalúrgico <43734867+LoboMetalurgico@users.noreply.github.com>2021-10-09 10:52:43 -0300
commit8d5911736ad41cdcd17654a269e95777a3219385 (patch)
tree4aa3398f38fe790810bc747eff05a25b7d34f3b3 /api/src
parentMerge remote-tracking branch 'upstream/master' into milestoneV1/routes/implem... (diff)
downloadserver-8d5911736ad41cdcd17654a269e95777a3219385.tar.xz
(api): add patch to emoji route
Diffstat (limited to 'api/src')
-rw-r--r--api/src/routes/guilds/#guild_id/emoji.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/api/src/routes/guilds/#guild_id/emoji.ts b/api/src/routes/guilds/#guild_id/emoji.ts
index f1e427e8..f14790ed 100644
--- a/api/src/routes/guilds/#guild_id/emoji.ts
+++ b/api/src/routes/guilds/#guild_id/emoji.ts
@@ -18,6 +18,11 @@ export interface EmojiCreateSchema {
     roles?: string[];
 }
 
+export interface EmojiModifySchema {
+    name?: string;
+    roles?: string[];
+}
+
 router.get("/", route({}), async (req: Request, res: Response) => {
     const guild_id = req.params.guild_id;
 
@@ -53,6 +58,27 @@ router.post("/", route({ body: "EmojiCreateSchema", permission: "MANAGE_EMOJIS_A
 });
 */
 
+router.patch("/:emoji_id", route({ body: "EmojiModifySchema", permission: "MANAGE_EMOJIS_AND_STICKERS" }), async (req: Request, res: Response) => {
+    const { emoji_id, guild_id } = req.params;
+    const body = req.body as EmojiModifySchema;
+
+    const emoji = new Emoji({ ...body, id: emoji_id, guild_id: guild_id });
+
+    await Promise.all([
+        emoji.save(),
+        emitEvent({
+            event: "GUILD_EMOJI_UPDATE",
+            guild_id: guild_id,
+            data: {
+                guild_id: guild_id,
+                emojis: await Emoji.find({ guild_id: guild_id })
+            }
+        } as GuildEmojiUpdateEvent)
+    ])
+
+    return res.json(emoji);
+});
+
 router.delete("/:emoji_id", route({ permission: "MANAGE_EMOJIS_AND_STICKERS" }), async (req: Request, res: Response) => {
     const guild_id = req.params.guild_id;
     const { emoji_id } = req.params;