Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { authHandler } from '$/middlewares/authHandler'
import { errorHandler } from '$/middlewares/errorHandler'

import { RunSourceGroup, SpanType } from '@latitude-data/constants'
import {
CompletedRun,
RunSourceGroup,
SpanType,
} from '@latitude-data/constants'
import { listCompletedRuns } from '@latitude-data/core/services/runs/completed/listCompleted'
import { Workspace } from '@latitude-data/core/schema/models/types/Workspace'
import { NextRequest, NextResponse } from 'next/server'

export const GET = errorHandler(
export const GET = errorHandler<CompletedRun[]>(
authHandler(
async (
request: NextRequest,
Expand Down Expand Up @@ -43,7 +47,7 @@ export const GET = errorHandler(
next: runs.next ? JSON.stringify(runs.next) : null,
}

return NextResponse.json(response, { status: 200 })
return NextResponse.json(response.items, { status: 200 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the bug 🐛 . Now that you're here remove response constant enterely 🔥

},
),
)
3 changes: 2 additions & 1 deletion apps/web/src/middlewares/adminHandler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getCurrentUserOrRedirect } from '$/services/auth/getCurrentUser'
import { notFound } from 'next/navigation'
import { NextRequest } from 'next/server'
import { RouteHandler } from './types'

export function adminHandler(handler: any) {
export function adminHandler<T>(handler: RouteHandler<T>) {
return async (
req: NextRequest,
{ params, ...rest }: { params?: Promise<Record<string, string>> } = {},
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/middlewares/authHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getDataFromSession } from '$/data-access'
import { NextRequest, NextResponse } from 'next/server'
import { RouteHandler } from './types'

export function authHandler(handler: any) {
export function authHandler<T>(handler: RouteHandler<T>) {
return async (
req: NextRequest,
{
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/middlewares/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { env } from '@latitude-data/env'
import { captureException } from '$/helpers/captureException'
import { NextRequest, NextResponse } from 'next/server'
import debug from '@latitude-data/core/lib/debug'
import { RouteHandler } from './types'

interface AbortError extends DOMException {
name: 'AbortError'
Expand All @@ -18,7 +19,7 @@ export function isAbortError(error: unknown): error is AbortError {
)
}

export function errorHandler(handler: any) {
export function errorHandler<T>(handler: RouteHandler<T>) {
const isDev = env.NODE_ENV === 'development'
return async (req: NextRequest, res: any) => {
try {
Expand Down
18 changes: 18 additions & 0 deletions apps/web/src/middlewares/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NextRequest, NextResponse } from 'next/server'

type ApiMessageResponse = {
message: string
}

type ApiErrorResponse = {
error: string
}

export type RouteHandler<T> = (
req: NextRequest,
res: any,
) => Promise<
| NextResponse<T>
| NextResponse<ApiErrorResponse>
| NextResponse<ApiMessageResponse>
>
12 changes: 0 additions & 12 deletions apps/web/src/services/routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,18 +399,6 @@ export const API_ROUTES = {
completed: {
root: `${projectRoot}/runs/completed`,
count: `${projectRoot}/runs/completed/count`,
detail: ({
limit,
sourceGroup,
}: {
limit?: number
sourceGroup?: RunSourceGroup
} = {}) => {
const params = new URLSearchParams()
if (limit) params.set('limit', limit.toString())
if (sourceGroup) params.set('sourceGroup', sourceGroup)
return `${projectRoot}/runs/completed?${params.toString()}`
},
},
detail: (uuid: string) => ({
root: `${projectRoot}/runs/${uuid}`,
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/stores/runs/completedRuns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import { useCallback, useMemo } from 'react'
import useSWR, { SWRConfiguration } from 'swr'
import { compactObject } from '@latitude-data/core/lib/compactObject'

export function useCompletedRuns(
{
Expand All @@ -32,7 +33,13 @@ export function useCompletedRuns(
opts?: SWRConfiguration,
) {
const fetcher = useFetcher<CompletedRun[]>(
ROUTES.api.projects.detail(project.id).runs.completed.detail(search),
ROUTES.api.projects.detail(project.id).runs.completed.root,
{
searchParams: compactObject({
limit: search?.limit ? search.limit.toString() : undefined,
sourceGroup: search?.sourceGroup,
}) as Record<string, string>,
},
)

const {
Expand Down
Loading