40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { db } from "@/lib/db"
|
|
import { NextResponse } from "next/server";
|
|
import fetchUserWithImpersonation from "@/lib/fetch-user-impersonation";
|
|
import axios from "axios";
|
|
import { env } from "process";
|
|
import { TwitchUpdateAuthorization } from "@/lib/twitch";
|
|
|
|
export async function GET(req: Request) {
|
|
try {
|
|
const user = await fetchUserWithImpersonation(req)
|
|
if (!user)
|
|
return new NextResponse("Unauthorized", { status: 401 });
|
|
|
|
const { searchParams } = new URL(req.url)
|
|
const groupId = searchParams.get('groupId') as string
|
|
|
|
let chatters: { userId: string, groupId: string, chatterId: bigint, chatterLabel: string }[]
|
|
|
|
if (!!groupId)
|
|
chatters = await db.chatterGroup.findMany({
|
|
where: {
|
|
userId: user.id,
|
|
groupId
|
|
}
|
|
})
|
|
else
|
|
chatters = await db.chatterGroup.findMany({
|
|
where: {
|
|
userId: user.id
|
|
}
|
|
})
|
|
|
|
return NextResponse.json(chatters.map(u => ({ ...u, chatterId: Number(u.chatterId) }))
|
|
.map(({userId, chatterLabel, ...attrs}) => attrs))
|
|
|
|
} catch (error) {
|
|
console.log("[GROUPS/USERS]", error);
|
|
return new NextResponse("Internal Error", { status: 500 });
|
|
}
|
|
} |