hrms-exam/cms/src/routes/qualifying/+page.server.ts

37 lines
1.1 KiB
TypeScript
Raw Normal View History

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'
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})=>{
let backgroundColor =""
2023-04-04 18:32:58 +07:00
switch (institute_id) {
case 1:
backgroundColor="rgba(251,64,75,.2)"
2023-04-04 18:32:58 +07:00
break;
case 2:
backgroundColor="#23ccef"
break;
case 3:
backgroundColor="rgba(68,125,247,.2)"
2023-04-04 18:32:58 +07:00
break;
default:
break;
}
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
}