🐛 fix member roles + list

This commit is contained in:
Flam3rboy 2021-09-03 13:23:20 +02:00
parent f83f4416b8
commit a446837679
4 changed files with 9 additions and 13 deletions

View File

@ -2,7 +2,6 @@ DROP TABLE applications;
DROP TABLE attachments; DROP TABLE attachments;
DROP TABLE audit_logs; DROP TABLE audit_logs;
DROP TABLE bans; DROP TABLE bans;
DROP TABLE channels;
DROP TABLE connected_accounts; DROP TABLE connected_accounts;
DROP TABLE emojis; DROP TABLE emojis;
DROP TABLE invites; DROP TABLE invites;
@ -24,6 +23,7 @@ DROP TABLE teams;
DROP TABLE templates; DROP TABLE templates;
DROP TABLE voice_states; DROP TABLE voice_states;
DROP TABLE webhooks; DROP TABLE webhooks;
DROP TABLE channels;
DROP TABLE members; DROP TABLE members;
DROP TABLE guilds; DROP TABLE guilds;
-- DROP TABLE users; -- DROP TABLE users;

View File

@ -30,18 +30,14 @@ router.patch("/", check(MemberChangeSchema), async (req: Request, res: Response)
const { guild_id, member_id } = req.params; const { guild_id, member_id } = req.params;
const body = req.body as MemberChangeSchema; const body = req.body as MemberChangeSchema;
const member = await Member.findOneOrFail({ where: { id: member_id, guild_id }, relations: ["roles", "user"] });
const permission = await getPermission(req.user_id, guild_id); const permission = await getPermission(req.user_id, guild_id);
if (body.roles) { if (body.roles) {
permission.hasThrow("MANAGE_ROLES"); permission.hasThrow("MANAGE_ROLES");
member.roles = body.roles.map((x) => new Role({ id: x })); // foreign key constraint will fail if role doesn't exist
const roles = await Role.find({ id: In(body.roles) });
if (body.roles.length !== roles.length) throw new HTTPError("Roles not found", 404);
} }
const member = await Member.findOneOrFail({ id: member_id, guild_id });
member.assign(req.body);
Promise.all([ Promise.all([
member.save(), member.save(),
emitEvent({ emitEvent({

View File

@ -20,7 +20,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
const guild_id = Snowflake.generate(); const guild_id = Snowflake.generate();
const guild = await new Guild({ await Guild.insert({
name: body.name, name: body.name,
region: Config.get().regions.default, region: Config.get().regions.default,
owner_id: req.user_id, owner_id: req.user_id,
@ -47,10 +47,10 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
welcome_channels: [] welcome_channels: []
}, },
widget_enabled: false widget_enabled: false
}).save(); });
// we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error // we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error
const role = await new Role({ await Role.insert({
id: guild_id, id: guild_id,
guild_id: guild_id, guild_id: guild_id,
color: 0, color: 0,
@ -60,7 +60,7 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
name: "@everyone", name: "@everyone",
permissions: String("2251804225"), permissions: String("2251804225"),
position: 0 position: 0
}).save(); });
if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }]; if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }];

View File

@ -33,7 +33,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
const roles = await Role.find({ const roles = await Role.find({
where: { guild_id: guild_id }, where: { guild_id: guild_id },
order: { order: {
position: "ASC", position: "DESC",
}, },
}); });
@ -47,7 +47,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
); );
const group = { const group = {
count: role_members.length, count: role_members.length,
id: role.id === guild_id ? "online" : role.name, id: role.id === guild_id ? "online" : role.id,
}; };
items.push({ group }); items.push({ group });