2023-03-27 16:43:56 +07:00
|
|
|
import type { PageServerLoad } from './$types'
|
2023-04-04 18:32:58 +07:00
|
|
|
import type {CalendarEvent} from '$lib/components/CalendarEvent'
|
2023-04-07 13:49:34 +07:00
|
|
|
import type {Exam} from '$lib/components/Exam'
|
|
|
|
|
export const load: PageServerLoad = async ({fetch}) => {
|
|
|
|
|
let content = ""
|
|
|
|
|
let exams:Exam[] = []
|
|
|
|
|
let res = await fetch("/api/content?page=qualifying")
|
|
|
|
|
if(res.ok){
|
|
|
|
|
content = (await res.json()).content
|
|
|
|
|
}
|
|
|
|
|
res = await fetch("/api/qualifying")
|
|
|
|
|
if(res.ok){
|
|
|
|
|
exams = await res.json()
|
|
|
|
|
}
|
2023-04-04 18:32:58 +07:00
|
|
|
const events:CalendarEvent[]=[]
|
|
|
|
|
exams.forEach(({id,title,start,institute_id})=>{
|
2023-04-05 18:16:31 +07:00
|
|
|
let backgroundColor =""
|
2023-04-04 18:32:58 +07:00
|
|
|
switch (institute_id) {
|
|
|
|
|
case 1:
|
2023-04-05 18:16:31 +07:00
|
|
|
backgroundColor="rgba(251,64,75,.2)"
|
2023-04-04 18:32:58 +07:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2023-04-05 18:16:31 +07:00
|
|
|
backgroundColor="#23ccef"
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
backgroundColor="rgba(68,125,247,.2)"
|
2023-04-04 18:32:58 +07:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-04-04 20:40:56 +07:00
|
|
|
const url = "/qualifying/"+id
|
|
|
|
|
events.push({id,title,start,url,backgroundColor})
|
2023-04-04 18:32:58 +07:00
|
|
|
})
|
2023-04-05 19:35:08 +07:00
|
|
|
return {exams,events,content}
|
2023-03-27 16:43:56 +07:00
|
|
|
}
|
|
|
|
|
|