feat: Nudge users to become template creators if eligible (#8357)
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { Service } from 'typedi';
|
||||
import { DataSource, QueryFailedError, Repository } from 'typeorm';
|
||||
import config from '@/config';
|
||||
import type { StatisticsNames } from '../entities/WorkflowStatistics';
|
||||
import { WorkflowStatistics } from '../entities/WorkflowStatistics';
|
||||
import { StatisticsNames, WorkflowStatistics } from '../entities/WorkflowStatistics';
|
||||
import type { User } from '@/databases/entities/User';
|
||||
import { WorkflowEntity } from '@/databases/entities/WorkflowEntity';
|
||||
import { SharedWorkflow } from '@/databases/entities/SharedWorkflow';
|
||||
import { Role } from '@/databases/entities/Role';
|
||||
|
||||
type StatisticsInsertResult = 'insert' | 'failed' | 'alreadyExists';
|
||||
type StatisticsUpsertResult = StatisticsInsertResult | 'update';
|
||||
@@ -98,4 +101,21 @@ export class WorkflowStatisticsRepository extends Repository<WorkflowStatistics>
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async queryNumWorkflowsUserHasWithFiveOrMoreProdExecs(userId: User['id']): Promise<number> {
|
||||
return await this.createQueryBuilder('workflow_statistics')
|
||||
.innerJoin(WorkflowEntity, 'workflow', 'workflow.id = workflow_statistics.workflowId')
|
||||
.innerJoin(
|
||||
SharedWorkflow,
|
||||
'shared_workflow',
|
||||
'shared_workflow.workflowId = workflow_statistics.workflowId',
|
||||
)
|
||||
.innerJoin(Role, 'role', 'role.id = shared_workflow.roleId')
|
||||
.where('shared_workflow.userId = :userId', { userId })
|
||||
.andWhere('workflow.active = :isActive', { isActive: true })
|
||||
.andWhere('workflow_statistics.name = :name', { name: StatisticsNames.productionSuccess })
|
||||
.andWhere('workflow_statistics.count >= 5')
|
||||
.andWhere('role.name = :roleName', { roleName: 'owner' })
|
||||
.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user