Files
n8n-enterprise-unlocked/packages/cli/src/role/role.service.ts
कारतोफ्फेलस्क्रिप्ट™ 10f8c35dbb refactor(core): Use injectable classes for db repositories (part-1) (no-changelog) (#5953)
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
2023-04-12 10:59:14 +02:00

22 lines
669 B
TypeScript

import { Service } from 'typedi';
import type { EntityManager, FindOptionsWhere } from 'typeorm';
import { Role } from '@db/entities/Role';
import { SharedWorkflowRepository } from '@db/repositories';
@Service()
export class RoleService {
constructor(private sharedWorkflowRepository: SharedWorkflowRepository) {}
static async trxGet(transaction: EntityManager, role: FindOptionsWhere<Role>) {
return transaction.findOneBy(Role, role);
}
async getUserRoleForWorkflow(userId: string, workflowId: string) {
const shared = await this.sharedWorkflowRepository.findOne({
where: { workflowId, userId },
relations: ['role'],
});
return shared?.role;
}
}