import type { NextApiRequest, NextApiResponse } from "next"; import { rdsConnection } from "@/lib/aws"; export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { if (req.method === "POST") { const { imo } = req.body; const query = ` SELECT COUNT(*) as count FROM spotship_vessel WHERE imo = ? `; rdsConnection.query(query, [imo], (error, results) => { if (error) { return res.status(500).json({ success: false, error: error.message }); } const exists = results[0].count > 0; return res.status(200).json({ success: true, exists }); }); } else { res.setHeader("Allow", ["POST"]); return res .status(405) .send(`Method ${req.method ?? "Undefined"} Not Allowed`); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter