import { NextResponse } from "next/server";
import salesforceProxy from "@/api/service/salesforceProxy";
import pool from "@/api/service/db";
export async function POST(request) {
const body = await request.json();
const { product_name, type, price } = body;
const insertQuery = {
text: `insert into salesforce.product (product_name, type, price)
values ($1, $2, $3)
returning id`,
values: [product_name, type, price],
};
try {
const insertResult = await salesforceProxy.query(query);
const insertedId = insertResult.rows[0].id;
const newestProducts = await pool.query(
"select * from salesforce.product order by inserted_at desc limit 100;"
);
return NextResponse.json({
response: newestProducts.rows,
lastInsertedId: insertedId,
});
} catch (error) {
return NextResponse.json({ error: error.message }, { status: 400 });
}
}