@@ -4,7 +4,7 @@ import * as schema from '@/db/schema'
4
4
import { getAuthenticatedUserDB } from './users'
5
5
import { z } from 'zod'
6
6
import { zValidator } from '@hono/zod-validator'
7
- import { eq , desc , getTableColumns , sql } from 'drizzle-orm'
7
+ import { eq , desc , and , getTableColumns , sql } from 'drizzle-orm'
8
8
9
9
const projects = new Hono < HonoServer > ( )
10
10
. get ( '/:pid' , zValidator ( 'param' , z . object ( { pid : z . string ( ) } ) ) , async ( c ) => {
@@ -28,7 +28,7 @@ const projects = new Hono<HonoServer>()
28
28
// tracking bug: https://github.com/drizzle-team/drizzle-orm/issues/555
29
29
// const {id: buildId, userId: buildUserId, projectId: buildRepoId, ...buildCols} = getTableColumns(schema.builds)
30
30
const projectBuilds = await db
31
- . selectDistinct ( {
31
+ . select ( {
32
32
builtBy : sql < string | null > `${ schema . builds . builtBy } ` . as ( 'build_built_by' ) ,
33
33
builtWith : sql < string | null > `${ schema . builds . builtWith } ` . as ( 'build_built_with' ) ,
34
34
commitSha : sql < string | null > `${ schema . builds . commitSha } ` . as ( 'build_commit_sha' ) ,
@@ -49,12 +49,13 @@ const projects = new Hono<HonoServer>()
49
49
tag : sql < string | null > `${ schema . builds . tag } ` . as ( 'build_tag' )
50
50
} )
51
51
. from ( schema . projects )
52
- . innerJoin ( schema . builds , eq ( schema . builds . projectPid , pid ) )
53
- . where ( eq ( schema . projects . userId , userId ) )
52
+ . innerJoin ( schema . builds , eq ( schema . builds . projectId , schema . projects . id ) )
53
+ . where ( and ( eq ( schema . projects . userId , userId ) , eq ( schema . builds . projectPid , pid ) ) )
54
54
. limit ( 50 )
55
55
. orderBy ( desc ( schema . builds . createdAt ) )
56
56
57
57
if ( projects && projectBuilds ) {
58
+ console . log ( projectBuilds )
58
59
return c . json ( { projects : projectsRes , projectBuilds} , 200 )
59
60
}
60
61
return c . json ( { message : 'User not found or incorrect authentication' } , 404 )
0 commit comments