From b7e43f3526f7016ce7bd2d7dfb8ddea0fc41de3c Mon Sep 17 00:00:00 2001 From: Emil Nielsen Date: Thu, 20 Apr 2023 09:29:49 +0700 Subject: [PATCH] add utils page to reset data and load game config --- src/app/utils/page.tsx | 55 ++++++++++++++++++++++++++++++++++ src/pages/api/import-config.ts | 3 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/app/utils/page.tsx diff --git a/src/app/utils/page.tsx b/src/app/utils/page.tsx new file mode 100644 index 0000000..35ec78b --- /dev/null +++ b/src/app/utils/page.tsx @@ -0,0 +1,55 @@ +"use client"; + +import { useState, useEffect } from "react"; + +import Navbar from "../Components/Navigation/Navbar"; + +const allowedUserID = ["30f76186-83ff-4b26-a429-357bc1ee126f"]; + +export default function Utils() { + const [userId, setUserId] = useState(""); + + const clearUserData = async () => { + await fetch(`/api/user/${userId}/clear-data`, { + method: "POST", + }); + }; + + const loadConfig = async () => { + await fetch(`/api/import-config`, { + method: "POST", + }); + }; + + if (allowedUserID.indexOf(userId) == -1) { + return ( + <> + +

Missing Permission

; + + ); + } + + return ( +
+ +

Utilities

+ + +
+ ); +} diff --git a/src/pages/api/import-config.ts b/src/pages/api/import-config.ts index 47fab94..90adfe2 100644 --- a/src/pages/api/import-config.ts +++ b/src/pages/api/import-config.ts @@ -6,10 +6,11 @@ export default async function handler( res: NextApiResponse ) { try { + console.log("Loading config...") if (req.method === "POST") { const db = postgresConnection; const result = await db.query("select import_config();"); - + console.log(result) if (result.rowCount > 0) { return res.status(200).json({ userId: result.rows[0].id}); } else {