mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 20:52:42 +01:00
Merge branch 'fosscord:master' into fix-dm
This commit is contained in:
commit
6d0f9abe0d
1
api/package-lock.json
generated
1
api/package-lock.json
generated
@ -68,6 +68,7 @@
|
||||
}
|
||||
},
|
||||
"../util": {
|
||||
"name": "@fosscord/util",
|
||||
"version": "1.0.0",
|
||||
"hasInstallScript": true,
|
||||
"license": "GPLV3",
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Channel, ChannelType, getPermission, Guild, Invite, trimSpecial } from "@fosscord/util";
|
||||
import { Router, Request, Response } from "express";
|
||||
import { route } from "@fosscord/api";
|
||||
import { HTTPError } from "lambert-server";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@ -29,14 +30,14 @@ router.patch("/", route({ body: "VanityUrlSchema", permission: "MANAGE_GUILD" })
|
||||
const body = req.body as VanityUrlSchema;
|
||||
const code = body.code?.replace(InviteRegex, "");
|
||||
|
||||
await Invite.findOneOrFail({ code });
|
||||
const invite = await Invite.findOne({ code });
|
||||
if (invite) throw new HTTPError("Invite already exists");
|
||||
|
||||
const guild = await Guild.findOneOrFail({ id: guild_id });
|
||||
const { id } = await Channel.findOneOrFail({ guild_id, type: ChannelType.GUILD_TEXT });
|
||||
guild.vanity_url_code = code;
|
||||
|
||||
Promise.all([
|
||||
guild.save(),
|
||||
Guild.update({ id: guild_id }, { vanity_url_code: code }),
|
||||
Invite.delete({ code: guild.vanity_url_code }),
|
||||
new Invite({
|
||||
code: code,
|
||||
|
Loading…
Reference in New Issue
Block a user