แก้ calender สอบแข่งขัน

This commit is contained in:
AnandaTon 2023-10-05 12:35:56 +07:00
parent c4546055d2
commit f8f28048b0

View file

@ -1,37 +1,35 @@
import { env } from '$env/dynamic/private' import { env } from '$env/dynamic/private';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType' import type { CalendarEvent, Exam } from '$lib/data/CMSDataType';
import dayjs from 'dayjs' import dayjs from 'dayjs';
import type { PageServerLoad } from './$types' import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({fetch}) => { export const load: PageServerLoad = async ({ fetch }) => {
const res = await fetch(env.API_COMPETITIVE_URL+"/competitive") const res = await fetch(env.API_COMPETITIVE_URL + '/competitive');
if(!res.ok) if (!res.ok) throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้'); const exams: Exam[] = await res.json();
const exams:Exam[] = await res.json() const events: CalendarEvent[] = [];
const events:CalendarEvent[]=[]
exams.forEach((ex)=>{
const {id,title,announcement_startDate} = ex
const url = "/qualifying/"+id
ex.date = dayjs(announcement_startDate).format("DD MMM BBBB")
ex.image = ex.image?ex.image:"/images/exam_place_holder.png"
if(!ex.announcementExam)
return //ignore other date for normal post
if(ex.register_startDate){ exams.forEach((ex) => {
const start = ex.register_startDate const { id, title, announcement_startDate } = ex;
const end = ex.register_endDate const url = '/qualifying/' + id;
events.push({id,"title":"สมัคร:"+title,start,end,url,backgroundColor:'#67a1ff4a'}) ex.date = dayjs(announcement_startDate).format('DD MMM BBBB');
} ex.image = ex.image ? ex.image : '/images/exam_place_holder.png';
if(ex.payment_startDate){ if (!ex.announcementExam) return; //ignore other date for normal post
const start = ex.payment_startDate
const end = ex.payment_endDate if (ex.register_startDate) {
events.push({id,"title":"ชำระเงิน:"+title,start,end,url,backgroundColor:'#D2B4DE'}) const start = ex.register_startDate;
} const end = dayjs(ex.register_endDate).add(1, 'day').format('YYYY-MM-DD');
if(ex.examDate){ events.push({ id, title: 'สมัคร:' + title, start, end, url, backgroundColor: '#67a1ff4a' });
const start = ex.examDate }
events.push({id,"title":"วันสอบ:"+title,start,url,backgroundColor:'#a2d9ce8f'}) if (ex.payment_startDate) {
} const start = ex.payment_startDate;
}) const end = dayjs(ex.payment_startDate).add(1, 'day').format('YYYY-MM-DD');
return {exams,events} 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 };
};