Clean data and update mockup api spec

This commit is contained in:
schooltechx 2023-04-08 11:27:09 +07:00
parent aaff6c92b8
commit 9012d03515
13 changed files with 171 additions and 77 deletions

View file

@ -1,9 +1,7 @@
# เวปประกาศข่าว (CMS TOR 6.6.4)
การพัฒนาแบบที่เป็นอยู่ Vue(SPA)+dotnet(Web API) ของบริษัทไม่ได้รองรับ SEO เท่าใดนัก จำเป็นต้องใช้ Meta Framework ที่รองรับ SSR เช่น Nuxt.js เนื่องจากไม่ขึ้นกับส่วนอื่นมากนัก จะทดลองใช้เทคโนโลยีแบบใหม่ๆในการพัฒนา ที่ง่ายในการพัฒนากว่าเดิมจะ SvelteKit เป็นฐาน Daisy UI และ Daisy UI สำหรับการทำ Frontend และจะนำเครื่องมือในการ Automate ต่างๆมาร่วมด้วย
- [Sveltekit](https://www.youtube.com/watch?v=uEJ-Rnm2yOE) Meta JS Framework รองรับ SSR เขียนง่าย
- [Sveltekit](https://www.youtube.com/watch?v=uEJ-Rnm2yOE) Meta JS Framework รองรับ SSR เขียนง่าย ทำ Frontend และ Backend (API) ได้ในตัวเดียว
- [TailWindCSS](https://tailwindcss.com/) ติดตั้งด้วย [svelte-add](https://github.com/svelte-add/tailwindcss)
- [marked](https://marked.js.org/) รองรับ Markdown สำหรับเนื้อหาที่ซับซ้อน
-
- [Daisy UI ](https://daisyui.com/) UI Component ที่ใช้ TailWindCSS ใช้ได้ไม่จำกัด Framework มีวิธีการใช้ดูใน[ลิงค์นี้](https://github.com/schooltechx/youtube/blob/main/svelte/component/DaisyUI.md)
- [PWA](https://web.dev/progressive-web-apps/) ทำให้ Web App เหมือนแอปมือถือ
- [Playwright](https://playwright.dev/) เขียนโค้ดทำการทดสอบเวปแอปบน Browser
@ -11,7 +9,8 @@
- [GitHub Actions](https://github.com/features/actions) ทำ CI/CD ในระบบทดสอบ
- [nektos/act](https://github.com/nektos/act) ใช้ GitHub Actions บนเครื่องของเราเอง
- [Argo CD](https://argo-cd.readthedocs.io/en/stable/) deploy ขึ้นระบบ Production (K8s)
- [FullCalendar](https://github.com/schooltechx/youtube/blob/main/svelte/component/FullCalendar.md) รองรับพ.ศ. ใช้แค่ฟีเจอร์[ฟรีก็น่าจะพอ](https://fullcalendar.io/license#:~:text=or%20FullCalendar%20Premium.-,FullCalendar%20Standard,all%20copyright%20headers%20are%20preserved.)
- [FullCalendar](https://github.com/schooltechx/youtube/blob/main/svelte/component/FullCalendar.md) รองรับพ.ศ. ใช้แค่ฟีเจอร์[ฟรีก็น่าจะพอ](https://fullcalendar.io/license#:~:text=or%20FullCalendar%20Premium.-,FullCalendar%20Standard,all%20copyright%20headers%20are%20preserved.)
- [Day.js](https://day.js.org/) ในฟอร์แม็ตวันในรูปแบบ local ไทยรองรับ พ.ศ.
## วีดีโอแสดงการทำงานทั้งหมด
[![Automate Development](https://img.youtube.com/vi/7CER67WVWec/0.jpg)](https://youtu.be/7CER67WVWec "Automate Development")
@ -21,26 +20,27 @@
## Install
คำสั่งสำหรับเริ่มต้นสร้างโปรเจ็กเปล่าๆ จนใช้งาน
``` bash
# เลือก Skeleton project,Typescript แล้ว ติดตั้งทั้งหมด
# สร้างโปรเจ็ก SvelteKit เลือก Skeleton project,Typescript แล้ว ติดตั้งทั้งหมด
npm create svelte@latest cms-recruit
cd cms-recruit
npm install
# ติดตั้ง Mdsvex
npm i --save-dev mdsvex
# ติดตั้ง Tailwindcss พร้อมเซ็ตค่าให้เรียบร้อย
npx svelte-add@latest tailwindcss
# เมื่อติดตั้ง daisyui ให้ดูวิธีการตั้งค่าเพิ่มจากในเวป
npm i daisyui
# ใช้สำหรับทำเป็น Node.js ทำ Docker Image
npm i -D @sveltejs/adapter-node
# Keycloak สำหรับ frontend และ backend
npm i -D keycloak-js keycloak-backend
# Day.js
npm i dayjs
# FullCalendar
npm i @fullcalendar/core
npm i @fullcalendar/daygrid
npm i @fullcalendar/interaction
# ช่วยทำ seo ให้ง่ายขึ้น
npm install -D svelte-seo
```
## Sveltekit
คำสั่งที่ใช้
คำสั่งที่ใช้รันโปรเจ็ก
``` bash
npm run dev -- --port=4000 --host=0.0.0.0
npm run build
@ -53,9 +53,25 @@ npx vite preview --port=4000 --host=0.0.0.0
โครงสร้างโค้ด
- หน้าเวปอยู่ใน [src/routes/](src/routes/) โครงหน้าหลัก +layout.svelte,หน้าต่างๆ +page.svelte
- library/component ที่ใช้ร่วมกัน [src/lib/](src/lib/)
ตัวอย่างการใช้ API โค้ดอยู่ใน [src/routes/api/users](./src/routes/api/users/)
- http://localhost:4000/api/users
- http://localhost:4000/api/users/1
สร้าง Mockup API โค้ดอยู่ใน [src/routes/api/](./src/routes/api/)
เพื่อความเรียบง่ายสไตล์ CMS การดึงค่าจะเรียงจากใหม่ไปเก่าเสมอ มี limit เพื่อลดปริมาณข้อมูล ถ้าไม่มี limit ดึงข้อมูลล่าสุดไปจนถึง Today+12month
ตัวอย่าง endpoint มีดังนี้
- http://localhost:4000/api/dev
- http://localhost:4000/api/info
- http://localhost:4000/api/content?page=home
- http://localhost:4000/api/content?page=about
- http://localhost:4000/api/competitive
- http://localhost:4000/api/competitive?limit=3
- http://localhost:4000/api/competitive/19
- http://localhost:4000/api/qualifying
- http://localhost:4000/api/qualifying?limit=3
- http://localhost:4000/api/qualifying/21
ถ้าไม่ build เอง ตอนนี้มี demo อยู่ที่ [https://bma-qualifying.frappet.synology.me/](https://bma-qualifying.frappet.synology.me/) ให้เปลี่ยน base url ให้เหมาะสม
Data Type ที่ใช้ดูในไฟล์ [CMSDataType.ts](./src/lib/data/CMSDataType.ts)
## Browser Testing
ใช้ Playwright มีคอนฟิกไฟล์ [playwright.config.ts](./playwright.config.ts) โค้ดสำหรับการทดสอบจะอยู่ใน โฟลเดอร์ [tests](./tests/) ใน VS Code จะติดตั้ง Playwright Extension รูปเป็นเหมือนโหลรูปชมพู่สำหรับทดลองวิทยาศาสตร์ ให้กดปุ่มเล่นเพื่อทำการทดสอบ

View file

@ -1,14 +1,18 @@
export interface Exam {
id:string;
title:string;
date:string;
start?:Date|string;
end?:Date|string;
exam_date?:Date|string;
announcement_date?:Date|string;
detail?:string;
date?:string;
start?:string;
end?:string;
exam_date?:string;
announcement_date?:string;
category_id?:string
category?:string
img?:string;
image?:string;
images?:{title:string,url:string}[];
files?:{title:string,url:string}[];
}
export interface CalendarEvent {
id:string;

View file

@ -1,15 +1,13 @@
[
{
"id":"20",
"date":"24 เม.ย. 2566 ",
"start":"2023-04-24",
"detail":"<p><b>ประกาศรายชื่อผู้ผ่านภาค</b> ข. และมีสิทธิสอบภาค ค. ในการคัดเลือกคนพิการ ครั้งที่ 1/2565</p> <p> <img src='https://webportal.bangkok.go.th/public/user_files_editor/305/%E0%B8%9B%E0%B8%8F%E0%B8%B4%E0%B8%97%E0%B8%B4%E0%B8%99%E0%B8%A7%E0%B8%B1%E0%B8%99%E0%B8%A0%E0%B8%B2%E0%B8%84%E0%B8%84.%E0%B8%84%E0%B8%99%E0%B8%9E%E0%B8%B4%E0%B8%81%E0%B8%B2%E0%B8%A3.jpg'> </p>",
"title":"ประกาศรายชื่อผู้ผ่านภาค ข. และมีสิทธิสอบภาค ค. ในการคัดเลือกคนพิการ ครั้งที่ 1/2565",
"img":"/images/c1.jpg",
"images":[
{
"title":"ภาพ1",
"url":"https://bma-qualifying.frappet.synology.me/images/c1.jpg"
"title":"topic",
"url":"/images/c1.jpg"
}
],
"files":[
@ -49,34 +47,50 @@
},
{
"id":"19",
"date":"13 เม.ย. 2566",
"start":"2023-04-20T09:00:00",
"detail":"ใครลืมส่งเอกสาร !! สำหรับการคัดเลือกคนพิการฯ ครั้งที่ 1/2565 ส่งเอกสารเพิ่มได้",
"title":"ใครลืมส่งเอกสาร !! สำหรับการคัดเลือกคนพิการฯ ครั้งที่ 1/2565 ส่งเอกสารเพิ่มได้",
"img":"/images/c2.jpg"
"images":[
{
"title":"topic",
"url":"/images/c2.jpg"
}
]
},
{
"id":"18",
"date":"9 เม.ย. 2566",
"start":"2023-03-28T09:00:00",
"detail":"แผนที่การเดินทางมาสนามสอบคนพิการฯ ครั้งที่ 1/2565",
"title":"แผนที่การเดินทางมาสนามสอบคนพิการฯ ครั้งที่ 1/2565",
"img":"/images/c3.jpg"
"images":[
{
"title":"topic",
"url":"/images/c3.jpg"
}
]
},
{
"id":"17",
"date":"28 มี.ย. 2566",
"start":"2023-03-28T09:00:00",
"detail":"การสอบแข่งขันเพื่อรรจุและแต่งตั้งบุคคลเข้ารับราชการเป็นข้าราชการกรุงเทพมหานครสามัญ ครั้งที่ 2/2566",
"title":"การสอบแข่งขันเพื่อรรจุและแต่งตั้งบุคคลเข้ารับราชการเป็นข้าราชการกรุงเทพมหานครสามัญ ครั้งที่ 2/2566",
"img":"/images/c1.jpg"
"images":[
{
"title":"topic",
"url":"/images/c1.jpg"
}
]
},
{
"id":"16",
"date":"10 มี.ค. 2556",
"start":"2023-03-10T09:00:00",
"detail":"การสอบแข่งขันเพื่อรรจุและแต่งตั้งบุคคลเข้ารับราชการเป็นข้าราชการกรุงเทพมหานครสามัญ ครั้งที่ 1/2565",
"title":"การสอบแข่งขันเพื่อรรจุและแต่งตั้งบุคคลเข้ารับราชการเป็นข้าราชการกรุงเทพมหานครสามัญ ครั้งที่ 1/2565",
"img":"/images/c2.jpg"
"images":[
{
"title":"topic",
"url":"/images/c2.jpg"
}
]
}
]

View file

@ -1,14 +1,23 @@
[
{
"id":"21",
"date":"24 เม.ย. 2566","institute":"สำนักงาน ก.ก.","institute_id":1,
"catetory":"สำนักงาน ก.ก.","catetory_id":1,
"start":"2023-04-24",
"title":"ด่วน !! ประกาศวัน เวลา สถานที่ และระเบียบการคัดเลือกลูกจ้างกทม.",
"detail":"<p><center><img src='https://webportal.bangkok.go.th/public/user_files_editor/305/bkkgovjob202303_12.jpg'></center></p><br/><center><h2>สำนักงานคณะกรรมการข้าราชการกรุงเทพมหานคร ประกาศกำหนดวัน เวลา สถานที่คัดเลือก และระเบียบ เกี่ยวกับการคัดเลือกบุคลากรกรุงเทพมหานครหรือผู้ปฏิบัติงานอื่นในกรุงเทพมหานครเพื่อบรรจุและแต่งตั้ง เป็นข้าราชการกรุงเทพมหานครสามัญ ครั้งที่ 1 / 2565</h2></center>",
"img":"/images/sel1.png",
"images":[
{
"title":"topic",
"url":"/images/sel1.png"
},
{
"title":"การแต่งกาย",
"url":"https://webportal.bangkok.go.th/public/user_files_editor/305/bkkgovjob202303_12.jpg"
}
],
"files":[
{
"title":"รายละเอียดประกาศฯ",
"title":"รายละเอียดประกาศ",
"url":"https://webportal.bangkok.go.th/public/user_files_editor/305/%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%81%E0%B8%B2%E0%B8%A8%E0%B8%A7%E0%B8%B1%E0%B8%99%20%E0%B9%80%E0%B8%A7%E0%B8%A5%E0%B8%B2%20%E0%B8%AA%E0%B8%96%E0%B8%B2%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%84%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%A5%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%A5%E0%B8%B9%E0%B8%81%E0%B8%88%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%AF.pdf"
},
{
@ -26,50 +35,63 @@
{
"title":"แผนผังสนามสอบ",
"url":"https://file.thaijobjob.com/prakad/bkkgovjob202303/bkkgovjob202303_14"
},
{
"title":"การแต่งกาย",
"url":"https://webportal.bangkok.go.th/public/user_files_editor/305/bkkgovjob202303_12.jpg"
}
]
},
{
"id":"20",
"date":"3 เม.ย. 2566","institute":"สำนักงาน ก.ก.","institute_id":1,
"catetory":"สำนักงาน ก.ก.","catetory_id":1,
"start":"2023-04-03",
"title":"วัน เวลา สถานที่ และระเบียบการคัดเลือกลูกจ้างกทม.",
"detail":"ด่วน !! ประกาศวัน เวลา สถานที่ และระเบียบการคัดเลือกลูกจ้างกทม.",
"img":"/images/sel2.png",
"docUrl":"https://webportal.bangkok.go.th/public/user_files_editor/305/%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%81%E0%B8%B2%E0%B8%A8%E0%B8%A7%E0%B8%B1%E0%B8%99%20%E0%B9%80%E0%B8%A7%E0%B8%A5%E0%B8%B2%20%E0%B8%AA%E0%B8%96%E0%B8%B2%E0%B8%99%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%84%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%A5%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%A5%E0%B8%B9%E0%B8%81%E0%B8%88%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%AF.pdf"
"images":[
{
"title":"topic",
"url":"/images/sel2.png"
}
]
},
{
"id":"19",
"date":"20 ธันวาคม 2566","institute":"สำนักการแพทย์","institute_id":3,
"catetory":"สำนักการแพทย์","catetory_id":3,
"start":"2003-12-20",
"title":"ประกาศรับสมัครคัดเลือกบุคลากรกทม. !!",
"img":"/images/sel3.png",
"detail":"ประกาศรับสมัครคัดเลือกบุคลากรกทม. !!"
"detail":"ประกาศรับสมัครคัดเลือกบุคลากรกทม. !!",
"images":[
{
"title":"topic",
"url":"/images/sel3.png"
}
]
},
{
"id":"18",
"date":"50 พ.ย. 2566","institute":"สำนักอนามัย","institute_id":2,
"catetory":"สำนักอนามัย","catetory_id":2,
"start":"2023-11-05T09:00:00",
"title":"สอบครั้งที่ 1/2565",
"detail":"สอบเป็นลูกจ้างและผู้ปฎิบัติงานในกรุงเทพมหานคร เป็นข้าราชการกรุงเทพมหานคร",
"img":"/images/sel1.png",
"docUrl":"https://webportal.bangkok.go.th/public/user_files_editor/305/%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%81%E0%B8%B2%E0%B8%A8%E0%B8%84%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%A5%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%A5%E0%B8%B9%E0%B8%81%E0%B8%88%E0%B9%89%E0%B8%B2%E0%B8%87.pdf"
"images":[
{
"title":"topic",
"url":"/images/sel1.png"
}
]
},
{
"id":"17",
"date":"1 พ.ย. 2566","institute":"สำนักงาน ก.ก.","institute_id":1,
"catetory":"สำนักงาน ก.ก.","catetory_id":1,
"start":"2023-11-01",
"title":"รับสมัครสอบตำแหน่งลูกจ้างและผู้ปฎิบัติงาน 1/2565",
"detail":"รับสมัครสอบตำแหน่ง ลูกจ้างและผู้ปฎิบัติงานในกรุงเทพมหานคร เป็นข้าราชการกรุงเทพมหานคร",
"img":"/images/sel2.png",
"docUrl":"https://webportal.bangkok.go.th/public/user_files_editor/305/%E0%B8%9B%E0%B8%A3%E0%B8%B0%E0%B8%81%E0%B8%B2%E0%B8%A8%E0%B8%84%E0%B8%B1%E0%B8%94%E0%B9%80%E0%B8%A5%E0%B8%B7%E0%B8%AD%E0%B8%81%E0%B8%A5%E0%B8%B9%E0%B8%81%E0%B8%88%E0%B9%89%E0%B8%B2%E0%B8%87.pdf"
"images":[
{
"title":"topic",
"url":"/images/sel2.png"
}
]
}
]

View file

@ -9,7 +9,6 @@
dayjs.extend(buddhistEra)
import type { LayoutData } from './$types';
export let data: LayoutData;
console.log(data)
let {logo_url,supervised,divisions,institutes,address,organization} = data
</script>

View file

@ -18,14 +18,17 @@ export const load: PageServerLoad = async ({fetch}) => {
if(res.ok){
qualify_exams = await res.json()
qualify_exams.forEach((e)=>{
e.start? dayjs(e.start).format("DD MMM BBBB"):""
e.date = e.start? dayjs(e.start).format("DD MMM BBBB"):""
})
for(let i=qualify_exams.length;i<3;i++){
qualify_exams.push({id:"0",title:"",date:"",image:""})
}
}
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"):""
e.date = e.start? dayjs(e.start).format("DD MMM BBBB"):""
})
}
return { content,image, qualify_exams,competitive_exams };

View file

@ -82,7 +82,7 @@
>
<div class="card bg-white shadow-xl w-full ">
<figure style="height: 250px;" class="img-hover-zoom--brightness">
<img src={qualify_exams[0].img} alt="1" />
<img src={qualify_exams[0].image} alt="1" />
</figure>
<div class="card-body">
<div class="text-sm font-medium text-gray-500">
@ -120,7 +120,7 @@
<div class="flex flex-col w-full">
<div class="card card-side bg-white shadow-xl w-full">
<figure class="w-full lg:w-5/12 imgCard">
<img src={qualify_exams[1].img} alt="1" class="h-full" />
<img src={qualify_exams[1].image} alt="1" class="h-full" />
</figure>
<div class="card-body w-full lg:w-7/12">
<h2 class="text-sm font-medium text-gray-500">
@ -155,7 +155,7 @@
<div class=" flex flex-col w-full">
<div class="card card-side bg-white shadow-xl w-full">
<figure class="w-full lg:w-5/12 imgCard">
<img src={qualify_exams[2].img} alt="1" class="h-full"/>
<img src={qualify_exams[2].image} alt="1" class="h-full"/>
</figure>
<div class="card-body w-full lg:w-7/12">
<div class="text-sm font-medium text-gray-500">
@ -212,7 +212,7 @@
<div class="w-full lg:w-6/12 cardxl">
<div class="card bg-white shadow-xl w-full ">
<figure style="height: 250px;" class="img-hover-zoom--brightness">
<img src={competitive_exams[0].img} alt="1" />
<img src={competitive_exams[0].image} alt="1" />
</figure>
<div class="card-body">
<div class="text-sm font-medium text-gray-500">
@ -251,7 +251,7 @@
<div class="flex flex-col w-full">
<div class="card card-side bg-white shadow-xl w-full">
<figure class="w-full lg:w-5/12 imgCard">
<img src={competitive_exams[1].img} alt="1" class="h-full" />
<img src={competitive_exams[1].image} alt="1" class="h-full" />
</figure>
<div class="card-body w-full lg:w-7/12">
<h2 class="text-sm font-medium text-gray-500">
@ -286,7 +286,7 @@
<div class=" flex flex-col w-full">
<div class="card card-side bg-white shadow-xl w-full">
<figure class="w-full lg:w-5/12 imgCard">
<img src={competitive_exams[2].img} alt="1" class="h-full"/>
<img src={competitive_exams[2].image} alt="1" class="h-full"/>
</figure>
<div class="card-body w-full lg:w-7/12">
<div class="text-sm font-medium text-gray-500">

View file

@ -1,6 +1,19 @@
import type {RequestHandler } from './$types'
import {json} from '@sveltejs/kit'
import type {Exam} from '$lib/data/CMSDataType'
import exams from "$lib/data/competitive-exam.json"
export const GET: RequestHandler = async () => {
return json(exams)
import type { RequestEvent,RequestHandler } from './$types'
export const GET: RequestHandler = async ({url}: RequestEvent) => {
const limit= Number(url.searchParams.get("limit"))
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let ex:Exam[] = exams.map(({files,images,detail,...minimal})=>{
if(images && images[0]){
const image = images[0].url
return {...minimal,image}
}
return minimal
})
if(limit>0){
ex = exams.slice(0,limit)
}
return json(ex)
}

View file

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

View file

@ -1,9 +1,6 @@
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({...info,version,builddate})
return json(info)
}

View file

@ -1,6 +1,19 @@
import type { RequestHandler } from './$types'
import {json} from '@sveltejs/kit'
import type {Exam} from '$lib/data/CMSDataType'
import exams from "$lib/data/qualify-exam.json"
export const GET: RequestHandler = async () => {
return json(exams)
import type { RequestEvent,RequestHandler } from './$types'
export const GET: RequestHandler = async ({url}: RequestEvent) => {
const limit= Number(url.searchParams.get("limit"))
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let ex:Exam[] = exams.map(({files,images,detail,...minimal})=>{
if(images && images[0]){
const image = images[0].url
return {...minimal,image}
}
return minimal
})
if(limit>0){
ex = exams.slice(0,limit)
}
return json(ex)
}

View file

@ -1,6 +1,7 @@
import type { PageServerLoad } from './$types'
import { error } from '@sveltejs/kit';
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => {
let content = ""
let exams:Exam[] = []
@ -10,9 +11,10 @@ export const load: PageServerLoad = async ({fetch}) => {
}
res = await fetch("/api/competitive")
if(res.ok){
exams = await res.json()
if(!res.ok){
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
}
exams = await res.json()
const events:CalendarEvent[]=[]
exams.forEach((e)=>{

View file

@ -1,4 +1,5 @@
import { error } from '@sveltejs/kit';
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types'
@ -10,16 +11,18 @@ export const load: PageServerLoad = async ({fetch}) => {
content = (await res.json()).content
}
res = await fetch("/api/qualifying")
if(res.ok){
exams = await res.json()
if(!res.ok){
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
}
exams = await res.json()
const events:CalendarEvent[]=[]
exams.forEach((e)=>{
if(!e.start){
e.date=""
return
}
e.date= dayjs(e.start).format("DD MMM BBBB")
e.date = e.start? dayjs(e.start).format("DD MMM BBBB"):""
const {id,title,start,end,category_id} = e
let backgroundColor =""
switch (category_id) {