From d5e3f1cd0b57086dd48809080cfba318d6dfcde6 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 12 May 2023 18:42:54 -0400 Subject: [PATCH] fix: mark available button correctly sets requests as completed --- server/lib/availabilitySync.ts | 1 - server/routes/media.ts | 24 +++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/server/lib/availabilitySync.ts b/server/lib/availabilitySync.ts index ea115c538..398701bc4 100644 --- a/server/lib/availabilitySync.ts +++ b/server/lib/availabilitySync.ts @@ -238,7 +238,6 @@ class AvailabilitySync { where: whereOptions, skip: offset, take: pageSize, - order: { id: 'DESC' }, })); offset += pageSize; } while (mediaPage.length > 0); diff --git a/server/routes/media.ts b/server/routes/media.ts index 9987380d1..ee0bc4f48 100644 --- a/server/routes/media.ts +++ b/server/routes/media.ts @@ -147,23 +147,29 @@ mediaRoutes.post< } if (req.params.status === 'available') { - const request = await requestRepository.findOne({ + const requests = await requestRepository.find({ relations: { media: true, }, where: { media: { id: media.id }, is4k: is4k }, }); - await requestRepository.update( - { media: { id: request?.id } }, - { status: MediaRequestStatus.COMPLETED } - ); + const requestIds = requests.map((request) => request.id); - request?.seasons.forEach(async (season) => { - await seasonRequestRepository.update(season.id, { - status: MediaRequestStatus.COMPLETED, + if (requestIds.length > 0) { + await requestRepository.update( + { id: In(requestIds) }, + { status: MediaRequestStatus.COMPLETED } + ); + } + + requests + .flatMap((request) => request.seasons) + .forEach(async (season) => { + await seasonRequestRepository.update(season.id, { + status: MediaRequestStatus.COMPLETED, + }); }); - }); } await mediaRepository.save(media);