import {qualifyingBase} from '$lib/data/CMSDataType' import { error } from '@sveltejs/kit'; import type {CalendarEvent,Exam} from '$lib/data/CMSDataType' import {getBgColorDict} from '$lib/utils' import dayjs from 'dayjs' import type { PageServerLoad } from './$types' export const load: PageServerLoad = async ({fetch}) => { const res = await fetch(qualifyingBase+"/qualifying") if(!res.ok) throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้'); const exams:Exam[] = await res.json() const catColor = {}; const events:CalendarEvent[]=[] exams.forEach((ex)=>{ const {id,title,start,end,category} = ex if(!category) return const backgroundColor = getBgColorDict(category,catColor) const url = "/qualifying/"+id if(start){ ex.date = dayjs(start).format("DD MMM BBBB") console.log({id,title,start,end,url,backgroundColor}) events.push({id,title,start,url,backgroundColor}) } if(ex.exam_date){ events.push({id,"title":"วันสอบคัดเลือก","start":ex.exam_date,url,backgroundColor}) } if(ex.announcement_date){ events.push({id,"title":"ผลสอบคัดเลือก","start":ex.announcement_date,url,backgroundColor}) } }) return {exams,events} }