29 lines
783 B
TypeScript
29 lines
783 B
TypeScript
import { NextResponse } from "next/server";
|
|
|
|
import { createPaycheck, listPaychecks } from "@/lib/paychecks";
|
|
import { paycheckInputSchema } from "@/lib/validation";
|
|
|
|
export async function GET() {
|
|
const paychecks = await listPaychecks();
|
|
return NextResponse.json({ paychecks });
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
const payload = await request.json();
|
|
const parsed = paycheckInputSchema.safeParse(payload);
|
|
|
|
if (!parsed.success) {
|
|
return NextResponse.json(
|
|
{ error: parsed.error.issues[0]?.message ?? "Invalid paycheck payload." },
|
|
{ status: 400 },
|
|
);
|
|
}
|
|
|
|
const paycheck = await createPaycheck({
|
|
amountCents: parsed.data.amount,
|
|
payDate: parsed.data.payDate,
|
|
});
|
|
|
|
return NextResponse.json({ paycheck }, { status: 201 });
|
|
}
|