Refactor: Fully migrated to direct PostgreSQL, implemented Public API v1, fixed Vercel deployment conflicts, and updated documentation

This commit is contained in:
mstfyldz
2026-03-12 21:54:57 +03:00
parent 321f25a15c
commit 515d513c1f
29 changed files with 1002 additions and 675 deletions

View File

@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from 'next/server';
import { supabaseAdmin } from '@/lib/supabase-admin';
import { db } from '@/lib/db';
export async function GET(
req: NextRequest,
@@ -7,14 +7,11 @@ export async function GET(
) {
try {
const { id } = await context.params;
const { data, error } = await supabaseAdmin
.from('merchants')
.select('*')
.eq('id', id)
.single();
const result = await db.query('SELECT * FROM merchants WHERE id = $1 LIMIT 1', [id]);
const data = result.rows[0];
if (error) {
return NextResponse.json({ error: error.message }, { status: 404 });
if (!data) {
return NextResponse.json({ error: 'Merchant not found' }, { status: 404 });
}
return NextResponse.json(data);
@@ -41,20 +38,14 @@ export async function PATCH(
);
}
const { data, error } = await supabaseAdmin
.from('merchants')
.update({
name,
webhook_url,
payment_provider,
provider_config
})
.eq('id', id)
.select()
.single();
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 (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
if (!data) {
return NextResponse.json({ error: 'Update failed or merchant not found' }, { status: 500 });
}
return NextResponse.json(data);
@@ -72,14 +63,7 @@ export async function DELETE(
) {
try {
const { id } = await context.params;
const { error } = await supabaseAdmin
.from('merchants')
.delete()
.eq('id', id);
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
await db.query('DELETE FROM merchants WHERE id = $1', [id]);
return NextResponse.json({ success: true });
} catch (err: any) {