import {qualifyingBase} from '$lib/data/CMSDataType' import { error } from '@sveltejs/kit'; import type {CalendarEvent,Exam} from '$lib/data/CMSDataType' 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 events:CalendarEvent[]=[] exams.forEach((ex)=>{ const {id,title,start,end,category_id} = ex let backgroundColor ="#23ccef" switch (String(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 if(start){ ex.date = dayjs(start).format("DD MMM BBBB") events.push({id,title,start,end,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} }