mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
refactor(core): Move more typeorm
operators to UserRepository
(no-changelog) (#8165)
Follow-up to: #8163
This commit is contained in:
parent
5aee7a1d48
commit
0e582594ea
|
@ -1,5 +1,4 @@
|
|||
import validator from 'validator';
|
||||
import { In } from 'typeorm';
|
||||
import { Authorized, Get, Post, RestController } from '@/decorators';
|
||||
import { issueCookie, resolveJwt } from '@/auth/jwt';
|
||||
import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES } from '@/constants';
|
||||
|
@ -25,6 +24,7 @@ import { InternalServerError } from '@/errors/response-errors/internal-server.er
|
|||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||
import { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
|
||||
import { ApplicationError } from 'n8n-workflow';
|
||||
import { UserRepository } from '@/databases/repositories/user.repository';
|
||||
|
||||
@RestController()
|
||||
export class AuthController {
|
||||
|
@ -34,6 +34,7 @@ export class AuthController {
|
|||
private readonly mfaService: MfaService,
|
||||
private readonly userService: UserService,
|
||||
private readonly license: License,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly postHog?: PostHogClient,
|
||||
) {}
|
||||
|
||||
|
@ -186,10 +187,8 @@ export class AuthController {
|
|||
}
|
||||
}
|
||||
|
||||
const users = await this.userService.findMany({
|
||||
where: { id: In([inviterId, inviteeId]) },
|
||||
relations: ['globalRole'],
|
||||
});
|
||||
const users = await this.userRepository.findManybyIds([inviterId, inviteeId]);
|
||||
|
||||
if (users.length !== 2) {
|
||||
this.logger.debug(
|
||||
'Request to resolve signup token failed because the ID of the inviter and/or the ID of the invitee were not found in database',
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { In } from 'typeorm';
|
||||
import { Response } from 'express';
|
||||
|
||||
import config from '@/config';
|
||||
|
@ -18,6 +17,7 @@ import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
|||
import { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { ExternalHooks } from '@/ExternalHooks';
|
||||
import { UserRepository } from '@/databases/repositories/user.repository';
|
||||
|
||||
@Authorized()
|
||||
@RestController('/invitations')
|
||||
|
@ -29,6 +29,7 @@ export class InvitationController {
|
|||
private readonly userService: UserService,
|
||||
private readonly license: License,
|
||||
private readonly passwordUtility: PasswordUtility,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly postHog: PostHogClient,
|
||||
) {}
|
||||
|
||||
|
@ -135,10 +136,7 @@ export class InvitationController {
|
|||
|
||||
const validPassword = this.passwordUtility.validate(password);
|
||||
|
||||
const users = await this.userService.findMany({
|
||||
where: { id: In([inviterId, inviteeId]) },
|
||||
relations: ['globalRole'],
|
||||
});
|
||||
const users = await this.userRepository.findManybyIds([inviterId, inviteeId]);
|
||||
|
||||
if (users.length !== 2) {
|
||||
this.logger.debug(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Service } from 'typedi';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { DataSource, In, Repository } from 'typeorm';
|
||||
import { User } from '../entities/User';
|
||||
|
||||
@Service()
|
||||
|
@ -7,4 +7,11 @@ export class UserRepository extends Repository<User> {
|
|||
constructor(dataSource: DataSource) {
|
||||
super(User, dataSource.manager);
|
||||
}
|
||||
|
||||
async findManybyIds(userIds: string[]) {
|
||||
return this.find({
|
||||
where: { id: In(userIds) },
|
||||
relations: ['globalRole'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue