31 lines
998 B
TypeScript
31 lines
998 B
TypeScript
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { db } from '@/lib/db';
|
|
|
|
export async function POST(
|
|
req: NextRequest,
|
|
context: { params: Promise<{ id: string }> }
|
|
) {
|
|
try {
|
|
const { id } = await context.params;
|
|
const { network, token } = await req.json();
|
|
|
|
if (!id || !network || !token) {
|
|
return NextResponse.json({ error: 'Missing required fields' }, { status: 400 });
|
|
}
|
|
|
|
// Update metadata with intent
|
|
// Using jsonb_set to merge or set properly
|
|
await db.query(`
|
|
UPDATE transactions
|
|
SET metadata = metadata || jsonb_build_object('intent_network', $2::text, 'intent_token', $3::text)
|
|
WHERE id = $1
|
|
`, [id, network, token]);
|
|
|
|
return NextResponse.json({ success: true });
|
|
} catch (error: any) {
|
|
console.error("[Intent Update Error]:", error.message);
|
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
}
|
|
}
|