2023-10-04 15:06:58 +07:00
|
|
|
import { env } from '$env/dynamic/private';
|
2023-04-08 11:27:09 +07:00
|
|
|
import { error } from '@sveltejs/kit';
|
2023-10-04 15:06:58 +07:00
|
|
|
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(env.API_QUALIFYING_URL + '/qualifying');
|
|
|
|
|
if (!res.ok) throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
|
|
|
|
const exams: Exam[] = await res.json();
|
|
|
|
|
const events: CalendarEvent[] = [];
|
2023-04-12 16:41:55 +07:00
|
|
|
|
2023-10-04 15:06:58 +07:00
|
|
|
exams.forEach((ex) => {
|
|
|
|
|
const { id, title, announcement_startDate } = ex;
|
|
|
|
|
const url = '/qualifying/' + id;
|
2025-11-05 13:08:41 +07:00
|
|
|
ex.date = dayjs(announcement_startDate).add(543, 'year').format('DD MMM YYYY');
|
2023-10-04 15:06:58 +07:00
|
|
|
ex.image = ex.image ? ex.image : '/images/exam_place_holder.png';
|
|
|
|
|
if (!ex.announcementExam) return; //ignore other date for normal post
|
2023-03-27 16:43:56 +07:00
|
|
|
|
2023-10-04 15:06:58 +07:00
|
|
|
if (ex.register_startDate) {
|
|
|
|
|
const start = ex.register_startDate;
|
|
|
|
|
const end = dayjs(ex.register_endDate).add(1, 'day').format('YYYY-MM-DD');
|
|
|
|
|
events.push({ id, title: 'สมัคร:' + title, start, end, url, backgroundColor: '#67a1ff4a' });
|
|
|
|
|
}
|
|
|
|
|
if (ex.payment_startDate) {
|
|
|
|
|
const start = ex.payment_startDate;
|
2023-10-05 12:32:43 +07:00
|
|
|
const end = dayjs(ex.payment_endDate).add(1, 'day').format('YYYY-MM-DD');
|
2023-10-04 15:06:58 +07:00
|
|
|
events.push({ id, title: 'ชำระเงิน:' + title, start, end, url, backgroundColor: '#D2B4DE' });
|
|
|
|
|
}
|
|
|
|
|
if (ex.examDate) {
|
|
|
|
|
const start = ex.examDate;
|
|
|
|
|
events.push({ id, title: 'วันสอบ:' + title, start, url, backgroundColor: '#a2d9ce8f' });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return { exams, events };
|
|
|
|
|
};
|