1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-22 18:32:29 +01:00

Apply Iratu's patch for relationships

Wrap get messages in try catch because around is broken
This commit is contained in:
Madeline 2022-09-02 21:14:31 +10:00
parent e7ea1ed798
commit 0d43bb0afa
2 changed files with 16 additions and 9 deletions

View File

@ -86,7 +86,7 @@ export interface MessageCreateSchema {
// get messages
router.get("/", async (req: Request, res: Response) => {
const channel_id = req.params.channel_id;
const channel = await Channel.findOneOrFail({ id: channel_id });
const channel = await Channel.findOneOrFail({ where: { id: channel_id } });
if (!channel) throw new HTTPError("Channel not found", 404);
isTextChannel(channel.type);
@ -106,7 +106,8 @@ router.get("/", async (req: Request, res: Response) => {
order: { timestamp: "DESC" },
take: limit,
where: { channel_id },
relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"]
relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"],
loadRelationIds: true,
};
if (after) {
@ -124,7 +125,13 @@ router.get("/", async (req: Request, res: Response) => {
];
}
const messages = await Message.find(query);
let messages;
try {
messages = await Message.find(query);
}
catch (e) {
return res.json([]);
}
const endpoint = Config.get().cdn.endpointPublic;
return res.json(
@ -194,7 +201,7 @@ router.post(
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] });
if (!channel.isWritable()) {
throw new HTTPError(`Cannot send messages to channel of type ${channel.type}`, 400)
throw new HTTPError(`Cannot send messages to channel of type ${channel.type}`, 400);
}
const files = req.files as Express.Multer.File[] ?? [];

View File

@ -21,7 +21,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
const user = await User.findOneOrFail({
where: { id: req.user_id },
relations: ["relationships", "relationships.to"],
select: ["relationships"]
select: ["id", "relationships"]
});
//TODO DTO