Fix notifications breaking due to deleted role being assigned

This commit is contained in:
JeDaYoshi 2024-12-13 16:46:34 -04:00
parent 9dc03858bd
commit 535e0c69ce
No known key found for this signature in database
GPG key ID: 8060B288C274219D

View file

@ -5,7 +5,7 @@
import { Inject, Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core'; import { ModuleRef } from '@nestjs/core';
import { In } from 'typeorm'; import { In, EntityNotFoundError } from 'typeorm';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import type { FollowRequestsRepository, NotesRepository, MiUser, UsersRepository } from '@/models/_.js'; import type { FollowRequestsRepository, NotesRepository, MiUser, UsersRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js'; import { awaitAll } from '@/misc/prelude/await-all.js';
@ -140,7 +140,12 @@ export class NotificationEntityService implements OnModuleInit {
// #endregion // #endregion
const needsRole = notification.type === 'roleAssigned'; const needsRole = notification.type === 'roleAssigned';
const role = needsRole ? await this.roleEntityService.pack(notification.roleId) : undefined; const role = needsRole
? await this.roleEntityService.pack(notification.roleId).catch(err => {
if (err instanceof EntityNotFoundError) return undefined;
throw err;
})
: undefined;
// if the role has been deleted, don't show this notification // if the role has been deleted, don't show this notification
if (needsRole && !role) { if (needsRole && !role) {
return null; return null;