fix(mediarequestsubscriber): reset season statuses when a TV request is declined
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
import { getRepository } from '@server/datasource';
|
||||
import Media from '@server/entity/Media';
|
||||
import { MediaRequest } from '@server/entity/MediaRequest';
|
||||
import Season from '@server/entity/Season';
|
||||
import SeasonRequest from '@server/entity/SeasonRequest';
|
||||
import notificationManager, { Notification } from '@server/lib/notifications';
|
||||
import { getSettings } from '@server/lib/settings';
|
||||
@@ -815,19 +816,6 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface<MediaRe
|
||||
await mediaRepository.save(media);
|
||||
}
|
||||
|
||||
logger.debug('updateParentStatus: checking TV declined conditions', {
|
||||
label: 'Media Request',
|
||||
requestId: entity.id,
|
||||
mediaId: media.id,
|
||||
mediaType: media.mediaType,
|
||||
entityStatus: entity.status,
|
||||
mediaStatus: media[statusKey],
|
||||
statusKey,
|
||||
isMediaTypeTv: media.mediaType === MediaType.TV,
|
||||
isDeclined: entity.status === MediaRequestStatus.DECLINED,
|
||||
isPending: media[statusKey] === MediaStatus.PENDING,
|
||||
});
|
||||
|
||||
/**
|
||||
* If the media type is TV, and we are declining a request,
|
||||
* we must check if its the only pending request and that
|
||||
@@ -849,39 +837,43 @@ export class MediaRequestSubscriber implements EntitySubscriberInterface<MediaRe
|
||||
},
|
||||
});
|
||||
|
||||
logger.debug('updateParentStatus: TV declined pending count result', {
|
||||
label: 'Media Request',
|
||||
requestId: entity.id,
|
||||
mediaId: media.id,
|
||||
pendingCount,
|
||||
entityIs4k: entity.is4k,
|
||||
});
|
||||
|
||||
if (pendingCount === 0) {
|
||||
// Re-fetch media without requests to avoid cascade issues
|
||||
const freshMedia = await mediaRepository.findOne({
|
||||
where: { id: media.id },
|
||||
});
|
||||
logger.debug('updateParentStatus: TV declined resetting to UNKNOWN', {
|
||||
label: 'Media Request',
|
||||
requestId: entity.id,
|
||||
mediaId: media.id,
|
||||
freshMediaFound: !!freshMedia,
|
||||
freshMediaStatus: freshMedia?.[statusKey],
|
||||
});
|
||||
if (freshMedia) {
|
||||
logger.debug('updateParentStatus: setting media status to UNKNOWN', {
|
||||
label: 'Media Request',
|
||||
requestId: entity.id,
|
||||
mediaId: media.id,
|
||||
statusKey,
|
||||
});
|
||||
freshMedia[statusKey] = MediaStatus.UNKNOWN;
|
||||
await mediaRepository.save(freshMedia);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset season statuses when a TV request is declined
|
||||
if (
|
||||
media.mediaType === MediaType.TV &&
|
||||
entity.status === MediaRequestStatus.DECLINED
|
||||
) {
|
||||
const seasonRepository = getRepository(Season);
|
||||
const actualSeasons = await seasonRepository.find({
|
||||
where: { media: { id: media.id } },
|
||||
});
|
||||
|
||||
for (const seasonRequest of entity.seasons) {
|
||||
seasonRequest.status = MediaRequestStatus.DECLINED;
|
||||
await seasonRequestRepository.save(seasonRequest);
|
||||
|
||||
const season = actualSeasons.find(
|
||||
(s) => s.seasonNumber === seasonRequest.seasonNumber
|
||||
);
|
||||
|
||||
if (season) {
|
||||
season[statusKey] = MediaStatus.UNKNOWN;
|
||||
await seasonRepository.save(season);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Approve child seasons if parent is approved
|
||||
if (
|
||||
media.mediaType === MediaType.TV &&
|
||||
|
||||
@@ -360,7 +360,11 @@ const TvRequestModal = ({
|
||||
).length > 0
|
||||
) {
|
||||
data.mediaInfo.requests
|
||||
.filter((request) => request.is4k === is4k)
|
||||
.filter(
|
||||
(request) =>
|
||||
request.is4k === is4k &&
|
||||
request.status !== MediaRequestStatus.DECLINED
|
||||
)
|
||||
.forEach((request) => {
|
||||
if (!seasonRequest) {
|
||||
seasonRequest = request.seasons.find(
|
||||
|
||||
Reference in New Issue
Block a user