Files
kolaytercih/src/app/api/program-ayrinti/route.ts
bilalgursen a3cb058a3b
All checks were successful
Deploy / deploy (push) Successful in 7m45s
feat: update app.db and BACKLOG.md with new decisions and adjustments
- Updated the app.db file to reflect recent changes in the application state.
- Modified BACKLOG.md to include new entries regarding the removal of certain wizard steps, adjustments to priority chips, and the introduction of special quota conditions for candidates.
- Added details on the decision to link priority chips to data sources and clarified the implications for user experience and data handling.
2026-10-06 17:17:49 +03:00

149 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { NextResponse, type NextRequest } from "next/server";
import {
kontenjanTurleriGetir,
netlerGetir,
programGecmisiGetir,
programGetir,
} from "@/lib/db";
import { kosulMetinleri, ogretimUyesiToplami, programOzellikGetir, type ProgramOzellik } from "@/lib/program-ozellik";
import {
BOLUM_ISTIHDAM,
BOLUM_ISTIHDAM_KAYNAK,
BOLUM_ISTIHDAM_YIL,
ISTIHDAM_ORTALAMA,
type BolumIstihdam,
type IstihdamDuzeyi,
} from "@/lib/bolum-istihdam";
import { uniSlugFromAd } from "@/lib/katalog";
import { bolumSayfaSlug } from "@/lib/slug";
import { URAP_DONEM, URAP_TOPLAM, urapSirasiBul } from "@/lib/urap-siralama";
import {
OGRENCI_BASINA_UYE_MEDYAN,
YOK_ISTATISTIK_DONEM,
ogrenciBasinaUye,
uniIstatistikBul,
} from "@/lib/yok-istatistik";
import type {
KontenjanTurleri,
ProgramGecmisSatiri,
ProgramNetSatiri,
} from "@/types/yokatlas";
/**
* Program satırındaki "ayrıntı" düğmesinin verisi (program-ayrinti.tsx):
* künye (özellikler), yıllara göre sıra/puan/kontenjan/yerleşen, kontenjan
* türleri, son yerleşenin netleri, yerleşme koşulları, TÜİK mezun istihdamı
* ve üniversitenin URAP/YÖK İstatistik özeti. Hepsi yılda bir değişen açık
* veri; istemci tarafında gönül rahatlığıyla cache'lenir.
*/
export type ProgramAyrintisi = {
program: {
id: string;
isim: string;
universite: string;
il: string | null;
unitur: string | null;
fakulte: string | null;
sure: number | null;
efektifSira: number | null;
};
ozellik: ProgramOzellik | null;
/** prof + doç + dr. öğr. üyesi (sunucuda hesaplanır; çekmece db modülünü import etmez) */
ogretimUyesiToplam: number | null;
kosullar: { kod: string; metin: string }[];
gecmis: ProgramGecmisSatiri[];
kontenjanTurleri: KontenjanTurleri | null;
netler: ProgramNetSatiri[];
istihdam:
| (BolumIstihdam & {
duzey: IstihdamDuzeyi;
yil: number;
kaynak: string;
ortalama: { istihdam: number | null; isBulmaAy: number | null };
bolumSayfasi: string;
})
| null;
universite: {
slug: string;
urap: { sira: number; toplam: number; donem: string } | null;
istatistik: {
donem: string;
ogrenci: number;
ogretimUyesi: number;
akademisyen: number;
hocaBasinaOgrenci: number;
medyan: number;
} | null;
} | null;
};
export function GET(request: NextRequest) {
const id = request.nextUrl.searchParams.get("id") ?? "";
if (!/^\d{1,12}$/.test(id)) {
return NextResponse.json(
{ error: "Geçerli bir program kimliği gerekli." },
{ status: 400 },
);
}
const p = programGetir(id);
if (!p) {
return NextResponse.json({ error: "Program bulunamadı." }, { status: 404 });
}
const ozellik = programOzellikGetir(id);
const duzey: IstihdamDuzeyi = p.tur === "TYT" ? "onlisans" : "lisans";
const bolumSlug = bolumSayfaSlug(p.isim);
const istihdamVeri = BOLUM_ISTIHDAM[duzey][bolumSlug] ?? null;
const uniSlug = uniSlugFromAd(p.universite);
const urap = uniSlug ? urapSirasiBul(uniSlug) : null;
const istatistik = uniSlug ? uniIstatistikBul(uniSlug) : null;
const veri: ProgramAyrintisi = {
program: {
id: p.id,
isim: p.isim.trim(),
universite: p.universite,
il: p.il,
unitur: p.unitur,
fakulte: p.fakulte,
sure: p.sure,
efektifSira: p.efektifSira,
},
ozellik,
ogretimUyesiToplam: ozellik ? ogretimUyesiToplami(ozellik) : null,
kosullar: ozellik ? kosulMetinleri(ozellik.kosulKodlari) : [],
gecmis: programGecmisiGetir(id),
kontenjanTurleri: kontenjanTurleriGetir(id),
netler: netlerGetir(id),
istihdam: istihdamVeri
? {
...istihdamVeri,
duzey,
yil: BOLUM_ISTIHDAM_YIL,
kaynak: BOLUM_ISTIHDAM_KAYNAK,
ortalama: ISTIHDAM_ORTALAMA[duzey],
bolumSayfasi: `/bolum/${bolumSlug}`,
}
: null,
universite: uniSlug
? {
slug: uniSlug,
urap: urap ? { sira: urap.sira, toplam: URAP_TOPLAM, donem: URAP_DONEM } : null,
istatistik: istatistik
? {
donem: YOK_ISTATISTIK_DONEM,
ogrenci: istatistik.ogrenci,
ogretimUyesi: istatistik.ogretimUyesi,
akademisyen: istatistik.akademisyen,
hocaBasinaOgrenci: ogrenciBasinaUye(istatistik),
medyan: OGRENCI_BASINA_UYE_MEDYAN,
}
: null,
}
: null,
};
return NextResponse.json(veri, {
headers: { "Cache-Control": "public, max-age=86400" },
});
}