From 6b8c0bd8f3ac7a5c74bc0cb2c81edd2c22a7a618 Mon Sep 17 00:00:00 2001 From: fallenbagel <98979876+fallenbagel@users.noreply.github.com> Date: Sat, 31 May 2025 17:23:15 +0800 Subject: [PATCH] fix(mediarequests): properly sort season numbers in media requests (#1688) Added an @AfterLoad() hook in MediaRequest to ensure seasons are always ordered by their ID. Previously, joinedseasons could appear in arbitrary database order, leading to jumbled UI displays. With this change,the seasons list is automatically re-sorted in ascending ID order as soon as TypeORM hydrates theentity. fix #1336 --- server/entity/MediaRequest.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/entity/MediaRequest.ts b/server/entity/MediaRequest.ts index e5dabc241..cdfa17c3a 100644 --- a/server/entity/MediaRequest.ts +++ b/server/entity/MediaRequest.ts @@ -17,6 +17,7 @@ import { DbAwareColumn } from '@server/utils/DbColumnHelper'; import { truncate } from 'lodash'; import { AfterInsert, + AfterLoad, AfterUpdate, Column, Entity, @@ -701,6 +702,13 @@ export class MediaRequest { } } + @AfterLoad() + private sortSeasons() { + if (Array.isArray(this.seasons)) { + this.seasons.sort((a, b) => a.id - b.id); + } + } + static async sendNotification( entity: MediaRequest, media: Media,