fix: modified media status handling when media has been deleted

pull/3460/head
Brandon 2 years ago committed by OwsleyJr
parent 8251c73ffa
commit 1cb31f43ea

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

@ -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<void> {
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,
});
}
}
}

@ -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' }
);

Loading…
Cancel
Save