🐛 fix dm #321

This commit is contained in:
Flam3rboy
2021-09-13 01:11:03 +02:00
parent 6b21e107dd
commit 4f1b926d09
7 changed files with 50 additions and 31 deletions
@@ -35,7 +35,7 @@ router.put(
allow: body.allow,
deny: body.deny
};
channel.permission_overwrites.push(overwrite);
channel.permission_overwrites!.push(overwrite);
}
overwrite.allow = body.allow;
overwrite.deny = body.deny;
@@ -60,7 +60,7 @@ router.delete("/:overwrite_id", route({ permission: "MANAGE_ROLES" }), async (re
const channel = await Channel.findOneOrFail({ id: channel_id });
if (!channel.guild_id) throw new HTTPError("Channel not found", 404);
channel.permission_overwrites = channel.permission_overwrites.filter((x) => x.id === overwrite_id);
channel.permission_overwrites = channel.permission_overwrites!.filter((x) => x.id === overwrite_id);
await Promise.all([
channel.save(),
+8 -8
View File
@@ -4,11 +4,6 @@ import { HTTPError } from "lambert-server";
import { route } from "@fosscord/api";
import { In } from "typeorm";
export interface DmChannelCreateSchema {
name?: string;
recipients: string[];
}
const router: Router = Router();
router.get("/", route({}), async (req: Request, res: Response) => {
@@ -17,12 +12,17 @@ router.get("/", route({}), async (req: Request, res: Response) => {
res.json(recipients.map((x) => x.channel));
});
export interface DmChannelCreateSchema {
name?: string;
recipients: string[];
}
router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request, res: Response) => {
const body = req.body as DmChannelCreateSchema;
body.recipients = body.recipients.filter((x) => x !== req.user_id).unique();
const recipients = await User.find({ id: In(body.recipients) });
const recipients = await User.find({ where: body.recipients.map((x) => ({ id: x })) });
if (recipients.length !== body.recipients.length) {
throw new HTTPError("Recipient/s not found");
@@ -34,10 +34,10 @@ router.post("/", route({ body: "DmChannelCreateSchema" }), async (req: Request,
const channel = await new Channel({
name,
type,
owner_id: req.user_id,
// owner_id only for group dm channels
created_at: new Date(),
last_message_id: null,
recipients: [...body.recipients.map((x) => new Recipient({ id: x })), new Recipient({ id: req.user_id })]
recipients: [...body.recipients.map((x) => new Recipient({ user_id: x })), new Recipient({ user_id: req.user_id })]
}).save();
await emitEvent({ event: "CHANNEL_CREATE", data: channel, user_id: req.user_id } as ChannelCreateEvent);
+2
View File
@@ -0,0 +1,2 @@
// TODO: check every route based on route() paramters: https://github.com/fosscord/fosscord-server/issues/308
// TODO: check every route with different database engine