All files / apps/huella-legal/layers/articles/server/api/pages [slug].get.ts

100% Statements 6/6
75% Branches 3/4
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31              5x   5x   5x 1x   4x           1x                    
import type { Page } from "../../../shared/types/Page";
import { toPage } from "../../mappers/page";
 
export default defineEventHandler(async (event): Promise<Page> => {
    const {
        content: { vendor },
        public: { site, pageSlugs },
    } = useRuntimeConfig(event);
 
    const slug = (getRouterParam(event, "slug", { decode: true }) ?? "").toLowerCase();
 
    if (!pageSlugs.includes(slug))
        throw createError({ statusCode: 404, statusMessage: "Page not found" });
 
    return toPage(await useContent(event).getEntry("pages", slug), {
        siteUrl: site.url,
        wordpressUrl: vendor.baseURL,
    });
});
 
defineRouteMeta({
    openAPI: {
        tags: ["Articles"],
        summary: "Read one of the site's configured WordPress pages",
        responses: {
            200: { description: "OK" },
            404: { description: "The slug isn't a configured page, or WordPress has no such page" },
        },
    },
});