refactor: Upgrade typeorm to 0.3.x (#5151)
This commit is contained in:
committed by
GitHub
parent
6608e69457
commit
0a5ab560b1
@@ -1,6 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import { INode, NodeOperationError, Workflow } from 'n8n-workflow';
|
||||
import { In } from 'typeorm';
|
||||
import express from 'express';
|
||||
import { compare, genSaltSync, hash } from 'bcryptjs';
|
||||
@@ -21,7 +20,7 @@ export async function getWorkflowOwner(workflowId: string): Promise<User> {
|
||||
const workflowOwnerRole = await RoleService.get({ name: 'owner', scope: 'workflow' });
|
||||
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOneOrFail({
|
||||
where: { workflowId, role: workflowOwnerRole },
|
||||
where: { workflowId, roleId: workflowOwnerRole?.id ?? undefined },
|
||||
relations: ['user', 'user.globalRole'],
|
||||
});
|
||||
|
||||
@@ -59,35 +58,26 @@ export function isUserManagementDisabled(): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
async function getInstanceOwnerRole(): Promise<Role> {
|
||||
const ownerRole = await Db.collections.Role.findOneOrFail({
|
||||
where: {
|
||||
name: 'owner',
|
||||
scope: 'global',
|
||||
},
|
||||
});
|
||||
return ownerRole;
|
||||
}
|
||||
|
||||
export async function getInstanceOwner(): Promise<User> {
|
||||
const ownerRole = await getInstanceOwnerRole();
|
||||
|
||||
const owner = await Db.collections.User.findOneOrFail({
|
||||
relations: ['globalRole'],
|
||||
where: {
|
||||
globalRole: ownerRole,
|
||||
},
|
||||
});
|
||||
return owner;
|
||||
}
|
||||
|
||||
export async function getRole(scope: Role['scope'], name: Role['name']): Promise<Role> {
|
||||
export async function getRoleId(scope: Role['scope'], name: Role['name']): Promise<Role['id']> {
|
||||
return Db.collections.Role.findOneOrFail({
|
||||
select: ['id'],
|
||||
where: {
|
||||
name,
|
||||
scope,
|
||||
},
|
||||
}).then((role) => role.id);
|
||||
}
|
||||
|
||||
export async function getInstanceOwner(): Promise<User> {
|
||||
const ownerRoleId = await getRoleId('global', 'owner');
|
||||
|
||||
const owner = await Db.collections.User.findOneOrFail({
|
||||
relations: ['globalRole'],
|
||||
where: {
|
||||
globalRoleId: ownerRoleId,
|
||||
},
|
||||
});
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,7 +158,8 @@ export function addInviteLinktoUser(user: PublicUser, inviterId: string): Public
|
||||
}
|
||||
|
||||
export async function getUserById(userId: string): Promise<User> {
|
||||
const user = await Db.collections.User.findOneOrFail(userId, {
|
||||
const user = await Db.collections.User.findOneOrFail({
|
||||
where: { id: userId },
|
||||
relations: ['globalRole'],
|
||||
});
|
||||
return user;
|
||||
|
||||
Reference in New Issue
Block a user