31 lines
929 B
TypeScript
31 lines
929 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/db";
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const body = await req.json();
|
|
const { participant_id, split_ids } = body as {
|
|
participant_id?: number;
|
|
split_ids?: number[];
|
|
};
|
|
|
|
const now = new Date();
|
|
|
|
if (participant_id) {
|
|
const result = await prisma.transaction_splits.updateMany({
|
|
where: { participant_id, settled: false },
|
|
data: { settled: true, settled_at: now },
|
|
});
|
|
return NextResponse.json({ settled: result.count });
|
|
}
|
|
|
|
if (split_ids?.length) {
|
|
const result = await prisma.transaction_splits.updateMany({
|
|
where: { id: { in: split_ids }, settled: false },
|
|
data: { settled: true, settled_at: now },
|
|
});
|
|
return NextResponse.json({ settled: result.count });
|
|
}
|
|
|
|
return NextResponse.json({ error: "participant_id or split_ids required" }, { status: 400 });
|
|
}
|