33 lines
847 B
TypeScript
33 lines
847 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { eq } from "drizzle-orm";
|
|
|
|
import { getUserFromSession } from "@/lib/auth/get-user";
|
|
import { db } from "@/lib/db";
|
|
import { stripeAccounts, xeroConnections } from "@/lib/schema";
|
|
|
|
export async function GET() {
|
|
const user = await getUserFromSession();
|
|
|
|
if (!user) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
// Get Stripe account
|
|
const stripe = await db
|
|
.select()
|
|
.from(stripeAccounts)
|
|
.where(eq(stripeAccounts.userId, user.id))
|
|
.limit(1);
|
|
|
|
// Get Xero connection
|
|
const xero = await db
|
|
.select()
|
|
.from(xeroConnections)
|
|
.where(eq(xeroConnections.userId, user.id))
|
|
.limit(1);
|
|
|
|
return NextResponse.json({
|
|
stripeAccountId: stripe[0]?.stripeAccountId ?? null,
|
|
xeroTenantId: xero[0]?.tenantId ?? null,
|
|
});
|
|
}
|