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

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