import { Service } from 'typedi'; import { DataSource, Repository } from 'typeorm'; import type { RoleNames, RoleScopes } from '../entities/Role'; import { Role } from '../entities/Role'; @Service() export class RoleRepository extends Repository { constructor(dataSource: DataSource) { super(Role, dataSource.manager); } async findGlobalOwnerRole(): Promise { return this.findRole('global', 'owner'); } async findGlobalOwnerRoleOrFail(): Promise { return this.findRoleOrFail('global', 'owner'); } async findGlobalMemberRole(): Promise { return this.findRole('global', 'member'); } async findGlobalMemberRoleOrFail(): Promise { return this.findRoleOrFail('global', 'member'); } async findWorkflowOwnerRole(): Promise { return this.findRole('workflow', 'owner'); } async findWorkflowOwnerRoleOrFail(): Promise { return this.findRoleOrFail('workflow', 'owner'); } async findWorkflowEditorRoleOrFail(): Promise { return this.findRoleOrFail('workflow', 'editor'); } async findCredentialOwnerRole(): Promise { return this.findRole('credential', 'owner'); } async findCredentialOwnerRoleOrFail(): Promise { return this.findRoleOrFail('credential', 'owner'); } async findCredentialUserRole(): Promise { return this.findRole('credential', 'user'); } async findRole(scope: RoleScopes, name: RoleNames): Promise { return this.findOne({ where: { scope, name } }); } async findRoleOrFail(scope: RoleScopes, name: RoleNames): Promise { return this.findOneOrFail({ where: { scope, name } }); } }