Skip to content

Commit 629fc07

Browse files
committed
Add jobs api
1 parent 1d0fefd commit 629fc07

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/pages/api/jobs.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { getCollection, getEntry } from "astro:content";
2+
import type { APIRoute } from "astro";
3+
4+
export const GET: APIRoute = async () => {
5+
const allJobs = await getCollection("jobs");
6+
7+
const jobs = await Promise.all(
8+
allJobs
9+
.filter((job) => !job.data.draft)
10+
.map(async (job) => {
11+
const sponsorId = job.id.split("/")[0];
12+
const sponsor = await getEntry("sponsors", sponsorId);
13+
14+
if (!sponsor) {
15+
throw new Error(`Sponsor with ID "${job.data.sponsor}" not found`);
16+
}
17+
18+
return {
19+
id: job.id,
20+
title: `${sponsor.data.name} - ${job.data.title}`,
21+
location: job.data.location,
22+
type: job.data.type,
23+
level: job.data.level,
24+
salary: job.data.salary,
25+
tags: job.data.tags,
26+
description: job.data.description,
27+
responsibilities: job.data.responsibilities,
28+
min_requirements: job.data.min_requirements,
29+
requirements: job.data.requirements,
30+
preferred: job.data.preferred, // fixed typo: `preffered` → `preferred`
31+
stack: job.data.stack,
32+
benefits: job.data.benefits,
33+
description2: job.data.description2,
34+
apply_link: `https://ep2025.europython.eu/sponsor/${job.id}`,
35+
sponsor: sponsor.data.name,
36+
sponsor_description: sponsor.data.description,
37+
};
38+
})
39+
);
40+
41+
return new Response(JSON.stringify(jobs, null, 2), {
42+
status: 200,
43+
headers: {
44+
"Content-Type": "application/json",
45+
},
46+
});
47+
};

0 commit comments

Comments
 (0)