import type {CalendarEvent} from '$lib/data/CMSDataType' import type {Exam} from '$lib/data/CMSDataType' import dayjs from 'dayjs' import type { PageServerLoad } from './$types' 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() } const events:CalendarEvent[]=[] exams.forEach((e)=>{ if(!e.start){ e.date="" return } e.date= dayjs(e.start).format("DD MMM BBBB") const {id,title,start,end,category_id} = e let backgroundColor ="" switch (category_id) { case "1": backgroundColor="rgba(251,64,75,.2)" break; case "2": backgroundColor="#23ccef" break; case "3": backgroundColor="rgba(68,125,247,.2)" break; default: break; } const url = "/qualifying/"+id events.push({id,title,start,end,url,backgroundColor}) if(e.exam_date){ events.push({id,"title":"สอบ","start":e.exam_date,url,backgroundColor}) } if(e.announcement_date){ events.push({id,"title":"ผลสอบสอบ","start":e.announcement_date,url,backgroundColor}) } }) return {exams,events,content} }