Update API from meeting
This commit is contained in:
parent
40f7e878c9
commit
b2083ebae2
13 changed files with 125 additions and 67 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import type { PageServerLoad } from './$types'
|
||||
import type {CalendarEvent} from '$lib/components/CalendarEvent'
|
||||
import type {Exam} from '$lib/components/Exam'
|
||||
|
||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||
import dayjs from 'dayjs'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
let content = ""
|
||||
let exams:Exam[] = []
|
||||
|
|
@ -16,8 +15,19 @@ export const load: PageServerLoad = async ({fetch}) => {
|
|||
}
|
||||
|
||||
const events:CalendarEvent[]=[]
|
||||
exams.forEach(({id,title,start})=>{
|
||||
const backgroundColor ="#9999FF"
|
||||
exams.forEach((e)=>{
|
||||
if(!e.start){
|
||||
e.date=""
|
||||
return
|
||||
}
|
||||
e.date= dayjs(e.start).format("DD MMM BBBB")
|
||||
|
||||
const {id,title,start,category_id} = e
|
||||
|
||||
let backgroundColor ="#9999FF"
|
||||
if(category_id)
|
||||
backgroundColor ="#99FFEE"
|
||||
|
||||
const url = "/competitive/"+id
|
||||
events.push({id,title,start,url,backgroundColor})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
|
||||
import type { PageServerLoad } from './$types'
|
||||
//import type {Exam} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import exams from "$lib/data/competitive-exam.json"
|
||||
export const load: PageServerLoad = async ({params}) => {
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||
const id = params.id+""
|
||||
//const exams = await getCompetitiveExams()
|
||||
const post = exams.find((q)=>{
|
||||
return q.id===id
|
||||
})
|
||||
|
||||
if(post)
|
||||
return post
|
||||
else
|
||||
throw error(404,{message:"ค้นหาโพสเกี่ยวกับการคัดเลือกไม่พบ"})
|
||||
|
||||
const res = await fetch("/api/compettive/"+id)
|
||||
if(res.status==404){
|
||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||
}
|
||||
if(!res.ok){
|
||||
throw error(500,{message:`พบข้อผิดพลาดเกี่ยวกับข้อมูลสอบคัดเลือก ${id}`})
|
||||
}
|
||||
const post = await res.json()
|
||||
return post
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue