File tree Expand file tree Collapse file tree
features/votes/components
routes/problems/getMedianVote Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import { tick } from ' svelte' ;
33 import { enhance } from ' $app/forms' ;
4+ import { resolve } from ' $app/paths' ;
45
56 import { Dropdown , DropdownItem , DropdownDivider } from ' flowbite-svelte' ;
67 import Check from ' @lucide/svelte/icons/check' ;
78
89 import { TaskGrade , getTaskGrade , type TaskResult } from ' $lib/types/task' ;
910 import { getTaskGradeLabel } from ' $lib/utils/task' ;
1011 import { nonPendingGrades } from ' $features/votes/utils/grade_options' ;
11- import { SIGNUP_PAGE , LOGIN_PAGE , VOTES_PAGE } from ' $lib/constants/navbar-links' ;
12+ import { SIGNUP_PAGE , LOGIN_PAGE } from ' $lib/constants/navbar-links' ;
1213 import { errorMessageStore } from ' $lib/stores/error_message' ;
1314
1415 import GradeLabel from ' $lib/components/GradeLabel.svelte' ;
4243 let votedGrade = $state <TaskGrade | null >(null );
4344
4445 async function onTriggerClick() {
45- if (isOpening ) return ;
46+ if (! isLoggedIn || isOpening ) return ;
4647 isOpening = true ;
4748 try {
4849 const res = await fetch (
169170 </DropdownItem >
170171 {/each }
171172 <DropdownDivider />
172- <DropdownItem href =" {VOTES_PAGE }/ {taskResult .task_id }" class =" rounded-md" >詳細</DropdownItem >
173+ <DropdownItem href ={resolve (' /votes/[slug]' , { slug: taskResult .task_id })} class =" rounded-md"
174+ >詳細</DropdownItem
175+ >
173176 </Dropdown >
174177{:else }
175178 <Dropdown
Original file line number Diff line number Diff line change 11import { json , type RequestHandler } from '@sveltejs/kit' ;
22import { getVoteStatsByTaskId } from '$features/votes/services/vote_statistics' ;
3+ import { getVoteGrade } from '$features/votes/services/vote_grade' ;
34
4- export const GET : RequestHandler = async ( { url } ) => {
5+ export const GET : RequestHandler = async ( { url, locals } ) => {
56 const taskId = url . searchParams . get ( 'taskId' ) ;
67 if ( ! taskId ) return json ( { error : 'taskId required' } , { status : 400 } ) ;
78
9+ const session = await locals . auth . validate ( ) ;
10+ if ( ! session || ! session . user || ! session . user . userId ) {
11+ return json ( { error : 'unauthorized' } , { status : 401 } ) ;
12+ }
13+
814 try {
15+ // Only return vote statistics to users who have already cast a vote for this task.
16+ const voteRecord = await getVoteGrade ( session . user . userId , taskId ) ;
17+ if ( ! voteRecord . voted ) return json ( { grade : null } ) ;
18+
919 const stats = await getVoteStatsByTaskId ( taskId ) ;
1020 if ( stats && stats . grade ) return json ( { grade : stats . grade } ) ;
1121 return json ( { grade : null } ) ;
You can’t perform that action at this time.
0 commit comments