summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorCyberL1 <cyber.hf18@gmail.com>2025-09-29 07:40:26 +0200
committerRory& <root@rory.gay>2025-09-29 18:32:21 +0200
commit29c4a6695c1061200b79da5871e617eda2de47e4 (patch)
treec0662fd273b926229393ee7d8a58ed0063410d9d /src/api
parentfix: migrate older pinned messages to the new system (diff)
downloadserver-ts-29c4a6695c1061200b79da5871e617eda2de47e4.tar.xz
refactor: don't use query builder
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/channels/#channel_id/messages/pins/index.ts12
-rw-r--r--src/api/routes/channels/#channel_id/pins.ts23
2 files changed, 14 insertions, 21 deletions
diff --git a/src/api/routes/channels/#channel_id/messages/pins/index.ts b/src/api/routes/channels/#channel_id/messages/pins/index.ts

index 3e04b157..3dd10ee4 100644 --- a/src/api/routes/channels/#channel_id/messages/pins/index.ts +++ b/src/api/routes/channels/#channel_id/messages/pins/index.ts
@@ -28,6 +28,7 @@ import { User, } from "@spacebar/util"; import { Request, Response, Router } from "express"; +import { IsNull, Not } from "typeorm"; const router: Router = Router(); @@ -184,13 +185,10 @@ router.get( async (req: Request, res: Response) => { const { channel_id } = req.params; - const pins = await Message.createQueryBuilder("message") - .leftJoinAndSelect("message.channel", "channel") - .leftJoinAndSelect("message.author", "author") - .where("channel.id = :channelId", { channelId: channel_id }) - .andWhere("message.pinned_at IS NOT NULL") - .orderBy("message.pinned_at", "DESC") - .getMany(); + const pins = await Message.find({ + where: { channel_id: channel_id, pinned_at: Not(IsNull()) }, + relations: ["author"], + }); const items = pins.map((message: Message) => ({ message, diff --git a/src/api/routes/channels/#channel_id/pins.ts b/src/api/routes/channels/#channel_id/pins.ts
index a8790eab..c45c8853 100644 --- a/src/api/routes/channels/#channel_id/pins.ts +++ b/src/api/routes/channels/#channel_id/pins.ts
@@ -28,6 +28,7 @@ import { User, } from "@spacebar/util"; import { Request, Response, Router } from "express"; +import { IsNull, Not } from "typeorm"; const router: Router = Router(); @@ -56,13 +57,10 @@ router.put( // * in dm channels anyone can pin messages -> only check for guilds if (message.guild_id) req.permission?.hasThrow("MANAGE_MESSAGES"); - const pinned_count = await Message.createQueryBuilder("message") - .leftJoinAndSelect("message.channel", "channel") - .leftJoinAndSelect("message.author", "author") - .where("channel.id = :channelId", { channelId: channel_id }) - .andWhere("message.pinned_at IS NOT NULL") - .orderBy("message.pinned_at", "DESC") - .getCount(); + const pinned_count = await Message.count({ + where: { channel: { id: channel_id }, pinned_at: Not(IsNull()) }, + }); + const { maxPins } = Config.get().limits.channel; if (pinned_count >= maxPins) throw DiscordApiErrors.MAXIMUM_PINS.withParams(maxPins); @@ -184,13 +182,10 @@ router.get( async (req: Request, res: Response) => { const { channel_id } = req.params; - const pins = await Message.createQueryBuilder("message") - .leftJoinAndSelect("message.channel", "channel") - .leftJoinAndSelect("message.author", "author") - .where("channel.id = :channelId", { channelId: channel_id }) - .andWhere("message.pinned_at IS NOT NULL") - .orderBy("message.pinned_at", "DESC") - .getMany(); + const pins = await Message.find({ + where: { channel_id: channel_id, pinned_at: Not(IsNull()) }, + relations: ["author"], + }); res.send(pins); },