This commit is contained in:
2022-03-31 12:25:54 +08:00
parent 7e4c106683
commit a67715a2a0
7 changed files with 38 additions and 37 deletions

View File

@@ -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);
});

View File

@@ -39,7 +39,7 @@ function MyApp({ Component, pageProps }) {
}}
>
<Typography variant="h5">
<Link href="/">ITSC Tool</Link>
<Link href="/"> </Link>
</Typography>
{username && (
<Button
@@ -50,7 +50,7 @@ function MyApp({ Component, pageProps }) {
setUsername("");
}}
>
{username} (Logout)
{username} (点击登出)
</Button>
)}
</Toolbar>

View File

@@ -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 + "不被允许" });
}
}

View File

@@ -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 + "不被允许" });
}
}

View File

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

View File

@@ -46,7 +46,7 @@ export default function Index(props) {
<Container>
<Stack direction="row" spacing={2}>
<TextField
label="Username"
label="您的大名?"
value={username}
onChange={(e) => setUsername(e.target.value)}
onKeyUp={(e) => {
@@ -64,7 +64,7 @@ export default function Index(props) {
login();
}}
>
Login
登入
</Button>
</Link>
</Stack>
@@ -74,7 +74,7 @@ export default function Index(props) {
onClose={() => setSnackbarOpen(false)}
>
<Alert variant="filled" severity="error">
Username can{"'"}t be empty
请输入您的大名
</Alert>
</Snackbar>
</Container>

View File

@@ -172,12 +172,12 @@ export default function Time(props) {
}}
>
<TextField
label="Name"
label="名称"
value={newName}
onChange={(e) => setNewName(e.target.value)}
/>
<TextField
label="Range"
label="时间段"
value={range}
onChange={(e) => 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
添加
</Button>
<Box
sx={{
@@ -196,7 +196,7 @@ export default function Time(props) {
}}
>
<TextField
label="Limit"
label="每人数量上限"
value={limit}
onChange={(e) => setLimit(e.target.value)}
/>
@@ -207,7 +207,7 @@ export default function Time(props) {
updateLimit(limit);
}}
>
Update Limit
修改上限
</Button>
</Box>
</Box>
@@ -224,10 +224,10 @@ export default function Time(props) {
<Table>
<TableHead>
<TableRow>
<TableCell>Name</TableCell>
<TableCell>Range</TableCell>
<TableCell>Taken</TableCell>
<TableCell>Action</TableCell>
<TableCell>名称</TableCell>
<TableCell>时间段</TableCell>
<TableCell>姓名</TableCell>
<TableCell>操作</TableCell>
</TableRow>
</TableHead>
<TableBody>
@@ -246,7 +246,7 @@ export default function Time(props) {
color="primary"
onClick={() => updateUsername(range.id, props.username)}
>
Take
</Button>
{isAdmin() && (
<Button
@@ -257,7 +257,7 @@ export default function Time(props) {
color="secondary"
onClick={() => deleteRange(range.id)}
>
Delete
删除
</Button>
)}
</TableCell>
@@ -289,7 +289,7 @@ export default function Time(props) {
onClose={() => setSnackbarSuccess(false)}
severity="success"
>
Success!
操作成功
</Alert>
</Snackbar>
</Container>