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:
कारतोफ्फेलस्क्रिप्ट™
2023-04-12 10:59:14 +02:00
committed by GitHub
parent 323e26acfd
commit 10f8c35dbb
67 changed files with 557 additions and 270 deletions

View File

@@ -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'],
});