diff --git a/server/constants/media.ts b/server/constants/media.ts index de2bf834d..cf2e046ca 100644 --- a/server/constants/media.ts +++ b/server/constants/media.ts @@ -3,6 +3,7 @@ export enum MediaRequestStatus { APPROVED, DECLINED, FAILED, + COMPLETED, } export enum MediaType { @@ -16,4 +17,5 @@ export enum MediaStatus { PROCESSING, PARTIALLY_AVAILABLE, AVAILABLE, + DELETED, } diff --git a/server/entity/SeasonRequest.ts b/server/entity/SeasonRequest.ts index c55906eb7..984c3d3bc 100644 --- a/server/entity/SeasonRequest.ts +++ b/server/entity/SeasonRequest.ts @@ -1,7 +1,7 @@ import { MediaRequestStatus } from '@server/constants/media'; import { getRepository } from '@server/datasource'; import { - AfterRemove, + AfterUpdate, Column, CreateDateColumn, Entity, @@ -37,15 +37,23 @@ class SeasonRequest { Object.assign(this, init); } - @AfterRemove() + @AfterUpdate() public async handleRemoveParent(): Promise { const mediaRequestRepository = getRepository(MediaRequest); const requestToBeDeleted = await mediaRequestRepository.findOneOrFail({ where: { id: this.request.id }, }); - if (requestToBeDeleted.seasons.length === 0) { - await mediaRequestRepository.delete({ id: this.request.id }); + const allSeasonsAreCompleted = requestToBeDeleted.seasons.filter( + (season) => { + return season.status === MediaRequestStatus.COMPLETED; + } + ); + + if (requestToBeDeleted.seasons.length === allSeasonsAreCompleted.length) { + await mediaRequestRepository.update(this.request.id, { + status: MediaRequestStatus.COMPLETED, + }); } } } diff --git a/server/lib/availabilitySync.ts b/server/lib/availabilitySync.ts index 0a16302cc..398701bc4 100644 --- a/server/lib/availabilitySync.ts +++ b/server/lib/availabilitySync.ts @@ -330,7 +330,7 @@ class AvailabilitySync { media.mediaType === 'movie' ? 'movie' : 'show' } [TMDB ID ${media.tmdbId}] was not found in any ${ media.mediaType === 'movie' ? 'Radarr' : 'Sonarr' - } and Plex instance. Status will be changed to unknown.`, + } and Plex instance. Status will be changed to deleted.`, { label: 'AvailabilitySync' } );