(requestId: string, userId: string, workspaceId: string)
| 121 | }) |
| 122 | |
| 123 | async function handleWorkspaceSchedules(requestId: string, userId: string, workspaceId: string) { |
| 124 | const hasPermission = await verifyWorkspaceMembership(userId, workspaceId) |
| 125 | if (!hasPermission) { |
| 126 | return NextResponse.json({ error: 'Not authorized' }, { status: 403 }) |
| 127 | } |
| 128 | |
| 129 | logger.info(`[${requestId}] Getting all schedules for workspace ${workspaceId}`) |
| 130 | |
| 131 | const [workflowRows, jobRows] = await Promise.all([ |
| 132 | db |
| 133 | .select({ |
| 134 | schedule: workflowSchedule, |
| 135 | workflowName: workflow.name, |
| 136 | }) |
| 137 | .from(workflowSchedule) |
| 138 | .innerJoin(workflow, eq(workflow.id, workflowSchedule.workflowId)) |
| 139 | .leftJoin( |
| 140 | workflowDeploymentVersion, |
| 141 | and( |
| 142 | eq(workflowDeploymentVersion.workflowId, workflowSchedule.workflowId), |
| 143 | eq(workflowDeploymentVersion.isActive, true) |
| 144 | ) |
| 145 | ) |
| 146 | .where( |
| 147 | and( |
| 148 | eq(workflow.workspaceId, workspaceId), |
| 149 | isNull(workflow.archivedAt), |
| 150 | eq(workflowSchedule.triggerType, 'schedule'), |
| 151 | isNull(workflowSchedule.archivedAt), |
| 152 | or(eq(workflowSchedule.sourceType, 'workflow'), isNull(workflowSchedule.sourceType)), |
| 153 | or( |
| 154 | eq(workflowSchedule.deploymentVersionId, workflowDeploymentVersion.id), |
| 155 | and(isNull(workflowDeploymentVersion.id), isNull(workflowSchedule.deploymentVersionId)) |
| 156 | ) |
| 157 | ) |
| 158 | ), |
| 159 | db |
| 160 | .select({ schedule: workflowSchedule }) |
| 161 | .from(workflowSchedule) |
| 162 | .where( |
| 163 | and( |
| 164 | eq(workflowSchedule.sourceWorkspaceId, workspaceId), |
| 165 | eq(workflowSchedule.sourceType, 'job'), |
| 166 | isNull(workflowSchedule.archivedAt) |
| 167 | ) |
| 168 | ), |
| 169 | ]) |
| 170 | |
| 171 | const headers = new Headers() |
| 172 | headers.set('Cache-Control', 'no-store, max-age=0') |
| 173 | |
| 174 | const schedules = [ |
| 175 | ...workflowRows.map((r) => ({ |
| 176 | ...r.schedule, |
| 177 | workflowName: r.workflowName, |
| 178 | })), |
| 179 | ...jobRows.map((r) => ({ |
| 180 | ...r.schedule, |
no test coverage detected