Skip to content

Commit b90fa8f

Browse files
committed
fix: vote api not working properly
1 parent 160fe4e commit b90fa8f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

utils/Query.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,15 @@ async function getVote(
507507
targetID: string,
508508
type: 'bot' | 'server'
509509
): Promise<number | null> {
510-
const user = await knex('users').select(['votes']).where({ id: userID })
511-
if (user.length === 0) return null
512-
const data = JSON.parse(user[0].votes)
513-
return data[`${type}:${targetID}`] || 0
510+
const [vote] = await knex('votes')
511+
.select('last_voted')
512+
.where({
513+
user_id: userID,
514+
target: targetID,
515+
type: type === 'bot' ? ObjectType.Bot : ObjectType.Server,
516+
})
517+
if (!vote) return null
518+
return vote.last_voted.getTime() || 0
514519
}
515520

516521
async function getWebhook(id: string, type: 'bots' | 'servers'): Promise<Webhook | null> {

0 commit comments

Comments
 (0)