api: don't auto-upvote new comments

This commit is contained in:
Adhityaa
2018-06-14 14:40:19 +05:30
parent 57e5bc7abc
commit e93733510b
6 changed files with 46 additions and 26 deletions

View File

@@ -11,6 +11,23 @@ func commentVote(commenterHex string, commentHex string, direction int) error {
}
statement := `
SELECT commenterHex
FROM comments
WHERE commentHex = $1;
`
row := db.QueryRow(statement, commentHex)
var authorHex string
if err := row.Scan(&authorHex); err != nil {
logger.Errorf("erorr selecting authorHex for vote")
return errorInternal
}
if authorHex == commenterHex {
return errorSelfVote
}
statement = `
INSERT INTO
votes (commentHex, commenterHex, direction, voteDate)
VALUES ($1, $2, $3, $4 )