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

41 lines
1.7 KiB
TypeScript
Raw Normal View History

import { env } from '$env/dynamic/private'
2023-04-08 11:27:09 +07:00
import { error } from '@sveltejs/kit';
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'
export const load: PageServerLoad = async ({fetch}) => {
const res = await fetch(env.API_QUALIFYING_URL+"/qualifying")
if(!res.ok)
2023-04-08 11:27:09 +07:00
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
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
exams.forEach((ex)=>{
2023-04-12 16:41:55 +07:00
const {id,title,category,announcement_startDate} = ex
const backgroundColor = category? getBgColorDict(category,catColor):"n/a"
const url = "/qualifying/"+id
2023-04-12 16:41:55 +07:00
ex.date = dayjs(announcement_startDate).format("DD MMM BBBB")
if(!ex.announcementExam)
2023-04-12 16:41:55 +07:00
return //ignore other date for normal post
if(ex.register_startDate){
const start = ex.register_startDate
const end = ex.register_endDate
2023-04-12 16:41:55 +07:00
events.push({id,"title":"สมัคร:"+title,start,end,url,backgroundColor})
}
if(ex.payment_startDate){
const start = ex.payment_startDate
const end = ex.payment_endDate
2023-04-12 16:41:55 +07:00
events.push({id,"title":"ชำระเงิน:"+title,start,end,url,backgroundColor})
}
if(ex.examDate){
const start = ex.examDate
events.push({id,"title":"วันสอบ:"+title,start,url,backgroundColor})
2023-04-07 22:59:53 +07:00
}
2023-04-04 18:32:58 +07:00
})
return {exams,events}
2023-03-27 16:43:56 +07:00
}