juntekim.com/stripe_to_invoice/app/api/dashboard/xero-settings/route.ts
2026-02-01 20:03:08 +00:00

44 lines
1.1 KiB
TypeScript

import { NextResponse } from "next/server";
import { eq } from "drizzle-orm";
import { db } from "@/lib/db";
import { xeroConnections } from "@/lib/schema";
import { getUserFromSession } from "@/lib/auth/get-user";
export async function GET() {
const user = await getUserFromSession();
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const [conn] = await db
.select()
.from(xeroConnections)
.where(eq(xeroConnections.userId, user.id))
.limit(1);
return NextResponse.json({
salesAccountCode: conn?.salesAccountCode ?? null,
stripeClearingAccountCode: conn?.stripeClearingAccountCode ?? null,
});
}
export async function POST(req: Request) {
const user = await getUserFromSession();
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const body = await req.json();
await db
.update(xeroConnections)
.set({
salesAccountCode: body.salesAccountCode,
stripeClearingAccountCode: body.stripeClearingAccountCode,
})
.where(eq(xeroConnections.userId, user.id));
return NextResponse.json({ ok: true });
}