File tree Expand file tree Collapse file tree
app/api/cron/fold-table-row-changes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { createLogger } from '@sim/logger'
22import { 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'
38import { verifyCronAuth } from '@/lib/auth/internal'
49import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
510import { 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} )
Original file line number Diff line number Diff 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+ } )
You can’t perform that action at this time.
0 commit comments