Apply Iratu's patch for relationships
Wrap get messages in try catch because around is broken
This commit is contained in:
parent
e7ea1ed798
commit
0d43bb0afa
@ -86,7 +86,7 @@ export interface MessageCreateSchema {
|
|||||||
// get messages
|
// get messages
|
||||||
router.get("/", async (req: Request, res: Response) => {
|
router.get("/", async (req: Request, res: Response) => {
|
||||||
const channel_id = req.params.channel_id;
|
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);
|
if (!channel) throw new HTTPError("Channel not found", 404);
|
||||||
|
|
||||||
isTextChannel(channel.type);
|
isTextChannel(channel.type);
|
||||||
@ -106,7 +106,8 @@ router.get("/", async (req: Request, res: Response) => {
|
|||||||
order: { timestamp: "DESC" },
|
order: { timestamp: "DESC" },
|
||||||
take: limit,
|
take: limit,
|
||||||
where: { channel_id },
|
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) {
|
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;
|
const endpoint = Config.get().cdn.endpointPublic;
|
||||||
|
|
||||||
return res.json(
|
return res.json(
|
||||||
@ -194,7 +201,7 @@ router.post(
|
|||||||
|
|
||||||
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] });
|
const channel = await Channel.findOneOrFail({ where: { id: channel_id }, relations: ["recipients", "recipients.user"] });
|
||||||
if (!channel.isWritable()) {
|
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[] ?? [];
|
const files = req.files as Express.Multer.File[] ?? [];
|
||||||
|
@ -21,7 +21,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
|
|||||||
const user = await User.findOneOrFail({
|
const user = await User.findOneOrFail({
|
||||||
where: { id: req.user_id },
|
where: { id: req.user_id },
|
||||||
relations: ["relationships", "relationships.to"],
|
relations: ["relationships", "relationships.to"],
|
||||||
select: ["relationships"]
|
select: ["id", "relationships"]
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO DTO
|
//TODO DTO
|
||||||
|
Loading…
x
Reference in New Issue
Block a user