mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -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 validator from 'validator';
|
||||||
import { In } from 'typeorm';
|
|
||||||
import { Authorized, Get, Post, RestController } from '@/decorators';
|
import { Authorized, Get, Post, RestController } from '@/decorators';
|
||||||
import { issueCookie, resolveJwt } from '@/auth/jwt';
|
import { issueCookie, resolveJwt } from '@/auth/jwt';
|
||||||
import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES } from '@/constants';
|
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 { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||||
import { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
|
import { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
|
||||||
import { ApplicationError } from 'n8n-workflow';
|
import { ApplicationError } from 'n8n-workflow';
|
||||||
|
import { UserRepository } from '@/databases/repositories/user.repository';
|
||||||
|
|
||||||
@RestController()
|
@RestController()
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
|
@ -34,6 +34,7 @@ export class AuthController {
|
||||||
private readonly mfaService: MfaService,
|
private readonly mfaService: MfaService,
|
||||||
private readonly userService: UserService,
|
private readonly userService: UserService,
|
||||||
private readonly license: License,
|
private readonly license: License,
|
||||||
|
private readonly userRepository: UserRepository,
|
||||||
private readonly postHog?: PostHogClient,
|
private readonly postHog?: PostHogClient,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -186,10 +187,8 @@ export class AuthController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const users = await this.userService.findMany({
|
const users = await this.userRepository.findManybyIds([inviterId, inviteeId]);
|
||||||
where: { id: In([inviterId, inviteeId]) },
|
|
||||||
relations: ['globalRole'],
|
|
||||||
});
|
|
||||||
if (users.length !== 2) {
|
if (users.length !== 2) {
|
||||||
this.logger.debug(
|
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',
|
'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 { Response } from 'express';
|
||||||
|
|
||||||
import config from '@/config';
|
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 { UnauthorizedError } from '@/errors/response-errors/unauthorized.error';
|
||||||
import { InternalHooks } from '@/InternalHooks';
|
import { InternalHooks } from '@/InternalHooks';
|
||||||
import { ExternalHooks } from '@/ExternalHooks';
|
import { ExternalHooks } from '@/ExternalHooks';
|
||||||
|
import { UserRepository } from '@/databases/repositories/user.repository';
|
||||||
|
|
||||||
@Authorized()
|
@Authorized()
|
||||||
@RestController('/invitations')
|
@RestController('/invitations')
|
||||||
|
@ -29,6 +29,7 @@ export class InvitationController {
|
||||||
private readonly userService: UserService,
|
private readonly userService: UserService,
|
||||||
private readonly license: License,
|
private readonly license: License,
|
||||||
private readonly passwordUtility: PasswordUtility,
|
private readonly passwordUtility: PasswordUtility,
|
||||||
|
private readonly userRepository: UserRepository,
|
||||||
private readonly postHog: PostHogClient,
|
private readonly postHog: PostHogClient,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -135,10 +136,7 @@ export class InvitationController {
|
||||||
|
|
||||||
const validPassword = this.passwordUtility.validate(password);
|
const validPassword = this.passwordUtility.validate(password);
|
||||||
|
|
||||||
const users = await this.userService.findMany({
|
const users = await this.userRepository.findManybyIds([inviterId, inviteeId]);
|
||||||
where: { id: In([inviterId, inviteeId]) },
|
|
||||||
relations: ['globalRole'],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (users.length !== 2) {
|
if (users.length !== 2) {
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
import { DataSource, Repository } from 'typeorm';
|
import { DataSource, In, Repository } from 'typeorm';
|
||||||
import { User } from '../entities/User';
|
import { User } from '../entities/User';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
|
@ -7,4 +7,11 @@ export class UserRepository extends Repository<User> {
|
||||||
constructor(dataSource: DataSource) {
|
constructor(dataSource: DataSource) {
|
||||||
super(User, dataSource.manager);
|
super(User, dataSource.manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findManybyIds(userIds: string[]) {
|
||||||
|
return this.find({
|
||||||
|
where: { id: In(userIds) },
|
||||||
|
relations: ['globalRole'],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue