feat: implement issues #5-#8 — error states, header search, delete/toggle visibility, auth-aware UI
This commit is contained in:
@@ -13,7 +13,7 @@ import { Badge } from "@/components/ui/badge"
|
|||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Separator } from "@/components/ui/separator"
|
import { Separator } from "@/components/ui/separator"
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
import { Share2, ArrowLeft, Loader2, Trophy } from "lucide-react"
|
import { Share2, ArrowLeft, Loader2, Trophy, AlertCircle } from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
|
||||||
interface ComparisonResultsClientProps {
|
interface ComparisonResultsClientProps {
|
||||||
@@ -32,6 +32,33 @@ export function ComparisonResultsClient({ initialData }: ComparisonResultsClient
|
|||||||
|
|
||||||
const winner = [...data.items].sort((a, b) => b.overallScore - a.overallScore)[0]
|
const winner = [...data.items].sort((a, b) => b.overallScore - a.overallScore)[0]
|
||||||
|
|
||||||
|
if (data.status === "failed") {
|
||||||
|
return (
|
||||||
|
<div className="max-w-2xl mx-auto p-4 space-y-6">
|
||||||
|
<div className="rounded-lg border border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-950/30 p-6 space-y-4">
|
||||||
|
<div className="flex items-start gap-3">
|
||||||
|
<AlertCircle className="size-6 text-red-600 shrink-0 mt-0.5" />
|
||||||
|
<div className="space-y-2">
|
||||||
|
<h2 className="text-lg font-semibold text-red-800 dark:text-red-200">
|
||||||
|
Comparison Failed
|
||||||
|
</h2>
|
||||||
|
<p className="text-sm text-red-700 dark:text-red-300">
|
||||||
|
This comparison could not be completed. This may be due to a processing error or
|
||||||
|
invalid input.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Link href="/compare">
|
||||||
|
<Button variant="outline" className="gap-2">
|
||||||
|
<ArrowLeft className="size-4" />
|
||||||
|
Try Again
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (isResearching) {
|
if (isResearching) {
|
||||||
return (
|
return (
|
||||||
<div className="max-w-4xl mx-auto p-4 space-y-6">
|
<div className="max-w-4xl mx-auto p-4 space-y-6">
|
||||||
|
|||||||
@@ -1,23 +1,36 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useState, useCallback, KeyboardEvent } from "react"
|
import { useState, useCallback, useEffect, KeyboardEvent } from "react"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Label } from "@/components/ui/label"
|
import { Label } from "@/components/ui/label"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { useComparisonStream } from "@/hooks/use-comparison-stream"
|
import { useComparisonStream } from "@/hooks/use-comparison-stream"
|
||||||
import { X, Plus, Loader2, Sparkles } from "lucide-react"
|
import { X, Plus, Loader2, Sparkles, AlertCircle } from "lucide-react"
|
||||||
|
import Link from "next/link"
|
||||||
|
|
||||||
export default function ComparePage() {
|
export default function ComparePage() {
|
||||||
const [query, setQuery] = useState("")
|
const [query, setQuery] = useState("")
|
||||||
const [items, setItems] = useState<string[]>([])
|
const [items, setItems] = useState<string[]>([])
|
||||||
const [itemInput, setItemInput] = useState("")
|
const [itemInput, setItemInput] = useState("")
|
||||||
const [dimensionHints, setDimensionHints] = useState("")
|
const [dimensionHints, setDimensionHints] = useState("")
|
||||||
const { progress, startResearch, cancel } = useComparisonStream()
|
const { progress, result, error, comparisonSlug, startResearch, cancel } = useComparisonStream()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const isResearching = progress.status === "researching"
|
const isResearching = progress.status === "researching"
|
||||||
|
|
||||||
|
// Auto-navigate to comparison results when stream completes
|
||||||
|
useEffect(() => {
|
||||||
|
if (result && comparisonSlug && !isResearching) {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
router.push(`/compare/${comparisonSlug}`)
|
||||||
|
}, 800)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}
|
||||||
|
}, [result, comparisonSlug, isResearching, router])
|
||||||
|
|
||||||
const addItem = useCallback(() => {
|
const addItem = useCallback(() => {
|
||||||
const trimmed = itemInput.trim()
|
const trimmed = itemInput.trim()
|
||||||
if (trimmed && !items.includes(trimmed) && items.length < 10) {
|
if (trimmed && !items.includes(trimmed) && items.length < 10) {
|
||||||
@@ -132,6 +145,28 @@ export default function ComparePage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<div className="rounded-lg border border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-950/30 p-4 space-y-2">
|
||||||
|
<div className="flex items-start gap-2">
|
||||||
|
<AlertCircle className="size-5 text-red-600 shrink-0 mt-0.5" />
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="text-sm font-medium text-red-800 dark:text-red-200">
|
||||||
|
Something went wrong
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-red-700 dark:text-red-300">{error}</p>
|
||||||
|
{(error.includes("Authentication") || error.includes("401")) && (
|
||||||
|
<Link
|
||||||
|
href="/sign-in"
|
||||||
|
className="inline-flex items-center text-sm font-medium text-red-700 underline underline-offset-2 hover:text-red-900 dark:text-red-300 dark:hover:text-red-100"
|
||||||
|
>
|
||||||
|
Sign in to continue
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{isResearching && (
|
{isResearching && (
|
||||||
<div className="space-y-3 rounded-lg border bg-muted/30 p-4">
|
<div className="space-y-3 rounded-lg border bg-muted/30 p-4">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react"
|
import { useState, useEffect, useCallback } from "react"
|
||||||
|
import { useSearchParams } from "next/navigation"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
@@ -28,13 +29,16 @@ interface ComparisonsResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ExplorePage() {
|
export default function ExplorePage() {
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const initialSearch = searchParams.get("search") ?? ""
|
||||||
|
|
||||||
const [comparisons, setComparisons] = useState<Comparison[]>([])
|
const [comparisons, setComparisons] = useState<Comparison[]>([])
|
||||||
const [total, setTotal] = useState(0)
|
const [total, setTotal] = useState(0)
|
||||||
const [page, setPage] = useState(1)
|
const [page, setPage] = useState(1)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [searchQuery, setSearchQuery] = useState("")
|
const [searchQuery, setSearchQuery] = useState(initialSearch)
|
||||||
const [debouncedSearch, setDebouncedSearch] = useState("")
|
const [debouncedSearch, setDebouncedSearch] = useState(initialSearch)
|
||||||
const [selectedCategory, setSelectedCategory] = useState("All")
|
const [selectedCategory, setSelectedCategory] = useState("All")
|
||||||
|
|
||||||
const limit = 20
|
const limit = 20
|
||||||
@@ -71,8 +75,8 @@ export default function ExplorePage() {
|
|||||||
}, [searchQuery, fetchComparisons])
|
}, [searchQuery, fetchComparisons])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchComparisons(1, "")
|
fetchComparisons(1, initialSearch)
|
||||||
}, [fetchComparisons])
|
}, [fetchComparisons, initialSearch])
|
||||||
|
|
||||||
const categories = ["All", ...Array.from(new Set(comparisons.flatMap(c => c.tags)))]
|
const categories = ["All", ...Array.from(new Set(comparisons.flatMap(c => c.tags)))]
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname, useRouter } from "next/navigation"
|
||||||
import { Sparkles, Home, BarChart3, Compass, User, Menu, X, Search } from "lucide-react"
|
import { Sparkles, Home, BarChart3, Compass, User, Menu, X, Search } from "lucide-react"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
@@ -72,6 +72,13 @@ export default function MainLayout({
|
|||||||
}) {
|
}) {
|
||||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
||||||
const [searchQuery, setSearchQuery] = useState("")
|
const [searchQuery, setSearchQuery] = useState("")
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
const handleSearchKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (e.key === "Enter" && searchQuery.trim()) {
|
||||||
|
router.push(`/explore?search=${encodeURIComponent(searchQuery.trim())}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex flex-col">
|
<div className="min-h-screen flex flex-col">
|
||||||
@@ -90,6 +97,7 @@ export default function MainLayout({
|
|||||||
placeholder="Search comparisons..."
|
placeholder="Search comparisons..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
onKeyDown={handleSearchKeyDown}
|
||||||
className="pl-9 h-9"
|
className="pl-9 h-9"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -146,6 +154,7 @@ export default function MainLayout({
|
|||||||
placeholder="Search comparisons..."
|
placeholder="Search comparisons..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
onKeyDown={handleSearchKeyDown}
|
||||||
className="pl-9"
|
className="pl-9"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -6,7 +6,13 @@ import { Button } from "@/components/ui/button"
|
|||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
import { BarChart3, Eye, Calendar, Plus, RefreshCw, LogIn } from "lucide-react"
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
} from "@/components/ui/dropdown-menu"
|
||||||
|
import { BarChart3, Eye, Calendar, Plus, RefreshCw, LogIn, MoreVertical, Trash2, Globe, Lock } from "lucide-react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { useSession } from "@/lib/auth-client"
|
import { useSession } from "@/lib/auth-client"
|
||||||
|
|
||||||
@@ -91,6 +97,37 @@ export default function ProfilePage() {
|
|||||||
}
|
}
|
||||||
}, [sessionLoading, session, fetchComparisons, fetchStats])
|
}, [sessionLoading, session, fetchComparisons, fetchStats])
|
||||||
|
|
||||||
|
const handleToggleVisibility = async (comparison: Comparison) => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/comparisons/${comparison.id}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ isPublic: !comparison.isPublic }),
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
fetchComparisons(page)
|
||||||
|
fetchStats()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Silently fail — user can retry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleDelete = async (comparison: Comparison) => {
|
||||||
|
if (!window.confirm(`Delete "${comparison.title}"? This cannot be undone.`)) return
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/comparisons/${comparison.id}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
fetchComparisons(page)
|
||||||
|
fetchStats()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Silently fail — user can retry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Not authenticated — show sign-in prompt
|
// Not authenticated — show sign-in prompt
|
||||||
if (!sessionLoading && !session?.user) {
|
if (!sessionLoading && !session?.user) {
|
||||||
return (
|
return (
|
||||||
@@ -207,8 +244,9 @@ export default function ProfilePage() {
|
|||||||
) : comparisons.length > 0 ? (
|
) : comparisons.length > 0 ? (
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
{comparisons.map((comparison) => (
|
{comparisons.map((comparison) => (
|
||||||
<Link key={comparison.id} href={`/compare/${comparison.slug}`}>
|
<Card key={comparison.id} className="h-full group transition-all hover:border-primary hover:shadow-md">
|
||||||
<Card className="h-full transition-all hover:border-primary hover:shadow-md">
|
<div className="flex flex-col h-full">
|
||||||
|
<Link href={`/compare/${comparison.slug}`} className="flex-1">
|
||||||
<CardHeader className="pb-3">
|
<CardHeader className="pb-3">
|
||||||
<CardTitle className="text-base line-clamp-1">{comparison.title}</CardTitle>
|
<CardTitle className="text-base line-clamp-1">{comparison.title}</CardTitle>
|
||||||
<CardDescription className="flex items-center gap-2 text-xs">
|
<CardDescription className="flex items-center gap-2 text-xs">
|
||||||
@@ -233,14 +271,57 @@ export default function ProfilePage() {
|
|||||||
<Eye className="size-3.5" />
|
<Eye className="size-3.5" />
|
||||||
{comparison.viewCount.toLocaleString()}
|
{comparison.viewCount.toLocaleString()}
|
||||||
</span>
|
</span>
|
||||||
{!comparison.isPublic && (
|
{!comparison.isPublic ? (
|
||||||
<Badge variant="outline" className="text-xs">Draft</Badge>
|
<Badge variant="outline" className="text-xs">Private</Badge>
|
||||||
|
) : (
|
||||||
|
<Badge variant="outline" className="text-xs">Public</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
|
||||||
</Link>
|
</Link>
|
||||||
|
<div className="flex justify-end px-4 pb-3">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger
|
||||||
|
className="inline-flex items-center justify-center size-8 rounded-md opacity-0 group-hover:opacity-100 transition-opacity hover:bg-accent"
|
||||||
|
onClick={(e: React.MouseEvent) => e.stopPropagation()}
|
||||||
|
>
|
||||||
|
<MoreVertical className="size-4" />
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
handleToggleVisibility(comparison)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{comparison.isPublic ? (
|
||||||
|
<>
|
||||||
|
<Lock className="size-4" />
|
||||||
|
Make Private
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Globe className="size-4" />
|
||||||
|
Make Public
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
variant="destructive"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
handleDelete(comparison)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Trash2 className="size-4" />
|
||||||
|
Delete
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
111
src/app/api/comparisons/[id]/route.ts
Normal file
111
src/app/api/comparisons/[id]/route.ts
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import { db } from "@/lib/db";
|
||||||
|
import { comparisons, sessions, users } from "@/lib/db/schema";
|
||||||
|
import { eq, and, gt } from "drizzle-orm";
|
||||||
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
|
async function getAuthedUserId(): Promise<string | null> {
|
||||||
|
const hdrs = await headers();
|
||||||
|
const cookieHeader = hdrs.get("cookie") ?? "";
|
||||||
|
const cookieMatch = cookieHeader
|
||||||
|
.split(";")
|
||||||
|
.map((c) => c.trim())
|
||||||
|
.find(
|
||||||
|
(c) =>
|
||||||
|
c.startsWith("__Secure-better-auth.session_token=") ||
|
||||||
|
c.startsWith("better-auth.session_token=")
|
||||||
|
);
|
||||||
|
const token = cookieMatch
|
||||||
|
?.split("=")
|
||||||
|
?.slice(1)
|
||||||
|
?.join("=")
|
||||||
|
?.trim()
|
||||||
|
.split(".")[0];
|
||||||
|
if (!token) return null;
|
||||||
|
|
||||||
|
const sessionRows = await db
|
||||||
|
.select()
|
||||||
|
.from(sessions)
|
||||||
|
.where(and(eq(sessions.token, token), gt(sessions.expiresAt, new Date())))
|
||||||
|
.limit(1);
|
||||||
|
if (!sessionRows.length) return null;
|
||||||
|
|
||||||
|
const userRows = await db
|
||||||
|
.select()
|
||||||
|
.from(users)
|
||||||
|
.where(eq(users.id, sessionRows[0].userId))
|
||||||
|
.limit(1);
|
||||||
|
if (!userRows.length) return null;
|
||||||
|
|
||||||
|
return userRows[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DELETE(
|
||||||
|
_request: Request,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const userId = await getAuthedUserId();
|
||||||
|
if (!userId) {
|
||||||
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = await params;
|
||||||
|
|
||||||
|
const existing = await db
|
||||||
|
.select({ userId: comparisons.userId })
|
||||||
|
.from(comparisons)
|
||||||
|
.where(eq(comparisons.id, id))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!existing.length) {
|
||||||
|
return Response.json({ error: "Not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing[0].userId !== userId) {
|
||||||
|
return Response.json({ error: "Forbidden" }, { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.delete(comparisons).where(eq(comparisons.id, id));
|
||||||
|
|
||||||
|
return Response.json({ success: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PATCH(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const userId = await getAuthedUserId();
|
||||||
|
if (!userId) {
|
||||||
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = await params;
|
||||||
|
|
||||||
|
const existing = await db
|
||||||
|
.select({ userId: comparisons.userId, isPublic: comparisons.isPublic })
|
||||||
|
.from(comparisons)
|
||||||
|
.where(eq(comparisons.id, id))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!existing.length) {
|
||||||
|
return Response.json({ error: "Not found" }, { status: 404 });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing[0].userId !== userId) {
|
||||||
|
return Response.json({ error: "Forbidden" }, { status: 403 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await request.json();
|
||||||
|
const newIsPublic =
|
||||||
|
typeof body.isPublic === "boolean" ? body.isPublic : !existing[0].isPublic;
|
||||||
|
|
||||||
|
const [updated] = await db
|
||||||
|
.update(comparisons)
|
||||||
|
.set({ isPublic: newIsPublic, updatedAt: new Date() })
|
||||||
|
.where(eq(comparisons.id, id))
|
||||||
|
.returning();
|
||||||
|
|
||||||
|
return Response.json({
|
||||||
|
id: updated.id,
|
||||||
|
isPublic: updated.isPublic,
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user