Files
itsc/pages/api/time/limit.js
2022-03-31 12:06:31 +08:00

31 lines
666 B
JavaScript

import { authenticate, setLimit } from "../../../libs/db";
export default function handler(req, res) {
// put method
if (req.method === "PUT") {
const { token, limit } = req.body;
// authenticate
if (!authenticate(token)) {
res.status(401).json({
error: "Unauthorized",
});
return;
}
// check type is integer
const limitInt = parseInt(limit);
if (!limitInt) {
res.status(400).json({
error: "limit must be integer",
});
return;
}
setLimit(limitInt);
res.status(200).send({ success: true });
} else {
res.status(405).send({ error: "method not allowed" });
}
}