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
@@ -1,18 +1,18 @@
|
||||
import { Service } from 'typedi';
|
||||
import type { EntityManager, FindOptionsWhere } from 'typeorm';
|
||||
import * as Db from '@/Db';
|
||||
import { Role } from '@db/entities/Role';
|
||||
import { SharedWorkflowRepository } from '@db/repositories';
|
||||
|
||||
@Service()
|
||||
export class RoleService {
|
||||
static async get(role: FindOptionsWhere<Role>): Promise<Role | null> {
|
||||
return Db.collections.Role.findOneBy(role);
|
||||
}
|
||||
constructor(private sharedWorkflowRepository: SharedWorkflowRepository) {}
|
||||
|
||||
static async trxGet(transaction: EntityManager, role: FindOptionsWhere<Role>) {
|
||||
return transaction.findOneBy(Role, role);
|
||||
}
|
||||
|
||||
static async getUserRoleForWorkflow(userId: string, workflowId: string) {
|
||||
const shared = await Db.collections.SharedWorkflow.findOne({
|
||||
async getUserRoleForWorkflow(userId: string, workflowId: string) {
|
||||
const shared = await this.sharedWorkflowRepository.findOne({
|
||||
where: { workflowId, userId },
|
||||
relations: ['role'],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user