fix(requests): prevent duplicate movie requests

pull/1776/head
sct 4 years ago
parent 46dac4d3c3
commit 126d8665ee
No known key found for this signature in database
GPG Key ID: 77D146606D30DCCD

@ -251,20 +251,19 @@ requestRoutes.post('/', async (req, res, next) => {
} }
if (req.body.mediaType === MediaType.MOVIE) { if (req.body.mediaType === MediaType.MOVIE) {
const existing = await requestRepository.findOne({ const existing = await requestRepository
where: { .createQueryBuilder('request')
media: { .leftJoin('request.media', 'media')
tmdbId: tmdbMedia.id, .where('request.is4k = :is4k', { is4k: req.body.is4k })
}, .andWhere('media.tmdbId = :tmdbId', { tmdbId: tmdbMedia.id })
is4k: req.body.is4k, .getOne();
},
});
if (existing) { if (existing) {
logger.warn('Duplicate request for media blocked', { logger.warn('Duplicate request for media blocked', {
tmdbId: tmdbMedia.id, tmdbId: tmdbMedia.id,
mediaType: req.body.mediaType, mediaType: req.body.mediaType,
is4k: req.body.is4k, is4k: req.body.is4k,
label: 'Media Request',
}); });
return next({ return next({
status: 409, status: 409,

Loading…
Cancel
Save