-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c55bd6f
commit cf4bf05
Showing
7 changed files
with
114 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { type NextRequest, NextResponse } from "next/server"; | ||
import { getCasts } from "@/lib/services/casts"; | ||
import { type NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { getCasts } from '@/lib/services/casts'; | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams; | ||
const fid = searchParams.get('fid'); | ||
if (!fid) { | ||
return NextResponse.json({ error: 'fid is required' }, { status: 400 }); | ||
} | ||
const casts = await getCasts(fid); | ||
return NextResponse.json({ casts }) | ||
const searchParams = request.nextUrl.searchParams; | ||
const fid = searchParams.get('fid'); | ||
if (!fid) { | ||
return NextResponse.json({ error: 'fid is required' }, { status: 400 }); | ||
} | ||
const casts = await getCasts(fid); | ||
return NextResponse.json({ casts }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { type NextRequest, NextResponse } from "next/server"; | ||
import { getProfile } from "@/lib/services/user"; | ||
import { type NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { getProfile } from '@/lib/services/user'; | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams; | ||
const fid = searchParams.get('fid'); | ||
if (!fid) { | ||
return NextResponse.json({ error: 'fid is required' }, { status: 400 }); | ||
} | ||
const profile = await getProfile(fid); | ||
return NextResponse.json({ profile }) | ||
const searchParams = request.nextUrl.searchParams; | ||
const fid = searchParams.get('fid'); | ||
if (!fid) { | ||
return NextResponse.json({ error: 'fid is required' }, { status: 400 }); | ||
} | ||
const profile = await getProfile(fid); | ||
return NextResponse.json({ profile }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import { Kysely, PostgresDialect } from "kysely"; | ||
import { Pool } from "pg"; | ||
import { DB } from "./types"; | ||
import { Kysely, PostgresDialect } from 'kysely'; | ||
import { Pool } from 'pg'; | ||
|
||
import { DB } from './types'; | ||
|
||
const dialect = new PostgresDialect({ | ||
pool: new Pool({ | ||
connectionString: process.env.DATABASE_URL | ||
}) | ||
pool: new Pool({ | ||
connectionString: process.env.DATABASE_URL, | ||
}), | ||
}); | ||
|
||
export const db = new Kysely<DB>({ | ||
dialect | ||
dialect, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import { sql } from "kysely"; | ||
import { db } from "../database/db"; | ||
import { sql } from 'kysely'; | ||
|
||
import { db } from '../database/db'; | ||
|
||
export async function getProfile(fid: string) { | ||
const profile = await db.selectFrom('user_data') | ||
.select([ | ||
'fid', | ||
sql`MAX(CASE WHEN type = 1 THEN value ELSE NULL END)`.as('pfp_url'), | ||
sql`MAX(CASE WHEN type = 2 THEN value ELSE NULL END)`.as('display_name'), | ||
sql`MAX(CASE WHEN type = 3 THEN value ELSE NULL END)`.as('bio'), | ||
sql`MAX(CASE WHEN type = 6 THEN value ELSE NULL END)`.as('username') | ||
]) | ||
.where('deleted_at', 'is', null) | ||
.where('fid', '=', fid) | ||
.groupBy('fid').execute(); | ||
const profile = await db | ||
.selectFrom('user_data') | ||
.select([ | ||
'fid', | ||
sql`MAX(CASE WHEN type = 1 THEN value ELSE NULL END)`.as('pfp_url'), | ||
sql`MAX(CASE WHEN type = 2 THEN value ELSE NULL END)`.as('display_name'), | ||
sql`MAX(CASE WHEN type = 3 THEN value ELSE NULL END)`.as('bio'), | ||
sql`MAX(CASE WHEN type = 6 THEN value ELSE NULL END)`.as('username'), | ||
]) | ||
.where('deleted_at', 'is', null) | ||
.where('fid', '=', fid) | ||
.groupBy('fid') | ||
.execute(); | ||
return profile[0]; | ||
} |