44 lines
1.1 KiB
TypeScript
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 });
|
|
}
|