mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
refactor(core): Continue moving typeorm operators to repositories (no-changelog) (#8186)
Follow-up to: #8163
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import { Container, Service } from 'typedi';
|
||||
import type { EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import { User } from '@db/entities/User';
|
||||
import type { IUserSettings } from 'n8n-workflow';
|
||||
import { UserRepository } from '@db/repositories/user.repository';
|
||||
@@ -29,38 +27,10 @@ export class UserService {
|
||||
private readonly urlService: UrlService,
|
||||
) {}
|
||||
|
||||
async findOne(options: FindOneOptions<User>) {
|
||||
return this.userRepository.findOne({ relations: ['globalRole'], ...options });
|
||||
}
|
||||
|
||||
async findOneOrFail(options: FindOneOptions<User>) {
|
||||
return this.userRepository.findOneOrFail({ relations: ['globalRole'], ...options });
|
||||
}
|
||||
|
||||
async findMany(options: FindManyOptions<User>) {
|
||||
return this.userRepository.find(options);
|
||||
}
|
||||
|
||||
async findOneBy(options: FindOptionsWhere<User>) {
|
||||
return this.userRepository.findOneBy(options);
|
||||
}
|
||||
|
||||
create(data: Partial<User>) {
|
||||
return this.userRepository.create(data);
|
||||
}
|
||||
|
||||
async save(user: Partial<User>) {
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
|
||||
async update(userId: string, data: Partial<User>) {
|
||||
return this.userRepository.update(userId, data);
|
||||
}
|
||||
|
||||
async getByIds(transaction: EntityManager, ids: string[]) {
|
||||
return transaction.find(User, { where: { id: In(ids) } });
|
||||
}
|
||||
|
||||
getManager() {
|
||||
return this.userRepository.manager;
|
||||
}
|
||||
@@ -257,12 +227,9 @@ export class UserService {
|
||||
async inviteUsers(owner: User, attributes: Array<{ email: string; role: 'member' | 'admin' }>) {
|
||||
const memberRole = await this.roleService.findGlobalMemberRole();
|
||||
const adminRole = await this.roleService.findGlobalAdminRole();
|
||||
const emails = attributes.map(({ email }) => email);
|
||||
|
||||
const existingUsers = await this.findMany({
|
||||
where: { email: In(attributes.map(({ email }) => email)) },
|
||||
relations: ['globalRole'],
|
||||
select: ['email', 'password', 'id'],
|
||||
});
|
||||
const existingUsers = await this.userRepository.findManyByEmail(emails);
|
||||
|
||||
const existUsersEmails = existingUsers.map((user) => user.email);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user