mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 22:10:24 +00:00
feat: added v1 bot vote check
This commit is contained in:
parent
62ce9c155b
commit
a5e577b3e6
29
pages/api/v1/bots/voted/[botID].ts
Normal file
29
pages/api/v1/bots/voted/[botID].ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { NextApiRequest } from 'next'
|
||||
import RequestHandler from '@utils/RequestHandler'
|
||||
import { get } from '@utils/Query'
|
||||
import ResponseWrapper from '@utils/ResponseWrapper'
|
||||
import Yup from '@utils/Yup'
|
||||
import { VOTE_COOLDOWN } from '@utils/Constants'
|
||||
|
||||
const BotVoted = RequestHandler()
|
||||
.get(async (req: ApiRequest, res) => {
|
||||
const bot = await get.BotAuthorization(req.headers.token)
|
||||
if(!bot) return ResponseWrapper(res, { code: 401, version: 1 })
|
||||
if(req.query.botID !== bot) return ResponseWrapper(res, { code: 403, version: 1 })
|
||||
const userID = await Yup.string().required().validate(req.query.id).then(el => el).catch(() => null)
|
||||
if(!userID) return ResponseWrapper(res, { code: 400, version: 1 })
|
||||
const result = await get.botVote(userID, bot)
|
||||
return res.json({ code: 200, voted: +new Date() < result + VOTE_COOLDOWN })
|
||||
})
|
||||
|
||||
interface ApiRequest extends NextApiRequest {
|
||||
headers: {
|
||||
token: string
|
||||
}
|
||||
query: {
|
||||
botID: string
|
||||
id: string
|
||||
}
|
||||
}
|
||||
|
||||
export default BotVoted
|
||||
Loading…
x
Reference in New Issue
Block a user