Added Account Dublicate fucntion, improved default sorts
This commit is contained in:
33
apps/hub/app/api/admin/user/search/route.ts
Normal file
33
apps/hub/app/api/admin/user/search/route.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@repo/db";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const publicId = searchParams.get("publicId")?.trim();
|
||||
const email = searchParams.get("email")?.trim()?.toLowerCase();
|
||||
|
||||
if (!publicId && !email) {
|
||||
return NextResponse.json({ error: "Missing query" }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
OR: [publicId ? { publicId } : undefined, email ? { email } : undefined].filter(
|
||||
Boolean,
|
||||
) as any,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
publicId: true,
|
||||
firstname: true,
|
||||
lastname: true,
|
||||
isBanned: true,
|
||||
},
|
||||
});
|
||||
if (!user) return NextResponse.json({ user: null }, { status: 200 });
|
||||
return NextResponse.json({ user }, { status: 200 });
|
||||
} catch (e) {
|
||||
return NextResponse.json({ error: "Server error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user