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
59
packages/cli/src/databases/repositories/role.repository.ts
Normal file
59
packages/cli/src/databases/repositories/role.repository.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
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<Role> {
|
||||
constructor(dataSource: DataSource) {
|
||||
super(Role, dataSource.manager);
|
||||
}
|
||||
|
||||
async findGlobalOwnerRole(): Promise<Role | null> {
|
||||
return this.findRole('global', 'owner');
|
||||
}
|
||||
|
||||
async findGlobalOwnerRoleOrFail(): Promise<Role> {
|
||||
return this.findRoleOrFail('global', 'owner');
|
||||
}
|
||||
|
||||
async findGlobalMemberRole(): Promise<Role | null> {
|
||||
return this.findRole('global', 'member');
|
||||
}
|
||||
|
||||
async findGlobalMemberRoleOrFail(): Promise<Role> {
|
||||
return this.findRoleOrFail('global', 'member');
|
||||
}
|
||||
|
||||
async findWorkflowOwnerRole(): Promise<Role | null> {
|
||||
return this.findRole('workflow', 'owner');
|
||||
}
|
||||
|
||||
async findWorkflowOwnerRoleOrFail(): Promise<Role> {
|
||||
return this.findRoleOrFail('workflow', 'owner');
|
||||
}
|
||||
|
||||
async findWorkflowEditorRoleOrFail(): Promise<Role> {
|
||||
return this.findRoleOrFail('workflow', 'editor');
|
||||
}
|
||||
|
||||
async findCredentialOwnerRole(): Promise<Role | null> {
|
||||
return this.findRole('credential', 'owner');
|
||||
}
|
||||
|
||||
async findCredentialOwnerRoleOrFail(): Promise<Role> {
|
||||
return this.findRoleOrFail('credential', 'owner');
|
||||
}
|
||||
|
||||
async findCredentialUserRole(): Promise<Role | null> {
|
||||
return this.findRole('credential', 'user');
|
||||
}
|
||||
|
||||
async findRole(scope: RoleScopes, name: RoleNames): Promise<Role | null> {
|
||||
return this.findOne({ where: { scope, name } });
|
||||
}
|
||||
|
||||
async findRoleOrFail(scope: RoleScopes, name: RoleNames): Promise<Role> {
|
||||
return this.findOneOrFail({ where: { scope, name } });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user