first
This commit is contained in:
30
pages/api/time/limit.js
Normal file
30
pages/api/time/limit.js
Normal file
@@ -0,0 +1,30 @@
|
||||
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" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user