summary refs log tree commit diff
path: root/src/api/routes/guilds/#guild_id/members/#member_id/nick.ts
blob: edd47605818d72db3ae4284f5c53780225a1e568 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { getPermission, Member, PermissionResolvable } from "@fosscord/util";
import { route } from "@fosscord/api";
import { Request, Response, Router } from "express";

const router = Router();

router.patch("/", route({ body: "MemberNickChangeSchema" }), async (req: Request, res: Response) => {
	var { guild_id, member_id } = req.params;
	var permissionString: PermissionResolvable = "MANAGE_NICKNAMES";
	if (member_id === "@me") {
		member_id = req.user_id;
		permissionString = "CHANGE_NICKNAME";
	}

	const perms = await getPermission(req.user_id, guild_id);
	perms.hasThrow(permissionString);

	await Member.changeNickname(member_id, guild_id, req.body.nick);
	res.status(200).send();
});

export default router;