43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { NextResponse } from "next/server"
|
|
import { accountService } from "@/services/account.service"
|
|
import type { Account } from "@/lib/types"
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const data: Omit<Account, "id"> = await request.json()
|
|
const created = await accountService.create(data)
|
|
return NextResponse.json(created)
|
|
} catch (error) {
|
|
console.error("Error creating account:", error)
|
|
return NextResponse.json({ error: "Failed to create account" }, { status: 500 })
|
|
}
|
|
}
|
|
|
|
export async function PUT(request: Request) {
|
|
try {
|
|
const account: Account = await request.json()
|
|
const updated = await accountService.update(account.id, account)
|
|
return NextResponse.json(updated)
|
|
} catch (error) {
|
|
console.error("Error updating account:", error)
|
|
return NextResponse.json({ error: "Failed to update account" }, { status: 500 })
|
|
}
|
|
}
|
|
|
|
export async function DELETE(request: Request) {
|
|
try {
|
|
const { searchParams } = new URL(request.url)
|
|
const id = searchParams.get("id")
|
|
|
|
if (!id) {
|
|
return NextResponse.json({ error: "Account ID is required" }, { status: 400 })
|
|
}
|
|
|
|
await accountService.delete(id)
|
|
return NextResponse.json({ success: true })
|
|
} catch (error) {
|
|
console.error("Error deleting account:", error)
|
|
return NextResponse.json({ error: "Failed to delete account" }, { status: 500 })
|
|
}
|
|
}
|