Skip to content

Commit

Permalink
fix UserSubscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 22, 2024
1 parent 6614fa1 commit beea55c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/cli/src/databases/subscribers/UserSubscriber.ts
Original file line number Diff line number Diff line change
@@ -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<User> {
Expand All @@ -27,14 +27,17 @@ export class UserSubscriber implements EntitySubscriberInterface<User> {
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
Expand All @@ -47,7 +50,7 @@ export class UserSubscriber implements EntitySubscriberInterface<User> {
return;
}

project.name = name;
project.name = projectName;

await event.manager.save(Project, project);
}
Expand Down

0 comments on commit beea55c

Please sign in to comment.