add utils page to reset data and load game config

This commit is contained in:
Emil Nielsen 2023-04-20 09:29:49 +07:00
parent 0668895422
commit b7e43f3526
2 changed files with 57 additions and 1 deletions

55
src/app/utils/page.tsx Normal file
View File

@ -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<string>("");
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 (
<>
<Navbar setUserId={setUserId} />
<h1 className="text-2xl text-white p-8">Missing Permission</h1>;
</>
);
}
return (
<div className="p-8">
<Navbar setUserId={setUserId} />
<h1 className="text-2xl text-white mb-4">Utilities</h1>
<button
className="bg-slate-100 text-slate-900 px-4 py-2 rounded-lg font-bold w-auto text-center mr-4"
onClick={() => {
clearUserData();
}}
>
Clear My Data
</button>
<button
className="bg-slate-100 text-slate-900 px-4 py-2 rounded-lg font-bold w-auto text-center mr-4"
onClick={() => {
loadConfig();
}}
>
Load Game Config
</button>
</div>
);
}

View File

@ -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 {