mirror of
https://github.com/seerr-team/seerr.git
synced 2026-10-12 02:22:17 +00:00
fix(subscriber): keep issue comment lookups on the owning save's connection (#3536)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import TheMovieDb from '@server/api/themoviedb';
|
||||
import { IssueType, IssueTypeName } from '@server/constants/issue';
|
||||
import { MediaType } from '@server/constants/media';
|
||||
import { getRepository } from '@server/datasource';
|
||||
import IssueComment from '@server/entity/IssueComment';
|
||||
import Media from '@server/entity/Media';
|
||||
import { User } from '@server/entity/User';
|
||||
@@ -9,7 +8,11 @@ import notificationManager, { Notification } from '@server/lib/notifications';
|
||||
import { Permission } from '@server/lib/permissions';
|
||||
import logger from '@server/logger';
|
||||
import { sortBy } from 'lodash';
|
||||
import type { EntitySubscriberInterface, InsertEvent } from 'typeorm';
|
||||
import type {
|
||||
EntityManager,
|
||||
EntitySubscriberInterface,
|
||||
InsertEvent,
|
||||
} from 'typeorm';
|
||||
import { EventSubscriber } from 'typeorm';
|
||||
|
||||
@EventSubscriber()
|
||||
@@ -18,24 +21,27 @@ export class IssueCommentSubscriber implements EntitySubscriberInterface<IssueCo
|
||||
return IssueComment;
|
||||
}
|
||||
|
||||
private async sendIssueCommentNotification(entity: IssueComment) {
|
||||
private async sendIssueCommentNotification(
|
||||
manager: EntityManager,
|
||||
entity: IssueComment
|
||||
) {
|
||||
let title: string;
|
||||
let image: string;
|
||||
const tmdb = new TheMovieDb();
|
||||
|
||||
try {
|
||||
const issue = (
|
||||
await getRepository(IssueComment).findOneOrFail({
|
||||
await manager.getRepository(IssueComment).findOneOrFail({
|
||||
where: { id: entity.id },
|
||||
relations: { issue: { createdBy: true } },
|
||||
})
|
||||
).issue;
|
||||
|
||||
const createdBy = await getRepository(User).findOneOrFail({
|
||||
const createdBy = await manager.getRepository(User).findOneOrFail({
|
||||
where: { id: issue.createdBy.id },
|
||||
});
|
||||
|
||||
const media = await getRepository(Media).findOneOrFail({
|
||||
const media = await manager.getRepository(Media).findOneOrFail({
|
||||
where: { id: issue.media.id },
|
||||
});
|
||||
|
||||
@@ -92,11 +98,11 @@ export class IssueCommentSubscriber implements EntitySubscriberInterface<IssueCo
|
||||
}
|
||||
}
|
||||
|
||||
public afterInsert(event: InsertEvent<IssueComment>): void {
|
||||
public async afterInsert(event: InsertEvent<IssueComment>): Promise<void> {
|
||||
if (!event.entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendIssueCommentNotification(event.entity);
|
||||
await this.sendIssueCommentNotification(event.manager, event.entity);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user