diff --git a/libs/db.js b/libs/db.js index 4f9d0c4..8aea6e7 100644 --- a/libs/db.js +++ b/libs/db.js @@ -41,10 +41,10 @@ const updateUsernameWithLimit = db.transaction((username, id, limit) => { const count = countUser.get(username).count; const existingUsername = getUsername.get(id).username; if (existingUsername !== "") { - throw new Error("Username already exists"); + throw new Error("这个时间段已经有人了喔"); } if (count >= limit) { - throw new Error("Limit reached"); + throw new Error("达到数量上限啦"); } updateUsername.run(username, id); }); diff --git a/pages/_app.js b/pages/_app.js index 4845572..7890410 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -39,7 +39,7 @@ function MyApp({ Component, pageProps }) { }} > - ITSC Tool + 抢 班 {username && ( )} diff --git a/pages/api/time/limit.js b/pages/api/time/limit.js index ba70ee0..e9465eb 100644 --- a/pages/api/time/limit.js +++ b/pages/api/time/limit.js @@ -8,7 +8,7 @@ export default function handler(req, res) { // authenticate if (!authenticate(token)) { res.status(401).json({ - error: "Unauthorized", + error: `token ${token} 验证失败`, }); return; } @@ -17,7 +17,7 @@ export default function handler(req, res) { const limitInt = parseInt(limit); if (!limitInt) { res.status(400).json({ - error: "limit must be integer", + error: `数量限制必须是整数,但是传入了 ${limit}`, }); return; } @@ -25,6 +25,6 @@ export default function handler(req, res) { setLimit(limitInt); res.status(200).send({ success: true }); } else { - res.status(405).send({ error: "method not allowed" }); + res.status(405).send({ error: "方法" + req.method + "不被允许" }); } } diff --git a/pages/api/time/ranges.js b/pages/api/time/ranges.js index 4f9fb07..158bc8a 100644 --- a/pages/api/time/ranges.js +++ b/pages/api/time/ranges.js @@ -10,7 +10,9 @@ export default function handler(req, res) { // authenticate const { token } = req.body; if (!authenticate(token)) { - res.status(401).json({ error: "Unauthorized" }); + res.status(401).json({ + error: `token ${token} 验证失败`, + }); return; } // jsonfiy @@ -21,9 +23,6 @@ export default function handler(req, res) { }); return; } else { - // 500 error - res.status(500).json({ - error: "Method not allowed", - }); + res.status(405).send({ error: "方法" + req.method + "不被允许" }); } } diff --git a/pages/api/time/ranges/[id].js b/pages/api/time/ranges/[id].js index 35fa19e..139b9f4 100644 --- a/pages/api/time/ranges/[id].js +++ b/pages/api/time/ranges/[id].js @@ -1,11 +1,16 @@ -import { deleteTimeRange, getLimit, authenticate, updateUsernameWithLimit } from "../../../../libs/db"; +import { + deleteTimeRange, + getLimit, + authenticate, + updateUsernameWithLimit, +} from "../../../../libs/db"; export default function handler(req, res) { // check if id is valid const { id } = req.query; if (id === undefined) { res.status(400).json({ - error: "Missing id", + error: `缺少参数 id`, }); return; } @@ -17,7 +22,7 @@ export default function handler(req, res) { if (!authenticate(token)) { console.log("[DELETE] Authentication failed"); res.status(401).json({ - error: "Unauthenticated", + error: `token ${token} 验证失败`, }); return; } @@ -30,7 +35,7 @@ export default function handler(req, res) { const { username } = req.body; if (username === undefined) { res.status(400).json({ - error: "Missing username", + error: `缺少参数 username`, }); return; } @@ -44,13 +49,10 @@ export default function handler(req, res) { }); return; } - - // not allow + + // not allow } else { - // 500 error - res.status(500).json({ - error: "Method not allowed", - }); + res.status(405).send({ error: "方法" + req.method + "不被允许" }); } res.status(200).json({ diff --git a/pages/index.js b/pages/index.js index c32788f..5165f9e 100644 --- a/pages/index.js +++ b/pages/index.js @@ -46,7 +46,7 @@ export default function Index(props) { setUsername(e.target.value)} onKeyUp={(e) => { @@ -64,7 +64,7 @@ export default function Index(props) { login(); }} > - Login + 登入 @@ -74,7 +74,7 @@ export default function Index(props) { onClose={() => setSnackbarOpen(false)} > - Username can{"'"}t be empty + 请输入您的大名 diff --git a/pages/time.js b/pages/time.js index ed67979..1281fc1 100644 --- a/pages/time.js +++ b/pages/time.js @@ -172,12 +172,12 @@ export default function Time(props) { }} > setNewName(e.target.value)} /> setRange(e.target.value)} placeholder="2022-01-01 00:00:00" @@ -188,7 +188,7 @@ export default function Time(props) { color="primary" onClick={() => addRange()} > - Add + 添加 setLimit(e.target.value)} /> @@ -207,7 +207,7 @@ export default function Time(props) { updateLimit(limit); }} > - Update Limit + 修改上限 @@ -224,10 +224,10 @@ export default function Time(props) { - Name - Range - Taken - Action + 名称 + 时间段 + 姓名 + 操作 @@ -246,7 +246,7 @@ export default function Time(props) { color="primary" onClick={() => updateUsername(range.id, props.username)} > - Take + 抢! {isAdmin() && ( )} @@ -289,7 +289,7 @@ export default function Time(props) { onClose={() => setSnackbarSuccess(false)} severity="success" > - Success! + 操作成功!