my_vote field

This commit is contained in:
Shish 2023-02-13 22:44:08 +00:00
parent 301a5d3027
commit 1da0f427e6

View file

@ -61,6 +61,16 @@ class NumericScoreVote
return $votes;
}
#[Field(extends: "Post", type: "Int!")]
public static function my_vote(Image $post): int
{
global $database, $user;
return $database->get_one(
"SELECT score FROM numeric_score_votes WHERE image_id=:image_id AND user_id=:user_id",
['image_id'=>$post->id, "user_id"=>$user->id]
) ?? 0;
}
#[Mutation]
public static function create_vote(int $post_id, int $score): bool
{