Files
Pay2Gateway/app/api/merchants/[id]/route.ts

76 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/db';
export async function GET(
req: NextRequest,
context: { params: Promise<{ id: string }> }
) {
try {
const { id } = await context.params;
const result = await db.query('SELECT * FROM merchants WHERE id = $1 LIMIT 1', [id]);
const data = result.rows[0];
if (!data) {
return NextResponse.json({ error: 'Merchant not found' }, { status: 404 });
}
return NextResponse.json(data);
} catch (err: any) {
return NextResponse.json(
{ error: `Internal Server Error: ${err.message}` },
{ status: 500 }
);
}
}
export async function PATCH(
req: NextRequest,
context: { params: Promise<{ id: string }> }
) {
try {
const { id } = await context.params;
const { name, webhook_url, payment_provider, provider_config } = await req.json();
if (!name) {
return NextResponse.json(
{ error: 'Firma adı zorunludur.' },
{ status: 400 }
);
}
const result = await db.query(
'UPDATE merchants SET name = $1, webhook_url = $2, payment_provider = $3, provider_config = $4 WHERE id = $5 RETURNING *',
[name, webhook_url, payment_provider, provider_config, id]
);
const data = result.rows[0];
if (!data) {
return NextResponse.json({ error: 'Update failed or merchant not found' }, { status: 500 });
}
return NextResponse.json(data);
} catch (err: any) {
return NextResponse.json(
{ error: `Internal Server Error: ${err.message}` },
{ status: 500 }
);
}
}
export async function DELETE(
req: NextRequest,
context: { params: Promise<{ id: string }> }
) {
try {
const { id } = await context.params;
await db.query('DELETE FROM merchants WHERE id = $1', [id]);
return NextResponse.json({ success: true });
} catch (err: any) {
return NextResponse.json(
{ error: `Internal Server Error: ${err.message}` },
{ status: 500 }
);
}
}