diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-31 17:56:33 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-08-31 17:56:33 +0200 |
commit | 42a50c0674a7165d1a4d57a09482cc3b40bd5e73 (patch) | |
tree | 934a4d50b58f940665514b00a1e586bba8efcf53 | |
parent | :bug: fix message sending (diff) | |
download | server-42a50c0674a7165d1a4d57a09482cc3b40bd5e73.tar.xz |
:zap: use insert instead of save
-rw-r--r-- | api/src/routes/auth/register.ts | 9 | ||||
-rw-r--r-- | api/src/routes/guilds/index.ts | 41 |
2 files changed, 25 insertions, 25 deletions
diff --git a/api/src/routes/auth/register.ts b/api/src/routes/auth/register.ts index b41ef82c..8bcecda1 100644 --- a/api/src/routes/auth/register.ts +++ b/api/src/routes/auth/register.ts @@ -181,10 +181,11 @@ router.post( // appearently discord doesn't save the date of birth and just calculate if nsfw is allowed // if nsfw_allowed is null/undefined it'll require date_of_birth to set it to true/false - const user = await new User({ + const user = { created_at: new Date(), username: adjusted_username, discriminator, + id: Snowflake.generate(), bot: false, system: false, desktop: false, @@ -204,8 +205,10 @@ router.post( hash: adjusted_password, valid_tokens_since: new Date() }, - settings: defaultSettings - }).save(); + settings: defaultSettings, + fingerprints: [] + }; + await User.insert(user); return res.json({ token: await generateToken(user.id) }); } diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts index 020aba6a..e4157384 100644 --- a/api/src/routes/guilds/index.ts +++ b/api/src/routes/guilds/index.ts @@ -1,9 +1,8 @@ import { Router, Request, Response } from "express"; -import { Role, Guild, Snowflake, Config, User, Member } from "@fosscord/util"; +import { Role, Guild, Snowflake, Config, User, Member, Channel } from "@fosscord/util"; import { HTTPError } from "lambert-server"; import { check } from "./../../util/instanceOf"; import { GuildCreateSchema } from "../../schema/Guild"; -import { createChannel } from "../../util/Channel"; const router: Router = Router(); @@ -13,14 +12,15 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = const body = req.body as GuildCreateSchema; const { maxGuilds } = Config.get().limits.user; - const guild_count = await Member.count({ where: { id: req.user_id } }); + const guild_count = await Member.count({ id: req.user_id }); if (guild_count >= maxGuilds) { throw new HTTPError(`Maximum number of guilds reached ${maxGuilds}`, 403); } const guild_id = Snowflake.generate(); - const guild = new Guild( - { + + const [guild, role] = await Promise.all([ + Guild.insert({ name: body.name, region: Config.get().regions.default, owner_id: req.user_id, @@ -38,7 +38,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = preferred_locale: "en-US", premium_subscription_count: 0, premium_tier: 0, - system_channel_flags: "0", + system_channel_flags: 0, unavailable: false, verification_level: 0, welcome_screen: { @@ -47,11 +47,9 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = welcome_channels: [] }, widget_enabled: false - }, - { id: guild_id } - ); - const role = new Role( - { + }), + Role.insert({ + id: guild_id, guild_id: guild_id, color: 0, hoist: false, @@ -59,15 +57,9 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = mentionable: false, name: "@everyone", permissions: String("2251804225"), - position: 0, - tags: null - }, - { - id: guild_id - } - ); - - await Promise.all([guild.save(), role.save()]); + position: 0 + }) + ]); if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }]; @@ -86,13 +78,18 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = // TODO: should we abort if parent_id is a category? (to disallow sub category channels) var parent_id = ids.get(x.parent_id); - return createChannel({ ...x, guild_id, id, parent_id }, req.user_id, { keepId: true, skipExistsCheck: true }); + return Channel.createChannel({ ...x, guild_id, id, parent_id }, req.user_id, { + keepId: true, + skipExistsCheck: true, + skipPermissionCheck: true, + skipEventEmit: true + }); }) ); await Member.addToGuild(req.user_id, guild_id); - res.status(201).json({ id: guild.id }); + res.status(201).json({ id: guild_id }); }); export default router; |