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
This commit is contained in:
fallenbagel
2025-05-31 17:23:15 +08:00
committed by GitHub
parent ea7e68fc99
commit 6b8c0bd8f3

View File

@@ -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,