fix: getting message pinss

This commit is contained in:
CyberL1 2025-07-13 07:30:17 +02:00 committed by Rory&
parent 06ae335d1b
commit b8b461f0db
3 changed files with 31 additions and 2 deletions

View File

@ -63,6 +63,7 @@ router.put(
throw DiscordApiErrors.MAXIMUM_PINS.withParams(maxPins);
message.pinned = true;
message.pinned_at = new Date();
const author = await User.getPublicUser(req.user_id);
@ -182,11 +183,19 @@ router.get(
const pins = await Message.find({
where: { channel_id: channel_id, pinned: true },
relations: ["author"],
order: {
pinned_at: "DESC",
},
});
const items = pins.map((message) => ({
message,
pinned_at: message.pinned_at,
}));
res.send({
items: pins,
has_more: false
items,
has_more: false,
});
},
);

View File

@ -188,6 +188,9 @@ export class Message extends BaseClass {
@Column({ nullable: true })
pinned?: boolean;
@Column({ nullable: true })
pinned_at?: Date;
@Column({ type: "int" })
type: MessageType;

View File

@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class MessagePinnedAt1752383879533 implements MigrationInterface {
name = "MessagePinnedAt1752383879533";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "messages" ADD "pinned_at" TIMESTAMP`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "messages" DROP COLUMN "pinned_at"`,
);
}
}