fix(watch-data): use sentinel values to avoid invalid SQL syntax (#2552)
This commit is contained in:
@@ -315,12 +315,12 @@ mediaRoutes.get<{ id: string }, MediaWatchDataResponse>(
|
|||||||
if (media.ratingKey) {
|
if (media.ratingKey) {
|
||||||
const watchStats = await tautulli.getMediaWatchStats(media.ratingKey);
|
const watchStats = await tautulli.getMediaWatchStats(media.ratingKey);
|
||||||
const watchUsers = await tautulli.getMediaWatchUsers(media.ratingKey);
|
const watchUsers = await tautulli.getMediaWatchUsers(media.ratingKey);
|
||||||
|
const plexIds = watchUsers.map((u) => u.user_id);
|
||||||
|
if (!plexIds.length) plexIds.push(-1);
|
||||||
|
|
||||||
const users = await userRepository
|
const users = await userRepository
|
||||||
.createQueryBuilder('user')
|
.createQueryBuilder('user')
|
||||||
.where('user.plexId IN (:...plexIds)', {
|
.where('user.plexId IN (:...plexIds)', { plexIds })
|
||||||
plexIds: watchUsers.map((u) => u.user_id),
|
|
||||||
})
|
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
const playCount =
|
const playCount =
|
||||||
@@ -347,12 +347,12 @@ mediaRoutes.get<{ id: string }, MediaWatchDataResponse>(
|
|||||||
const watchUsers4k = await tautulli.getMediaWatchUsers(
|
const watchUsers4k = await tautulli.getMediaWatchUsers(
|
||||||
media.ratingKey4k
|
media.ratingKey4k
|
||||||
);
|
);
|
||||||
|
const plexIds4k = watchUsers4k.map((u) => u.user_id);
|
||||||
|
if (!plexIds4k.length) plexIds4k.push(-1);
|
||||||
|
|
||||||
const users = await userRepository
|
const users = await userRepository
|
||||||
.createQueryBuilder('user')
|
.createQueryBuilder('user')
|
||||||
.where('user.plexId IN (:...plexIds)', {
|
.where('user.plexId IN (:...plexIds)', { plexIds: plexIds4k })
|
||||||
plexIds: watchUsers4k.map((u) => u.user_id),
|
|
||||||
})
|
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
const playCount =
|
const playCount =
|
||||||
|
|||||||
@@ -494,13 +494,16 @@ settingsRoutes.get(
|
|||||||
thumb: string;
|
thumb: string;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
|
const plexIds = plexUsers.map((plexUser) => plexUser.id);
|
||||||
|
const plexEmails = plexUsers.map((plexUser) =>
|
||||||
|
plexUser.email.toLowerCase()
|
||||||
|
);
|
||||||
|
if (!plexIds.length) plexIds.push('-1');
|
||||||
|
if (!plexEmails.length) plexEmails.push('@');
|
||||||
|
|
||||||
const existingUsers = await qb
|
const existingUsers = await qb
|
||||||
.where('user.plexId IN (:...plexIds)', {
|
.where('user.plexId IN (:...plexIds)', { plexIds })
|
||||||
plexIds: plexUsers.map((plexUser) => plexUser.id),
|
.orWhere('user.email IN (:...plexEmails)', { plexEmails })
|
||||||
})
|
|
||||||
.orWhere('user.email IN (:...plexEmails)', {
|
|
||||||
plexEmails: plexUsers.map((plexUser) => plexUser.email.toLowerCase()),
|
|
||||||
})
|
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
|
|||||||
Reference in New Issue
Block a user