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) {
const existing = await requestRepository.findOne({
where: {
media: {
tmdbId: tmdbMedia.id,
},
is4k: req.body.is4k,
},
});
const existing = await requestRepository
.createQueryBuilder('request')
.leftJoin('request.media', 'media')
.where('request.is4k = :is4k', { is4k: req.body.is4k })
.andWhere('media.tmdbId = :tmdbId', { tmdbId: tmdbMedia.id })
.getOne();
if (existing) {
logger.warn('Duplicate request for media blocked', {
tmdbId: tmdbMedia.id,
mediaType: req.body.mediaType,
is4k: req.body.is4k,
label: 'Media Request',
});
return next({
status: 409,

Loading…
Cancel
Save