fix: correctly deal with tmdb id duplicates between movies/series

fixes #526
This commit is contained in:
sct
2020-12-29 10:26:37 +00:00
parent 5295f74915
commit 721ed9a930
10 changed files with 108 additions and 24 deletions

View File

@@ -40,12 +40,15 @@ class Media {
}
}
public static async getMedia(id: number): Promise<Media | undefined> {
public static async getMedia(
id: number,
mediaType: MediaType
): Promise<Media | undefined> {
const mediaRepository = getRepository(Media);
try {
const media = await mediaRepository.findOne({
where: { tmdbId: id },
where: { tmdbId: id, mediaType },
relations: ['requests'],
});
@@ -62,7 +65,7 @@ class Media {
@Column({ type: 'varchar' })
public mediaType: MediaType;
@Column({ unique: true })
@Column()
@Index()
public tmdbId: number;
@@ -70,7 +73,7 @@ class Media {
@Index()
public tvdbId?: number;
@Column({ unique: true, nullable: true })
@Column({ nullable: true })
@Index()
public imdbId?: string;