JUNOHUB-test/src/app/api/admin/product-syncs/route.ts
root 284fb12576 Set up JUNOHUB app and EC2 deployment
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-09 20:12:52 +05:00

39 lines
1.0 KiB
TypeScript

import { NextResponse } from "next/server"
import { auth } from "@/auth"
import { prisma } from "@/lib/prisma"
export async function GET(req: Request) {
try {
const session = await auth()
if (!session?.user?.id || session.user.role !== "ADMIN") {
return NextResponse.json({ message: "Unauthorized" }, { status: 401 })
}
const { searchParams } = new URL(req.url)
const status = searchParams.get("status")
const syncs = await (prisma as any).productSync.findMany({
where: {
...(status && { status }),
},
include: {
store: true,
supplier: true,
},
orderBy: {
createdAt: "desc",
},
})
return NextResponse.json({ syncs })
} catch (error) {
console.error("Error fetching admin product syncs:", error)
return NextResponse.json(
{ message: "Failed to fetch product syncs" },
{ status: 500 },
)
}
}