Remove unused code. Add utils.ts
This commit is contained in:
parent
0348e6b72e
commit
ea07766fd8
9 changed files with 34 additions and 112 deletions
|
|
@ -25,7 +25,7 @@ export const load: PageServerLoad = async ({fetch}) => {
|
|||
})
|
||||
//This page layout require 3 item, patch with empty
|
||||
for(let i=exams.length;i<3;i++){
|
||||
exams.push({id:"0",title:"",date:"",image:"/images/exam_place_holder.png"})
|
||||
exams.push({id:"0",title:"",date:"",category:" ",image:"/images/exam_place_holder.png"})
|
||||
}
|
||||
return exams
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import type { RequestEvent, RequestHandler } from './$types'
|
||||
import {json} from '@sveltejs/kit'
|
||||
import { createUser, getUsers } from '$lib/data/users'
|
||||
|
||||
//api/users
|
||||
export const POST: RequestHandler = async ({ request }: RequestEvent) => {
|
||||
const data = await request.json()
|
||||
return json(await createUser( data))
|
||||
}
|
||||
export const GET: RequestHandler = async () => {
|
||||
return json(await getUsers())
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
import type { RequestEvent, RequestHandler } from './$types'
|
||||
import {json} from '@sveltejs/kit'
|
||||
import { getUser, updateUser } from '$lib/data/users'
|
||||
|
||||
//api/users/1
|
||||
export const PUT: RequestHandler = async ({ request }: RequestEvent) => {
|
||||
const o = await request.json()
|
||||
if(!updateUser(o))
|
||||
return json({message:"call updateUser fail "},{status:400})
|
||||
return json({message:"Update Success"})
|
||||
}
|
||||
export const GET: RequestHandler = async ({params}: RequestEvent) => {
|
||||
const id = Number(params.id)
|
||||
const u = await getUser(id)
|
||||
if(!u)
|
||||
return json({message:`User ${id} not found`},{status:404})
|
||||
return json(u)
|
||||
}
|
||||
|
||||
|
|
@ -1,31 +1,22 @@
|
|||
import {competitiveBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||
import {getBgColorDict} from '$lib/utils'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
const res = await fetch(competitiveBase+"/competitive")
|
||||
if(!res.ok)
|
||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||
|
||||
|
||||
const exams:Exam[] = await res.json()
|
||||
const events:CalendarEvent[]=[]
|
||||
const catColor = {};
|
||||
exams.forEach((ex)=>{
|
||||
const {id,title,start,end,category_id} = ex
|
||||
let backgroundColor ="#23ccef"
|
||||
switch (String(category_id)) {
|
||||
case "1":
|
||||
backgroundColor="rgba(251,64,75,.2)"
|
||||
break;
|
||||
case "2":
|
||||
backgroundColor="#23ccef"
|
||||
break;
|
||||
case "3":
|
||||
backgroundColor="rgba(68,125,247,.2)"
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const {id,title,start,end,category} = ex
|
||||
if(!category)
|
||||
return
|
||||
const backgroundColor = getBgColorDict(category,catColor)
|
||||
const url = "/competitive/"+id
|
||||
if(start){
|
||||
ex.date = dayjs(start).format("DD MMM BBBB")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {qualifyingBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||
import {getBgColorDict} from '$lib/utils'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
|
|
@ -8,28 +9,20 @@ export const load: PageServerLoad = async ({fetch}) => {
|
|||
if(!res.ok)
|
||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||
const exams:Exam[] = await res.json()
|
||||
|
||||
const catColor = {};
|
||||
const events:CalendarEvent[]=[]
|
||||
|
||||
exams.forEach((ex)=>{
|
||||
const {id,title,start,end,category_id} = ex
|
||||
let backgroundColor ="#23ccef"
|
||||
switch (String(category_id)) {
|
||||
case "1":
|
||||
backgroundColor="rgba(251,64,75,.2)"
|
||||
break;
|
||||
case "2":
|
||||
backgroundColor="#23ccef"
|
||||
break;
|
||||
case "3":
|
||||
backgroundColor="rgba(68,125,247,.2)"
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const {id,title,start,end,category} = ex
|
||||
if(!category)
|
||||
return
|
||||
const backgroundColor = getBgColorDict(category,catColor)
|
||||
|
||||
const url = "/qualifying/"+id
|
||||
if(start){
|
||||
ex.date = dayjs(start).format("DD MMM BBBB")
|
||||
events.push({id,title,start,end,url,backgroundColor})
|
||||
console.log({id,title,start,end,url,backgroundColor})
|
||||
events.push({id,title,start,url,backgroundColor})
|
||||
}
|
||||
if(ex.exam_date){
|
||||
events.push({id,"title":"วันสอบคัดเลือก","start":ex.exam_date,url,backgroundColor})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue