Update API from meeting

This commit is contained in:
schooltechx 2023-04-07 22:59:53 +07:00
parent 40f7e878c9
commit b2083ebae2
13 changed files with 125 additions and 67 deletions

View file

@ -0,0 +1,14 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => {
const res = await fetch("/api/info")
if(res.ok){
const info = await res.json()
return info
}else{
throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของเวปได้');
}
}

View file

@ -1,7 +1,15 @@
<script>
<script lang="ts">
import '../app.postcss';
import Header from '$lib/components/Header.svelte';
import Footer from '$lib/components/Footer.svelte';
import 'dayjs/locale/th'
import dayjs from 'dayjs'
dayjs.locale('th')
import buddhistEra from 'dayjs/plugin/buddhistEra'
dayjs.extend(buddhistEra)
import type { LayoutData } from './$types';
export let data: LayoutData;
console.log(data)
</script>
<Header />

View file

@ -1,7 +1,8 @@
//import content from "$lib/data/content/home.html?raw"
//import { getQualifyExams,getCompetitiveExams } from '$lib/data/info';
import type { PageServerLoad } from './$types';
import type {Exam} from '$lib/components/Exam'
import type {Exam} from '$lib/components/Exam'
import dayjs from 'dayjs'
export const load: PageServerLoad = async ({fetch}) => {
let qualify_exams: Exam[] = []
let competitive_exams: Exam[] = []
@ -13,10 +14,16 @@ export const load: PageServerLoad = async ({fetch}) => {
res = await fetch("/api/qualifying")
if(res.ok){
qualify_exams = await res.json()
qualify_exams.forEach((e)=>{
e.start? dayjs(e.start).format("DD MMM BBBB"):""
})
}
res = await fetch("/api/competitive")
if(res.ok){
competitive_exams = await res.json()
competitive_exams.forEach((e)=>{
e.start? dayjs(e.start).format("DD MMM BBBB"):""
})
}
return { content , qualify_exams,competitive_exams };
};

View file

@ -1,8 +1,9 @@
import ver from "$lib/ver.json"
import {json} from '@sveltejs/kit'
import info from "$lib/data/info.json"
import type { RequestHandler } from './$types'
export const GET: RequestHandler = async () => {
const version = ver.version
const builddate = ver.builddate
return json({version,builddate})
return json({...info,version,builddate})
}

View file

@ -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})
})

View file

@ -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
}

View file

@ -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}
}

View file

@ -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>

View file

@ -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
}

View file

@ -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">