From cf4bf0551b2cf6da324d2b339c3efc0001cd13e8 Mon Sep 17 00:00:00 2001 From: Nick Cherry Date: Wed, 24 Jan 2024 20:06:32 -0500 Subject: [PATCH] fix lint --- web/src/app/api/casts/route.ts | 19 +++++----- web/src/app/api/feed/route.ts | 9 +++-- web/src/app/api/user/route.ts | 19 +++++----- web/src/lib/database/db.ts | 15 ++++---- web/src/lib/services/casts.ts | 61 ++++++++++++++++--------------- web/src/lib/services/feed.ts | 67 +++++++++++++++++----------------- web/src/lib/services/user.ts | 29 ++++++++------- 7 files changed, 114 insertions(+), 105 deletions(-) diff --git a/web/src/app/api/casts/route.ts b/web/src/app/api/casts/route.ts index 9062733..034fa34 100644 --- a/web/src/app/api/casts/route.ts +++ b/web/src/app/api/casts/route.ts @@ -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 }); +} diff --git a/web/src/app/api/feed/route.ts b/web/src/app/api/feed/route.ts index 0ee174f..5d7df4d 100644 --- a/web/src/app/api/feed/route.ts +++ b/web/src/app/api/feed/route.ts @@ -1,11 +1,12 @@ -import { type NextRequest, NextResponse } from "next/server"; -import { getFeed } from "@/lib/services/feed"; +import { type NextRequest, NextResponse } from 'next/server'; + +import { getFeed } from '@/lib/services/feed'; export async function GET(request: NextRequest) { const searchParams = request.nextUrl.searchParams; - const fid = searchParams.get("fid"); + const fid = searchParams.get('fid'); if (!fid) { - return NextResponse.json({ error: "fid is required" }, { status: 400 }); + return NextResponse.json({ error: 'fid is required' }, { status: 400 }); } const feed = await getFeed(fid); return NextResponse.json({ feed }); diff --git a/web/src/app/api/user/route.ts b/web/src/app/api/user/route.ts index 1c26526..7c59aaf 100644 --- a/web/src/app/api/user/route.ts +++ b/web/src/app/api/user/route.ts @@ -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 }); +} diff --git a/web/src/lib/database/db.ts b/web/src/lib/database/db.ts index d38189a..e167993 100644 --- a/web/src/lib/database/db.ts +++ b/web/src/lib/database/db.ts @@ -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({ - dialect + dialect, }); diff --git a/web/src/lib/services/casts.ts b/web/src/lib/services/casts.ts index 01383ad..ebfd365 100644 --- a/web/src/lib/services/casts.ts +++ b/web/src/lib/services/casts.ts @@ -1,45 +1,46 @@ -import { sql } from "kysely"; -import { db } from "../database/db"; +import { sql } from 'kysely'; + +import { db } from '../database/db'; export function formatHash(hash: Buffer) { - return hash.toString("hex"); + return hash.toString('hex'); } export async function getCasts(fid: string, limit = 100) { const profile = db - .selectFrom("user_data") + .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"), + '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") - .as("profile"); + .where('deleted_at', 'is', null) + .where('fid', '=', fid) + .groupBy('fid') + .as('profile'); const casts = await db - .selectFrom("casts") - .leftJoin(profile, "profile.fid", "casts.fid") + .selectFrom('casts') + .leftJoin(profile, 'profile.fid', 'casts.fid') .select([ - "casts.hash", - "casts.timestamp", - "casts.text", - "casts.embeds", - "casts.mentions", - "casts.mentions_positions", - "casts.fid", - "profile.pfp_url", - "profile.display_name", - "profile.bio", - "profile.username", + 'casts.hash', + 'casts.timestamp', + 'casts.text', + 'casts.embeds', + 'casts.mentions', + 'casts.mentions_positions', + 'casts.fid', + 'profile.pfp_url', + 'profile.display_name', + 'profile.bio', + 'profile.username', ]) - .where("casts.fid", "=", fid) - .where("casts.deleted_at", "is", null) - .where("casts.parent_hash", "is", null) - .orderBy("casts.timestamp", "desc") + .where('casts.fid', '=', fid) + .where('casts.deleted_at', 'is', null) + .where('casts.parent_hash', 'is', null) + .orderBy('casts.timestamp', 'desc') .limit(limit) .execute(); diff --git a/web/src/lib/services/feed.ts b/web/src/lib/services/feed.ts index 033235a..52fa780 100644 --- a/web/src/lib/services/feed.ts +++ b/web/src/lib/services/feed.ts @@ -1,47 +1,48 @@ -import { sql } from "kysely"; -import { db } from "../database/db"; -import { formatHash } from "./casts"; +import { sql } from 'kysely'; + +import { db } from '../database/db'; +import { formatHash } from './casts'; export async function getFeed(fid: string, limit = 100) { const follows = db - .selectFrom("links") - .select("target_fid") - .where("fid", "=", fid); + .selectFrom('links') + .select('target_fid') + .where('fid', '=', fid); const profiles = db - .selectFrom("user_data") + .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"), + '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", "in", follows) - .groupBy("fid") - .as("profiles"); + .where('deleted_at', 'is', null) + .where('fid', 'in', follows) + .groupBy('fid') + .as('profiles'); const casts = await db - .selectFrom("casts") - .leftJoin(profiles, "profiles.fid", "casts.fid") + .selectFrom('casts') + .leftJoin(profiles, 'profiles.fid', 'casts.fid') .select([ - "casts.hash", - "casts.timestamp", - "casts.text", - "casts.embeds", - "casts.mentions", - "casts.mentions_positions", - "casts.fid", - "profiles.pfp_url", - "profiles.display_name", - "profiles.bio", - "profiles.username", + 'casts.hash', + 'casts.timestamp', + 'casts.text', + 'casts.embeds', + 'casts.mentions', + 'casts.mentions_positions', + 'casts.fid', + 'profiles.pfp_url', + 'profiles.display_name', + 'profiles.bio', + 'profiles.username', ]) - .where("casts.fid", "in", follows) - .where("casts.deleted_at", "is", null) - .where("casts.parent_hash", "is", null) - .orderBy("casts.timestamp", "desc") + .where('casts.fid', 'in', follows) + .where('casts.deleted_at', 'is', null) + .where('casts.parent_hash', 'is', null) + .orderBy('casts.timestamp', 'desc') .limit(limit) .execute(); diff --git a/web/src/lib/services/user.ts b/web/src/lib/services/user.ts index 9781326..5a7d612 100644 --- a/web/src/lib/services/user.ts +++ b/web/src/lib/services/user.ts @@ -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]; }