diff --git a/packages/cli/src/databases/subscribers/UserSubscriber.ts b/packages/cli/src/databases/subscribers/UserSubscriber.ts index e5fad5bf53698..b925965a0c912 100644 --- a/packages/cli/src/databases/subscribers/UserSubscriber.ts +++ b/packages/cli/src/databases/subscribers/UserSubscriber.ts @@ -1,12 +1,12 @@ +import { Container } from 'typedi'; import type { EntitySubscriberInterface, UpdateEvent } from '@n8n/typeorm'; import { EventSubscriber } from '@n8n/typeorm'; -import { User } from '../entities/User'; -import Container from 'typedi'; -import { ProjectRepository } from '../repositories/project.repository'; import { ApplicationError, ErrorReporterProxy } from 'n8n-workflow'; import { Logger } from '@/Logger'; -import { UserRepository } from '../repositories/user.repository'; + import { Project } from '../entities/Project'; +import { User } from '../entities/User'; +import { UserRepository } from '../repositories/user.repository'; @EventSubscriber() export class UserSubscriber implements EntitySubscriberInterface { @@ -27,14 +27,17 @@ export class UserSubscriber implements EntitySubscriberInterface { fields.includes('email') ) { const oldUser = event.databaseEntity; - const name = + const userEntity = newUserData instanceof User - ? newUserData.createPersonalProjectName() - : Container.get(UserRepository).create(newUserData).createPersonalProjectName(); + ? newUserData + : Container.get(UserRepository).create(newUserData); + + const projectName = userEntity.createPersonalProjectName(); - const project = await Container.get(ProjectRepository).getPersonalProjectForUser( - oldUser.id, - ); + const project = await event.manager.findOneBy(Project, { + type: 'personal', + projectRelations: { userId: oldUser.id }, + }); if (!project) { // Since this is benign we're not throwing the exception. We don't @@ -47,7 +50,7 @@ export class UserSubscriber implements EntitySubscriberInterface { return; } - project.name = name; + project.name = projectName; await event.manager.save(Project, project); }