Compare commits

...

1 Commits

Author SHA1 Message Date
fallenbagel
30b441efcb fix: fixes pending media removal after request deletion
This fixes MORE TPYEORM LIFECYCLE HOOK ISSUES for postgresql. Current behavior is after media
request is removed (either by cancellation or deletion) the media remains as `pending` unless a user
with `manage requests` clears the media data, on **POSTGRESQL** database. With this change, the
media status will be changed to `UKNOWN` with the media request removal. TLDR; Though the
@AfterRemove() hook in MediaRequest works fine in SQLite it doesn't reliably update the media status
in PostgreSQL which is likely due to transaction timing or relation loading differences between the
two databases
2025-04-22 13:40:53 +08:00

View File

@@ -569,6 +569,31 @@ requestRoutes.delete('/:requestId', async (req, res, next) => {
await requestRepository.remove(request);
const mediaRepository = getRepository(Media);
const media = await mediaRepository.findOne({
where: { id: request.media.id },
relations: { requests: true },
});
if (media) {
if (
!media.requests.some((r) => !r.is4k) &&
media.status !== MediaStatus.AVAILABLE
) {
media.status = MediaStatus.UNKNOWN;
}
if (
!media.requests.some((r) => r.is4k) &&
media.status4k !== MediaStatus.AVAILABLE
) {
media.status4k = MediaStatus.UNKNOWN;
}
await mediaRepository.save(media);
}
return res.status(204).send();
} catch (e) {
logger.error('Something went wrong deleting a request.', {