fix: mark available button correctly sets requests as completed

pull/3460/head
Brandon 2 years ago committed by OwsleyJr
parent 390000d6d4
commit d5e3f1cd0b

@ -238,7 +238,6 @@ class AvailabilitySync {
where: whereOptions, where: whereOptions,
skip: offset, skip: offset,
take: pageSize, take: pageSize,
order: { id: 'DESC' },
})); }));
offset += pageSize; offset += pageSize;
} while (mediaPage.length > 0); } while (mediaPage.length > 0);

@ -147,23 +147,29 @@ mediaRoutes.post<
} }
if (req.params.status === 'available') { if (req.params.status === 'available') {
const request = await requestRepository.findOne({ const requests = await requestRepository.find({
relations: { relations: {
media: true, media: true,
}, },
where: { media: { id: media.id }, is4k: is4k }, where: { media: { id: media.id }, is4k: is4k },
}); });
await requestRepository.update( const requestIds = requests.map((request) => request.id);
{ media: { id: request?.id } },
{ status: MediaRequestStatus.COMPLETED }
);
request?.seasons.forEach(async (season) => { if (requestIds.length > 0) {
await seasonRequestRepository.update(season.id, { await requestRepository.update(
status: MediaRequestStatus.COMPLETED, { 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); await mediaRepository.save(media);

Loading…
Cancel
Save