@@ -27,16 +27,7 @@ const logger = createLogger('ScheduleAPI')
2727
2828export const dynamic = 'force-dynamic'
2929
30- type ScheduleRow = {
31- id : string
32- workflowId : string | null
33- status : string
34- cronExpression : string | null
35- timezone : string | null
36- sourceType : string | null
37- sourceWorkspaceId : string | null
38- jobTitle : string | null
39- }
30+ type ScheduleRow = typeof workflowSchedule . $inferSelect
4031
4132async function fetchAndAuthorize (
4233 requestId : string ,
@@ -45,16 +36,7 @@ async function fetchAndAuthorize(
4536 action : 'read' | 'write'
4637) : Promise < { schedule : ScheduleRow ; workspaceId : string | null } | NextResponse > {
4738 const [ schedule ] = await db
48- . select ( {
49- id : workflowSchedule . id ,
50- workflowId : workflowSchedule . workflowId ,
51- status : workflowSchedule . status ,
52- cronExpression : workflowSchedule . cronExpression ,
53- timezone : workflowSchedule . timezone ,
54- sourceType : workflowSchedule . sourceType ,
55- sourceWorkspaceId : workflowSchedule . sourceWorkspaceId ,
56- jobTitle : workflowSchedule . jobTitle ,
57- } )
39+ . select ( )
5840 . from ( workflowSchedule )
5941 . where ( and ( eq ( workflowSchedule . id , scheduleId ) , isNull ( workflowSchedule . archivedAt ) ) )
6042 . limit ( 1 )
@@ -121,20 +103,12 @@ export const GET = withRouteHandler(
121103
122104 const { id : scheduleId } = parsed . data . params
123105
106+ // fetchAndAuthorize already loads the full row (and 404s if missing), so
107+ // return it directly — no second query.
124108 const authResult = await fetchAndAuthorize ( requestId , scheduleId , session . user . id , 'read' )
125109 if ( authResult instanceof NextResponse ) return authResult
126110
127- const [ row ] = await db
128- . select ( )
129- . from ( workflowSchedule )
130- . where ( and ( eq ( workflowSchedule . id , scheduleId ) , isNull ( workflowSchedule . archivedAt ) ) )
131- . limit ( 1 )
132-
133- if ( ! row ) {
134- return NextResponse . json ( { error : 'Schedule not found' } , { status : 404 } )
135- }
136-
137- return NextResponse . json ( { schedule : row } )
111+ return NextResponse . json ( { schedule : authResult . schedule } )
138112 } catch ( error ) {
139113 logger . error ( `[${ requestId } ] Failed to get schedule` , { error } )
140114 return NextResponse . json ( { error : 'Failed to get schedule' } , { status : 500 } )
0 commit comments