import Project from '#models/project';
export default class ProjectsController {
    async index({ request, response }) {
        const query = Project.query().preload('category');
        const sort = request.qs().sort;
        if (sort === 'start:desc') {
            query.orderBy('start', 'desc');
        }
        const projects = await query;
        return response.ok({
            data: projects.map((p) => ({
                id: p.id,
                title: p.title,
                category: p.category ? { name: p.category.name } : null,
            })),
        });
    }
    async show({ params, response }) {
        const numericId = Number(params.id);
        const query = Project.query()
            .preload('category')
            .preload('tags')
            .preload('trainings');
        const project = await query.where('id', numericId).first();
        if (!project) {
            return response.notFound({ data: null });
        }
        return response.ok({
            data: {
                title: project.title,
                content: project.content,
                start: project.start?.toISODate() ?? null,
                end: project.end?.toISODate() ?? null,
                thumbnail: project.thumbnailUrl ? [{ url: project.thumbnailUrl }] : [],
                tags: project.tags.map((t) => ({ name: t.name, color: t.color })),
                trainings: project.trainings.map((t) => ({
                    name: t.name,
                    start: t.start?.toISODate(),
                    end: t.end?.toISODate(),
                    skill: t.skill,
                    place: t.place,
                })),
            },
        });
    }
}
//# sourceMappingURL=projects_controller.js.map