refactor(core): Use injectable classes for db repositories (part-1) (no-changelog) (#5953)
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
committed by
GitHub
parent
323e26acfd
commit
10f8c35dbb
@@ -3,7 +3,7 @@
|
||||
import { In } from 'typeorm';
|
||||
import type express from 'express';
|
||||
import { compare, genSaltSync, hash } from 'bcryptjs';
|
||||
import Container from 'typedi';
|
||||
import { Container } from 'typedi';
|
||||
|
||||
import * as Db from '@/Db';
|
||||
import * as ResponseHelper from '@/ResponseHelper';
|
||||
@@ -11,15 +11,15 @@ import type { CurrentUser, PublicUser, WhereClause } from '@/Interfaces';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { MAX_PASSWORD_LENGTH, MIN_PASSWORD_LENGTH } from '@db/entities/User';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import { RoleRepository } from '@db/repositories';
|
||||
import type { AuthenticatedRequest } from '@/requests';
|
||||
import config from '@/config';
|
||||
import { getWebhookBaseUrl } from '@/WebhookHelpers';
|
||||
import { License } from '@/License';
|
||||
import { RoleService } from '@/role/role.service';
|
||||
import type { PostHogClient } from '@/posthog';
|
||||
|
||||
export async function getWorkflowOwner(workflowId: string): Promise<User> {
|
||||
const workflowOwnerRole = await RoleService.get({ name: 'owner', scope: 'workflow' });
|
||||
const workflowOwnerRole = await Container.get(RoleRepository).findWorkflowOwnerRole();
|
||||
|
||||
const sharedWorkflow = await Db.collections.SharedWorkflow.findOneOrFail({
|
||||
where: { workflowId, roleId: workflowOwnerRole?.id ?? undefined },
|
||||
@@ -61,13 +61,9 @@ export function isSharingEnabled(): boolean {
|
||||
}
|
||||
|
||||
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);
|
||||
return Container.get(RoleRepository)
|
||||
.findRoleOrFail(scope, name)
|
||||
.then((role) => role.id);
|
||||
}
|
||||
|
||||
export async function getInstanceOwner(): Promise<User> {
|
||||
|
||||
Reference in New Issue
Block a user