refactor(core): Move active workflows endpoints to a decorated controller class (no-changelog) (#8101)
This is a continuation of migrating all rest endpoints to decorated controller classes
This commit is contained in:
committed by
GitHub
parent
39e45d8b92
commit
021add0f39
@@ -1,10 +1,31 @@
|
||||
import { Service } from 'typedi';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { DataSource, type FindOptionsWhere, Repository, In } from 'typeorm';
|
||||
import { SharedWorkflow } from '../entities/SharedWorkflow';
|
||||
import { type User } from '../entities/User';
|
||||
|
||||
@Service()
|
||||
export class SharedWorkflowRepository extends Repository<SharedWorkflow> {
|
||||
constructor(dataSource: DataSource) {
|
||||
super(SharedWorkflow, dataSource.manager);
|
||||
}
|
||||
|
||||
async hasAccess(workflowId: string, user: User) {
|
||||
const where: FindOptionsWhere<SharedWorkflow> = {
|
||||
workflowId,
|
||||
};
|
||||
if (!user.hasGlobalScope('workflow:read')) {
|
||||
where.userId = user.id;
|
||||
}
|
||||
return this.exist({ where });
|
||||
}
|
||||
|
||||
async getSharedWorkflowIds(workflowIds: string[]) {
|
||||
const sharedWorkflows = await this.find({
|
||||
select: ['workflowId'],
|
||||
where: {
|
||||
workflowId: In(workflowIds),
|
||||
},
|
||||
});
|
||||
return sharedWorkflows.map((sharing) => sharing.workflowId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,14 @@ export class WorkflowRepository extends Repository<WorkflowEntity> {
|
||||
});
|
||||
}
|
||||
|
||||
async getActiveIds() {
|
||||
const activeWorkflows = await this.find({
|
||||
select: ['id'],
|
||||
where: { active: true },
|
||||
});
|
||||
return activeWorkflows.map((workflow) => workflow.id);
|
||||
}
|
||||
|
||||
async findById(workflowId: string) {
|
||||
return this.findOne({
|
||||
where: { id: workflowId },
|
||||
|
||||
Reference in New Issue
Block a user