import {json} from '@sveltejs/kit'
import type {Exam} from '$lib/data/CMSDataType'
import exams from "$lib/data/competitive-exam.json"
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,positions,detail,...minimal})=>{
        if(images && images[0]){
            const image = images[0].url
            return {...minimal,image}
        }
        return minimal
    })
    if(limit>0){
        ex = ex.slice(0,limit)
    }
    return json(ex)
}