Add paycheck tracking workflow for v1
This commit is contained in:
28
src/app/paychecks/route.ts
Normal file
28
src/app/paychecks/route.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user