diff options
author | Intevel ツ <59223342+Intevel@users.noreply.github.com> | 2021-05-06 23:01:46 +0200 |
---|---|---|
committer | Intevel ツ <59223342+Intevel@users.noreply.github.com> | 2021-05-06 23:01:46 +0200 |
commit | f2cecdecdc9639d92a2c23c1a244415cc6e0d4a7 (patch) | |
tree | f24b2821c5ff5a41508f33d377361b551f059446 /src | |
parent | Update index.ts (diff) | |
download | server-f2cecdecdc9639d92a2c23c1a244415cc6e0d4a7.tar.xz |
Updated
new ids
Diffstat (limited to 'src')
-rw-r--r-- | src/routes/guilds/#guild_id/templates.ts | 21 | ||||
-rw-r--r-- | src/routes/guilds/templates/index.ts | 2 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/routes/guilds/#guild_id/templates.ts b/src/routes/guilds/#guild_id/templates.ts index a380ac2f..7b820779 100644 --- a/src/routes/guilds/#guild_id/templates.ts +++ b/src/routes/guilds/#guild_id/templates.ts @@ -1,5 +1,5 @@ import { Request, Response, Router } from "express"; -import { TemplateModel, GuildModel, getPermission, toObject, UserModel } from "@fosscord/server-util"; +import { TemplateModel, GuildModel, getPermission, toObject, UserModel, Snowflake } from "@fosscord/server-util"; import { HTTPError } from "lambert-server"; import { TemplateCreateSchema, TemplateModifySchema } from "../../../schema/Template"; import { emitEvent } from "../../../util/Event"; @@ -35,8 +35,11 @@ router.post("/", check(TemplateCreateSchema), async (req: Request, res: Response if (!perms.has("MANAGE_GUILD")) throw new HTTPError("You missing the MANAGE_GUILD permission", 401);*/ + const template_id = Snowflake.generate(); + var template = { ...req.body, + id: template_id, creator_id: req.user_id, creator: user, created_at: new Date(), @@ -67,8 +70,8 @@ router.delete("/:template_id", async (req: Request, res: Response) => { if (!perms.has("MANAGE_GUILD")) throw new HTTPError("You missing the MANAGE_GUILD permission", 401); - await TemplateModel.findByIdAndDelete({ - _id: template_id, + await TemplateModel.findOneAndDelete({ + id: template_id, source_guild_id: guild_id }).exec(); @@ -87,7 +90,7 @@ router.put("/:template_id", async (req: Request, res: Response) => { const user = await UserModel.findOne({ id: req.user_id }).exec(); if (!user) throw new HTTPError("User not found", 404); - const template = await TemplateModel.findById({ _id: template_id }).exec(); + const template = await TemplateModel.findOneAndDelete({ id: template_id }).exec(); if (!template) throw new HTTPError("template not found", 404); const perms = await getPermission(req.user_id, guild_id); @@ -95,8 +98,8 @@ router.put("/:template_id", async (req: Request, res: Response) => { if (!perms.has("MANAGE_GUILD")) throw new HTTPError("You missing the MANAGE_GUILD permission", 401); - var templateobj = await TemplateModel.findByIdAndUpdate({ - _id: template_id, + var templateobj = await TemplateModel.findOneAndUpdate({ + id: template_id, serialized_source_guild: guild }).exec(); @@ -114,7 +117,7 @@ router.patch("/:template_id", check(TemplateModifySchema), async (req: Request, const user = await UserModel.findOne({ id: req.user_id }).exec(); if (!user) throw new HTTPError("User not found", 404); - const template = await TemplateModel.findById({ _id: template_id }).exec(); + const template = await TemplateModel.findOne({ id: template_id }).exec(); if (!template) throw new HTTPError("template not found", 404); const perms = await getPermission(req.user_id, guild_id); @@ -122,8 +125,8 @@ router.patch("/:template_id", check(TemplateModifySchema), async (req: Request, if (!perms.has("MANAGE_GUILD")) throw new HTTPError("You missing the MANAGE_GUILD permission", 401); - var templateobj = await TemplateModel.findByIdAndUpdate({ - _id: template_id + var templateobj = await TemplateModel.findOneAndUpdate({ + id: template_id }, {name: req.body.name, description: req.body.description || "No description"}).exec(); diff --git a/src/routes/guilds/templates/index.ts b/src/routes/guilds/templates/index.ts index fdd70335..80dbe5f8 100644 --- a/src/routes/guilds/templates/index.ts +++ b/src/routes/guilds/templates/index.ts @@ -36,7 +36,7 @@ router.post("/:template_id", check(GuildTemplateCreateSchema), async (req: Reque if (!template_id) throw new HTTPError("Unknown template_id", 404); - const template = await TemplateModel.findById({ _id: template_id }).exec(); + const template = await TemplateModel.findOne({ id: template_id }).exec(); if (!template) throw new HTTPError("template not found", 404); const guild_id = Snowflake.generate(); |