Files
my-portfolio/src/app/api/projects/route.ts
T
Space-Banane dfbe14d284
Build Check / build (push) Failing after 18s
Build Check / deploy-coolify (push) Has been skipped
Build Check / push-image (push) Has been skipped
Little rework
2026-07-16 23:03:42 +02:00

37 lines
1.0 KiB
TypeScript

import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { resolveLoc } from "@/lib/loc";
// Public: list all projects (served from our DB), each with a resolved
// line-of-code count (manual `loc` or fetched from `locEndpoint`, cached).
export async function GET() {
// Ordered by size (Big -> MediumSized -> Small via the enum's declared order),
// then alphabetically by name.
const projects = await prisma.project.findMany({
orderBy: [{ size: "asc" }, { name: "asc" }],
});
const withLoc = await Promise.all(
projects.map(async (p) => ({
id: p.id,
name: p.name,
label: p.label,
size: p.size,
imageUrl: p.imageUrl,
link: p.link,
linkIsDemo: p.linkIsDemo,
sourceCode: p.sourceCode,
description: p.description,
why: p.why,
note: p.note,
tags: p.tags,
loc: p.loc,
resolvedLoc: await resolveLoc(p.loc, p.locEndpoint),
createdAt: p.createdAt,
updatedAt: p.updatedAt,
})),
);
return NextResponse.json(withLoc);
}