Skip to content

Commit fe3c623

Browse files
fix(tables): give the fold cron route a response contract
1 parent 98bfafd commit fe3c623

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎apps/sim/app/api/cron/fold-table-row-changes/route.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
3+
import {
4+
type FoldTableRowChangesResponse,
5+
foldTableRowChangesContract,
6+
} from '@/lib/api/contracts/tables'
7+
import { parseRequest } from '@/lib/api/server/validation'
38
import { verifyCronAuth } from '@/lib/auth/internal'
49
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
510
import { foldPendingTableRowChanges } from '@/lib/table/row-changes'
@@ -20,7 +25,11 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
2025
const authError = verifyCronAuth(request, 'Table row-change fold')
2126
if (authError) return authError
2227

28+
const parsed = await parseRequest(foldTableRowChangesContract, request, {})
29+
if (!parsed.success) return parsed.response
30+
2331
const result = await foldPendingTableRowChanges(FOLD_SWEEP_BUDGET_MS)
2432
logger.info('Table row-change fold sweep completed', { ...result })
25-
return NextResponse.json({ success: true, ...result })
33+
const body: FoldTableRowChangesResponse = { success: true, ...result }
34+
return NextResponse.json(body)
2635
})

‎apps/sim/lib/api/contracts/tables.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,3 +2326,18 @@ export const bulkDeleteTablesContract = defineRouteContract({
23262326
),
23272327
},
23282328
})
2329+
2330+
const foldTableRowChangesResponseSchema = z.object({
2331+
success: z.literal(true),
2332+
folded: z.number().int().min(0),
2333+
skipped: z.number().int().min(0),
2334+
budgetExhausted: z.boolean(),
2335+
})
2336+
2337+
export type FoldTableRowChangesResponse = z.output<typeof foldTableRowChangesResponseSchema>
2338+
2339+
export const foldTableRowChangesContract = defineRouteContract({
2340+
method: 'GET',
2341+
path: '/api/cron/fold-table-row-changes',
2342+
response: { mode: 'json', schema: foldTableRowChangesResponseSchema },
2343+
})

0 commit comments

Comments
 (0)