Connect Real API of qualify exam and cms info
This commit is contained in:
parent
acfe81c58a
commit
f536b6e2e9
15 changed files with 34 additions and 31 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {cmsBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
const res = await fetch(apibase+"/info")
|
||||
const res = await fetch(cmsBase+"/home")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของเวปได้');
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
import type { LayoutData } from './$types';
|
||||
export let data: LayoutData;
|
||||
let {logo_url,supervised,divisions,institutes,address,title,subtitle} = data
|
||||
|
||||
</script>
|
||||
|
||||
<Header {logo_url} {title} {supervised} />
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {cmsBase,qualifyingBase,competitiveBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type {Exam} from '$lib/data/CMSDataType'
|
||||
import dayjs from 'dayjs'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
let res = await fetch(apibase+"/info")
|
||||
let res = await fetch("/api/info")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของหน้าหลักได้');
|
||||
const {title,subtitle} = await res.json()
|
||||
|
||||
res = await fetch(apibase+"/content?page=home")
|
||||
res = await fetch(cmsBase+"/content/home")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าหลักได้');
|
||||
const {content,image} = await res.json()
|
||||
console.log("xxx",image)
|
||||
//Inner function reduce code and able to throw here
|
||||
async function loadExam(api_path:string,err_msg:string){
|
||||
const res = await fetch(api_path)
|
||||
|
|
@ -21,16 +22,16 @@ export const load: PageServerLoad = async ({fetch}) => {
|
|||
const exams:Exam[] = await res.json()
|
||||
exams.forEach((e)=>{
|
||||
e.date = e.start? dayjs(e.start).format("DD MMM BBBB"):""
|
||||
e.image = e.image?e.image:"/images/exam_place_holder.png"
|
||||
})
|
||||
//This page layout require 3 item, patch with empty
|
||||
for(let i=exams.length;i<3;i++){
|
||||
exams.push({id:"0",title:"",date:"",image:""})
|
||||
exams.push({id:"0",title:"",date:"",image:"/images/exam_place_holder.png"})
|
||||
}
|
||||
return exams
|
||||
|
||||
return exams
|
||||
}
|
||||
const qualify_exams = loadExam(apibase+"/qualifying",'ไม่สามารถอ่านรายการสอบคัดเลือกได้')
|
||||
const competitive_exams = loadExam(apibase+"/competitive",'ไม่สามารถอ่านรายการสอบแข่งขันได้')
|
||||
const qualify_exams = loadExam(qualifyingBase+"/qualifying?limit=3",'ไม่สามารถอ่านรายการสอบคัดเลือกได้')
|
||||
const competitive_exams = loadExam(competitiveBase+"/competitive?limit=3",'ไม่สามารถอ่านรายการสอบแข่งขันได้')
|
||||
|
||||
return {title,subtitle,content,image, qualify_exams,competitive_exams };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
</div>
|
||||
<img
|
||||
class="absolute top-0 b-auto right-0 sm:w-5/12 sm:mt-32 pr-10 hidden md:flex"
|
||||
src="{image}"
|
||||
src={image?image:'/images/pattern.png'}
|
||||
alt="..."
|
||||
/>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {cmsBase} from '$lib/data/CMSDataType'
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
export const load = (async ({fetch}) => {
|
||||
const res = await fetch(apibase+"/content?page=about")
|
||||
const res = await fetch(cmsBase+"/content/about")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าเกี่ยวกับได้');
|
||||
const {content} = await res.json()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {competitiveBase} from '$lib/data/CMSDataType'
|
||||
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 exams:Exam[] = []
|
||||
const res = await fetch(apibase+"/competitive")
|
||||
const res = await fetch(competitiveBase+"/competitive")
|
||||
if(!res.ok)
|
||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||
exams = await res.json()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {competitiveBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||
const id = params.id+""
|
||||
const res = await fetch(apibase+"/competitive/"+id)
|
||||
const res = await fetch(competitiveBase+"/competitive/"+id)
|
||||
if(res.status==404){
|
||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {qualifyingBase} from '$lib/data/CMSDataType'
|
||||
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 exams:Exam[] = []
|
||||
const res = await fetch(apibase+"/qualifying")
|
||||
const res = await fetch(qualifyingBase+"/qualifying")
|
||||
if(!res.ok)
|
||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||
exams = await res.json()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {qualifyingBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||
const id = params.id+""
|
||||
const res = await fetch(apibase+"/qualifying/"+id)
|
||||
const res = await fetch(qualifyingBase+"/qualifying/"+id)
|
||||
if(res.status==404){
|
||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue