Update API from meeting
This commit is contained in:
parent
40f7e878c9
commit
b2083ebae2
13 changed files with 125 additions and 67 deletions
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
import type {CalendarEvent} from '$lib/data/CMSDataType'
|
||||
import type {Exam} from '$lib/data/CMSDataType'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
import type {CalendarEvent} from '$lib/components/CalendarEvent'
|
||||
import type {Exam} from '$lib/components/Exam'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
let content = ""
|
||||
let exams:Exam[] = []
|
||||
|
|
@ -13,23 +15,36 @@ export const load: PageServerLoad = async ({fetch}) => {
|
|||
exams = await res.json()
|
||||
}
|
||||
const events:CalendarEvent[]=[]
|
||||
exams.forEach(({id,title,start,institute_id})=>{
|
||||
exams.forEach((e)=>{
|
||||
if(!e.start){
|
||||
e.date=""
|
||||
return
|
||||
}
|
||||
e.date= dayjs(e.start).format("DD MMM BBBB")
|
||||
const {id,title,start,end,category_id} = e
|
||||
let backgroundColor =""
|
||||
switch (institute_id) {
|
||||
case 1:
|
||||
switch (category_id) {
|
||||
case "1":
|
||||
backgroundColor="rgba(251,64,75,.2)"
|
||||
break;
|
||||
case 2:
|
||||
case "2":
|
||||
backgroundColor="#23ccef"
|
||||
break;
|
||||
case 3:
|
||||
case "3":
|
||||
backgroundColor="rgba(68,125,247,.2)"
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const url = "/qualifying/"+id
|
||||
events.push({id,title,start,url,backgroundColor})
|
||||
events.push({id,title,start,end,url,backgroundColor})
|
||||
if(e.exam_date){
|
||||
events.push({id,"title":"สอบ","start":e.exam_date,url,backgroundColor})
|
||||
}
|
||||
if(e.announcement_date){
|
||||
events.push({id,"title":"ผลสอบสอบ","start":e.announcement_date,url,backgroundColor})
|
||||
}
|
||||
|
||||
})
|
||||
return {exams,events,content}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
<tr>
|
||||
<th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">วันที่</th>
|
||||
<th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">การสอบ</th>
|
||||
<th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">หน่วยงาน</th>
|
||||
<th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">ประเภท</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
<tr>
|
||||
<th class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left"><a href={"/qualifying/"+exam.id}>{exam.date}</a></th>
|
||||
<td class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left"><a href={"/qualifying/"+exam.id}>{exam.title}</a></td>
|
||||
<td class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left">{exam.institute}</td>
|
||||
<td class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left">{exam.category}</td>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
|
||||
import type { PageServerLoad } from './$types'
|
||||
//import type {Exam} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import exams from "$lib/data/qualify-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 post = exams.find((q)=>{
|
||||
return q.id===id
|
||||
})
|
||||
|
||||
if(post)
|
||||
return post
|
||||
else
|
||||
throw error(404,{message:"ค้นหาโพสเกี่ยวกับการคัดเลือกไม่พบ"})
|
||||
|
||||
const res = await fetch("/api/qualifying/"+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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
<script lang="ts">
|
||||
|
||||
import ver from "$lib/ver.json"
|
||||
import type { PageData } from './$types'
|
||||
export let data: PageData;
|
||||
|
||||
</script>
|
||||
<section>
|
||||
<div class="p-one parallax-inner">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue