Added API for TTS Username Filters
This commit is contained in:
82
app/api/settings/tts/filter/users/route.ts
Normal file
82
app/api/settings/tts/filter/users/route.ts
Normal file
@ -0,0 +1,82 @@
|
||||
import { db } from "@/lib/db"
|
||||
import { NextResponse } from "next/server";
|
||||
import fetchUserUsingAPI from "@/lib/validate-api";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserUsingAPI(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const filters = await db.ttsUsernameFilter.findMany({
|
||||
where: {
|
||||
userId: user.id
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(filters);
|
||||
} catch (error) {
|
||||
console.log("[TTS/FILTER/USER]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserUsingAPI(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const { username, tag } = await req.json();
|
||||
|
||||
const filter = await db.ttsUsernameFilter.upsert({
|
||||
where: {
|
||||
userId_username: {
|
||||
userId: user.id as string,
|
||||
username
|
||||
}
|
||||
},
|
||||
update: {
|
||||
tag
|
||||
},
|
||||
create: {
|
||||
userId: user.id as string,
|
||||
username,
|
||||
tag
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(filter);
|
||||
} catch (error) {
|
||||
console.log("[TTS/FILTER/USER]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(req: Request) {
|
||||
try {
|
||||
const user = await fetchUserUsingAPI(req)
|
||||
if (!user) {
|
||||
return new NextResponse("Unauthorized", { status: 401 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(req.url)
|
||||
const username = searchParams.get('username') as string
|
||||
|
||||
const filter = await db.ttsUsernameFilter.delete({
|
||||
where: {
|
||||
userId_username: {
|
||||
userId: user.id as string,
|
||||
username
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(filter)
|
||||
} catch (error) {
|
||||
console.log("[TTS/FILTER/USER]", error);
|
||||
return new NextResponse("Internal Error", { status: 500 });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user