chore: commit previously untracked runtime files (splits, auth, participants, shared)

This commit is contained in:
2026-03-08 18:00:46 +11:00
parent 30a7857d13
commit 5dbeb0cb87
11 changed files with 450 additions and 0 deletions
@@ -0,0 +1,32 @@
import { NextRequest, NextResponse } from "next/server";
import { queryRaw } from "@/lib/db";
interface BalanceRow {
participant_id: number;
name: string;
total_owed: number;
transaction_count: number;
}
export async function GET(
_req: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
const rows = await queryRaw<BalanceRow>(
`SELECT ts.participant_id, p.name,
SUM(t.amount * ts.share_percent / 100)::numeric(12,2) as total_owed,
COUNT(*)::int as transaction_count
FROM transaction_splits ts
JOIN transactions t ON t.id = ts.transaction_id
JOIN participants p ON p.id = ts.participant_id
WHERE ts.participant_id = $1 AND ts.settled = false
GROUP BY ts.participant_id, p.name`,
[Number(id)]
);
return NextResponse.json(
rows[0] ?? { participant_id: Number(id), total_owed: 0, transaction_count: 0 }
);
}
@@ -0,0 +1,11 @@
import { NextRequest, NextResponse } from "next/server";
import { getParticipantBalances } from "@/lib/queries";
import { getCurrentUser } from "@/lib/auth";
export async function GET(req: NextRequest) {
const user = await getCurrentUser(req);
if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const balances = await getParticipantBalances(user.id);
return NextResponse.json(balances);
}
+21
View File
@@ -0,0 +1,21 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { queryRaw } from "@/lib/db";
export async function GET() {
const participants = await prisma.participants.findMany({
orderBy: { name: "asc" },
});
return NextResponse.json(participants);
}
export async function POST(req: NextRequest) {
const { name, email } = await req.json();
if (!name?.trim()) {
return NextResponse.json({ error: "name required" }, { status: 400 });
}
const participant = await prisma.participants.create({
data: { name: name.trim(), email: email?.trim() || null },
});
return NextResponse.json(participant, { status: 201 });
}