Files
api.portfolio/app/controllers/experiences_controller.js
2026-02-25 00:34:39 +01:00

48 lines
1.6 KiB
JavaScript

import Experience from '#models/experience';
export default class ExperiencesController {
async index({ response }) {
const experiences = await Experience.query()
.preload('projects')
.orderBy('start', 'desc');
return response.ok({
data: experiences.map((e) => ({
id: e.id,
name: e.name,
start: e.start.toISODate(),
end: e.end?.toISODate() ?? null,
missions: e.missions,
place: e.place,
projects: e.projects.map((p) => ({
id: p.id,
title: p.title,
thumbnailUrl: p.thumbnailUrl,
})),
})),
});
}
async show({ params, response }) {
const experience = await Experience.query()
.where('id', params.id)
.preload('projects')
.first();
if (!experience) {
return response.notFound();
}
return response.ok({
data: {
id: experience.id,
name: experience.name,
start: experience.start.toISODate(),
end: experience.end?.toISODate() ?? null,
missions: experience.missions,
place: experience.place,
projects: experience.projects.map((p) => ({
id: p.id,
title: p.title,
thumbnailUrl: p.thumbnailUrl,
}))
}
});
}
}
//# sourceMappingURL=experiences_controller.js.map