From 1cb31f43eafc8840a93e8ca0a0ef155458886be6 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 6 Mar 2023 23:14:22 -0500 Subject: [PATCH] fix: modified media status handling when media has been deleted --- server/constants/media.ts | 2 ++ server/entity/SeasonRequest.ts | 16 ++++++++++++---- server/lib/availabilitySync.ts | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) 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' } );