Add: 修改

This commit is contained in:
2022-04-02 17:42:30 +08:00
parent 880c26b8d3
commit 7bc70f5c25
3 changed files with 68 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ import {
deleteTimeRange,
getLimit,
authenticate,
update,
updateUsername,
updateUsernameWithLimit,
} from "../../../../libs/db";
@@ -34,26 +35,28 @@ export default function handler(req, res) {
// update username
} else if (req.method === "PUT") {
// check if id is valid
// check if username is valid
const { username } = req.body;
if (username === undefined) {
res.status(400).json({
error: `缺少参数 username`,
});
return;
}
// admin update username
const { token } = req.body;
if (authenticate(token)) {
updateUsername.run(username, id);
const { name, username, id, range } = req.body;
const result = update.run(name, range, username, id);
res.status(200).json({
success: true,
});
return;
}
// check if id is valid
// check if username is valid
if (username === undefined) {
res.status(400).json({
error: `缺少参数 username`,
});
return;
}
try {
const limit = getLimit();
updateUsernameWithLimit(username, id, limit);