diff --git a/src/pages/api/user/[userId]/clear-data.ts b/src/pages/api/user/[userId]/clear-data.ts new file mode 100644 index 0000000..1adb7dd --- /dev/null +++ b/src/pages/api/user/[userId]/clear-data.ts @@ -0,0 +1,25 @@ +import { postgresConnection } from "db"; +import type { NextApiRequest, NextApiResponse } from "next"; + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse +) { + try { + if (req.method === "POST") { + let { userId } = req.query; + + const db = postgresConnection; + + const result = await db.query("select clear_user_data($1)", [userId]); + console.log(result); + if (result.rowCount > 0) { + return res.status(200).json({message: "Success!"}); + } else { + return res.status(404).json({ message: "User not found" }); + } + } + } catch (error) { + res.status(500).json(error.message); + } +} diff --git a/test-endpoints.restclient b/test-endpoints.restclient index ebd8d24..3836ec2 100644 --- a/test-endpoints.restclient +++ b/test-endpoints.restclient @@ -20,7 +20,7 @@ POST http://localhost:3000/api/user/login GET http://localhost:3000/api/user/:user_id/bank-account :headers -# Get bank account +# Clear user data POST http://localhost:3000/api/user/:user_id/clear-data :headers