2023-04-09 14:39:23 +07:00
|
|
|
import {qualifyingBase} from '$lib/data/CMSDataType'
|
2023-04-08 11:27:09 +07:00
|
|
|
import { error } from '@sveltejs/kit';
|
2023-04-07 23:56:23 +07:00
|
|
|
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
2023-04-10 14:41:43 +07:00
|
|
|
import {getBgColorDict} from '$lib/utils'
|
2023-04-07 22:59:53 +07:00
|
|
|
import dayjs from 'dayjs'
|
2023-03-27 16:43:56 +07:00
|
|
|
import type { PageServerLoad } from './$types'
|
2023-04-07 13:49:34 +07:00
|
|
|
export const load: PageServerLoad = async ({fetch}) => {
|
2023-04-09 14:39:23 +07:00
|
|
|
const res = await fetch(qualifyingBase+"/qualifying")
|
2023-04-08 16:15:15 +07:00
|
|
|
if(!res.ok)
|
2023-04-08 11:27:09 +07:00
|
|
|
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
2023-04-10 11:33:42 +07:00
|
|
|
const exams:Exam[] = await res.json()
|
2023-04-10 14:41:43 +07:00
|
|
|
const catColor = {};
|
2023-04-04 18:32:58 +07:00
|
|
|
const events:CalendarEvent[]=[]
|
2023-04-10 14:41:43 +07:00
|
|
|
|
2023-04-08 16:15:15 +07:00
|
|
|
exams.forEach((ex)=>{
|
2023-04-10 14:41:43 +07:00
|
|
|
const {id,title,start,end,category} = ex
|
|
|
|
|
if(!category)
|
|
|
|
|
return
|
|
|
|
|
const backgroundColor = getBgColorDict(category,catColor)
|
|
|
|
|
|
2023-04-04 20:40:56 +07:00
|
|
|
const url = "/qualifying/"+id
|
2023-04-08 16:15:15 +07:00
|
|
|
if(start){
|
|
|
|
|
ex.date = dayjs(start).format("DD MMM BBBB")
|
2023-04-10 14:41:43 +07:00
|
|
|
console.log({id,title,start,end,url,backgroundColor})
|
|
|
|
|
events.push({id,title,start,url,backgroundColor})
|
2023-04-08 16:15:15 +07:00
|
|
|
}
|
|
|
|
|
if(ex.exam_date){
|
|
|
|
|
events.push({id,"title":"วันสอบคัดเลือก","start":ex.exam_date,url,backgroundColor})
|
2023-04-07 22:59:53 +07:00
|
|
|
}
|
2023-04-08 16:15:15 +07:00
|
|
|
if(ex.announcement_date){
|
|
|
|
|
events.push({id,"title":"ผลสอบคัดเลือก","start":ex.announcement_date,url,backgroundColor})
|
2023-04-07 22:59:53 +07:00
|
|
|
}
|
|
|
|
|
|
2023-04-04 18:32:58 +07:00
|
|
|
})
|
2023-04-08 16:15:15 +07:00
|
|
|
return {exams,events}
|
2023-03-27 16:43:56 +07:00
|
|
|
}
|
|
|
|
|
|